#!/usr/bin/env python
import urllib2
import json
import apt
import tarfile
import tempfile
import shutil
import sys

from shutil import copytree
from os import environ
from os import listdir
from os import symlink
from os.path import isfile, join

# install packages
package_list = ['python-pip']

print "Updating apt cache"
cache = apt.cache.Cache()
cache.update()

for package in package_list:
    pkg = cache[package]

    if not pkg.is_installed:
        pkg.mark_install(auto_inst=True)

try:
    cache.commit()
except Exception, arg:
    print >> sys.stderr, "Sorry, package installation failed [{err}]".format(err=str(arg))

import pip

pip_packages = ['jinja2', 'azure', 'azure-mgmt', 'click']
for package in pip_packages:
    pip.main(['install', package])

gh_url = 'https://api.github.com/repos/cf-platform-eng/bosh-azure-template/releases/latest'

req = urllib2.Request(gh_url)
headers = req.headers = {
  'Content-Type':'application/json'
}

# upload the release asset
handler = urllib2.urlopen(req)
release = json.loads(handler.read())

release_url = release['assets'][0]['browser_download_url']
res = urllib2.urlopen(release_url)

code = res.getcode()
length = int(res.headers["Content-Length"])

# content-length
if code is 200:

    CHUNK = 16 * 1024
    filename = '/tmp/archive.tgz'

    with open(filename, 'wb') as temp:
        while True:
            chunk = res.read(CHUNK)

            if not chunk: break
            temp.write(chunk)

        print "Download complete."

    tfile = tarfile.open(filename, 'r:gz')
    tfile.extractall(".")

copytree('.' '../..')
symlink('/usr/local/lib/python2.7/dist-packages/azure/mgmt', '../../azure/mgmt')

@@ -256,44 +256,938 @@
 ll p
-ackages%0Apackage_list = %5B'python-pip'
+ython-pip and it's dependencies...%0Apackage_list = %5B%22binutils%22, %22build-essential%22, %22cpp%22, %22cpp-4.8%22, %22dpkg-dev%22, %5C%0A    %22fakeroot%22, %22g++%22, %22g++-4.8%22, %22gcc%22, %22gcc-4.8%22, %22libalgorithm-diff-perl%22, %5C%0A    %22libalgorithm-diff-xs-perl%22, %22libalgorithm-merge-perl%22, %22libasan0%22, %5C%0A    %22libatomic1%22, %22libc-dev-bin%22, %22libc6-dev%22, %22libcloog-isl4%22, %5C%0A    %22libdpkg-perl%22, %22libfakeroot%22, %22libfile-fcntllock-perl%22, %22libgcc-4.8-dev%22, %5C%0A    %22libgomp1%22, %22libisl10%22, %22libitm1%22, %22libmpc3%22, %22libmpfr4%22, %22libquadmath0%22, %5C%0A    %22libstdc++-4.8-dev%22, %22libtsan0%22, %22linux-libc-dev%22, %22make%22, %22manpages-dev%22, %5C%0A    %22python-chardet-whl%22, %22python-colorama%22, %22python-colorama-whl%22, %5C%0A    %22python-distlib%22, %22python-distlib-whl%22, %22python-html5lib%22, %5C%0A    %22python-html5lib-whl%22, %22python-pip%22, %22python-pip-whl%22, %5C%0A    %22python-requests-whl%22, %22python-setuptools%22, %22python-setuptools-whl%22, %5C%0A    %22python-six-whl%22, %22python-urllib3-whl%22, %22python-wheel%22, %22python3-pkg-resources%22
 %5D%0A%0Ap
@@ -1338,16 +1338,16 @@
 talled:%0A
+
         
@@ -1367,22 +1367,8 @@
 all(
-auto_inst=True
 )%0A%0At

Update package list to include pip deps