#!/usr/bin/env python
#coding:utf-8

import os
import tarfile
setuptools_url='https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz --no-check-certificate'
pip_url='https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz --no-check-certificate'
tools_package = 'setuptools-0.6c11.tar.gz'
pip_package = 'pip-9.0.1.tar.gz'
tools_dirname = 'setuptools-0.6c11'
pip_dirname = 'pip-9.0.1'
url = [ setuptools_url,pip_url]
package = [tools_package,pip_package]
package_path = os.getcwd()
for u in url:
    os.system('wget -c %s' % url)
for p in package:
     abs_package_name = os.path.join(package_path,p)
     t=tarfile.open(abs_package_name,'r')
     t.extractall()
     t.close()
tools_dir = os.path.join(package_path,tools_dirname)
pip_dir = os.path.join(package_path,pip_dirname)
os.chdir(tools_dir)
os.system('python setup.py install')
os.chdir(pip_dir)
os.system('python setup.py build && python setup.py install && pip install --upgrade pip')