fixed PY-6067 Offer to install pip and distribute if they are not installed in the current interpreter

This commit is contained in:
Ekaterina Tuzova
2012-03-26 20:21:59 +04:00
parent 2235935ec7
commit 1391181432
2 changed files with 87 additions and 11 deletions

View File

@@ -15,13 +15,13 @@ def error(message, retcode):
sys.exit(retcode)
def error_no_pip():
error("Python package management tool 'pip' not found. Please install 'pip' manually", ERROR_NO_PACKAGING_TOOLS)
error("Python package management tool 'pip' not found. <a href=\"installPip\">Install 'pip'</a>.", ERROR_NO_PACKAGING_TOOLS)
def do_list():
try:
import pkg_resources
except ImportError:
error("Python package management tools not found. Please install 'setuptools' or 'distribute' manually", ERROR_NO_PACKAGING_TOOLS)
error("Python package management tools not found. <a href=\"installDistribute\">Install 'distribute'</a>.", ERROR_NO_PACKAGING_TOOLS)
for pkg in pkg_resources.working_set:
print('\t'.join([pkg.project_name, pkg.version, pkg.location]))
@@ -39,6 +39,19 @@ def do_uninstall(pkgs):
error_no_pip()
return pip.main(['uninstall', '-y'] + pkgs)
def untarDirectory(name):
import os
import tempfile
directory_name = tempfile.mkdtemp("management")
import tarfile
filename = name + ".tar.gz"
tar = tarfile.open(filename)
for item in tar:
tar.extract(item, directory_name)
print (directory_name)
def main():
retcode = 0
try:
@@ -55,6 +68,11 @@ def main():
usage()
pkgs = sys.argv[2:]
retcode = do_install(pkgs)
elif cmd == 'untar':
if len(sys.argv) < 2:
usage()
name = sys.argv[2]
retcode = untarDirectory(name)
elif cmd == 'uninstall':
if len(sys.argv) < 2:
usage()