mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
modified install and uninstall command
This commit is contained in:
@@ -3,6 +3,8 @@ from pythonbrew.log import logger
|
||||
from pythonbrew.installer.pythoninstaller import PythonInstaller,\
|
||||
PythonInstallerMacOSX
|
||||
from pythonbrew.util import is_macosx_snowleopard
|
||||
from pythonbrew.exceptions import UnknownVersionException,\
|
||||
AlreadyInstalledException, NotSupportedVersionException
|
||||
|
||||
class InstallCommand(Command):
|
||||
name = "install"
|
||||
@@ -48,12 +50,20 @@ class InstallCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if args:
|
||||
# Install Python
|
||||
if is_macosx_snowleopard():
|
||||
p = PythonInstallerMacOSX(args[0], options)
|
||||
else:
|
||||
p = PythonInstaller(args[0], options)
|
||||
p.install()
|
||||
# Install pythons
|
||||
for arg in args:
|
||||
try:
|
||||
if is_macosx_snowleopard():
|
||||
p = PythonInstallerMacOSX(arg, options)
|
||||
else:
|
||||
p = PythonInstaller(arg, options)
|
||||
p.install()
|
||||
except UnknownVersionException:
|
||||
continue
|
||||
except AlreadyInstalledException:
|
||||
continue
|
||||
except NotSupportedVersionException:
|
||||
continue
|
||||
else:
|
||||
logger.info("Unknown python version.")
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
from pythonbrew.basecommand import Command
|
||||
from pythonbrew.define import PATH_PYTHONS
|
||||
from pythonbrew.util import off, rm_r, Package, get_current_python_path
|
||||
@@ -12,15 +11,17 @@ class UninstallCommand(Command):
|
||||
|
||||
def run_command(self, options, args):
|
||||
if args:
|
||||
pkg = Package(args[0])
|
||||
pkgname = pkg.name
|
||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgpath):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
sys.exit(1)
|
||||
if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
|
||||
off()
|
||||
rm_r(pkgpath)
|
||||
# Uninstall pythons
|
||||
for arg in args:
|
||||
pkg = Package(arg)
|
||||
pkgname = pkg.name
|
||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||
if not os.path.isdir(pkgpath):
|
||||
logger.info("`%s` is not installed." % pkgname)
|
||||
continue
|
||||
if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
|
||||
off()
|
||||
rm_r(pkgpath)
|
||||
else:
|
||||
self.parser.print_help()
|
||||
|
||||
|
||||
@@ -4,4 +4,11 @@ class BuildingException(Exception):
|
||||
|
||||
class ShellCommandException(Exception):
|
||||
"""General exception during shell command"""
|
||||
|
||||
class UnknownVersionException(Exception):
|
||||
"""General exception during installing"""
|
||||
class AlreadyInstalledException(Exception):
|
||||
"""General exception during installing"""
|
||||
class NotSupportedVersionException(Exception):
|
||||
"""General exception during installing"""
|
||||
|
||||
@@ -14,6 +14,8 @@ from pythonbrew.define import PATH_BUILD, PATH_DISTS, PATH_PYTHONS,\
|
||||
from pythonbrew.downloader import get_python_version_url, Downloader,\
|
||||
get_headerinfo_from_url
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.exceptions import UnknownVersionException,\
|
||||
AlreadyInstalledException, NotSupportedVersionException
|
||||
|
||||
class PythonInstaller(object):
|
||||
"""Python installer
|
||||
@@ -38,7 +40,7 @@ class PythonInstaller(object):
|
||||
self.download_url = get_python_version_url(pkg.version)
|
||||
if not self.download_url:
|
||||
logger.info("Unknown python version: `%s`" % pkg.name)
|
||||
sys.exit(1)
|
||||
raise UnknownVersionException
|
||||
filename = Link(self.download_url).filename
|
||||
self.pkg = pkg
|
||||
self.install_dir = os.path.join(PATH_PYTHONS, pkg.name)
|
||||
@@ -57,7 +59,7 @@ class PythonInstaller(object):
|
||||
def install(self):
|
||||
if os.path.isdir(self.install_dir):
|
||||
logger.info("You are already installed `%s`" % self.pkg.name)
|
||||
sys.exit()
|
||||
raise AlreadyInstalledException
|
||||
self.download_unpack()
|
||||
logger.info("")
|
||||
logger.info("This could take a while. You can run the following command on another shell to track the status:")
|
||||
@@ -78,7 +80,6 @@ class PythonInstaller(object):
|
||||
self.install_setuptools()
|
||||
logger.info("Installed %(pkgname)s successfully. Run the following command to switch to %(pkgname)s."
|
||||
% {"pkgname":self.pkg.name})
|
||||
logger.info("")
|
||||
logger.info(" pythonbrew switch %s" % self.pkg.alias)
|
||||
|
||||
def download_unpack(self):
|
||||
@@ -185,7 +186,7 @@ class PythonInstallerMacOSX(PythonInstaller):
|
||||
# check for version
|
||||
if version < '2.6' and (version != '2.4.6' and version != '2.5.5'):
|
||||
logger.info("`%s` is not supported on MacOSX Snow Leopard" % self.pkg.name)
|
||||
sys.exit()
|
||||
raise NotSupportedVersionException
|
||||
# set configure options
|
||||
if is_python24(version):
|
||||
self.configure_options = '--with-universal-archs="intel" MACOSX_DEPLOYMENT_TARGET=10.6 CPPFLAGS="-D__DARWIN_UNIX03"'
|
||||
|
||||
Reference in New Issue
Block a user