mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 15:20:16 +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"'
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import shutil
|
||||
|
||||
PYTHONBREW_ROOT = '/tmp/pythonbrew.test'
|
||||
TESTPY_FILE = '/tmp/pythonbrew_test.py'
|
||||
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6']
|
||||
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6', '3.2']
|
||||
def cleanall():
|
||||
if os.path.isdir(PYTHONBREW_ROOT):
|
||||
shutil.rmtree(PYTHONBREW_ROOT)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
class UpdateOptions(object):
|
||||
head = False
|
||||
config = False
|
||||
force = False
|
||||
|
||||
def test_update():
|
||||
from pythonbrew.commands.update import UpdateCommand
|
||||
c = UpdateCommand()
|
||||
c.run_command(UpdateOptions(), None)
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ class InstallOptions(object):
|
||||
|
||||
def test_install():
|
||||
from pythonbrew.commands.install import InstallCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = InstallCommand()
|
||||
c.run_command(InstallOptions(), [py_version])
|
||||
py_version = TESTPY_VERSION.pop(0)
|
||||
c = InstallCommand()
|
||||
c.run_command(InstallOptions(), [py_version]) # pybrew install -f -j2 2.4.6
|
||||
c.run_command(InstallOptions(), TESTPY_VERSION) # pybrew install -f -j2 2.5.6 2.6.6 3.2
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ class PyOptions(object):
|
||||
|
||||
def _create_pyfile():
|
||||
fp = open(TESTPY_FILE, 'w')
|
||||
fp.write("print 'test'")
|
||||
fp.write("print('test')")
|
||||
fp.close()
|
||||
|
||||
def test_py():
|
||||
|
||||
Reference in New Issue
Block a user