Added symlink command. Added --as option.

This commit is contained in:
Yuta
2011-03-23 01:14:39 +09:00
parent 2f3fbeca53
commit eb49f121db
6 changed files with 65 additions and 10 deletions
+9 -3
View File
@@ -14,21 +14,27 @@ class InstallCommand(Command):
dest="force",
action="store_true",
default=False,
help="Force installation of a Python."
help="Force install of python.(skip make test)"
)
self.parser.add_option(
"-C", "--configure",
dest="configure",
default="",
metavar="CONFIGURE_OPTIONS",
help="Custom configure options."
help="Options passed directly to configure."
)
self.parser.add_option(
"-n", "--no-setuptools",
dest="no_setuptools",
action="store_true",
default=False,
help="Skip installation of setuptools."
help="Skip install of setuptools."
)
self.parser.add_option(
"--as",
dest="alias",
default=None,
help="Install a python under an alias."
)
def run_command(self, options, args):
+1 -1
View File
@@ -38,7 +38,7 @@ class ListCommand(Command):
logger.info('# installed pythons')
cur = get_current_python_path()
for d in sorted(os.listdir(PATH_PYTHONS)):
if cur == os.path.join(PATH_PYTHONS, d, 'bin','python'):
if cur and os.path.samefile(cur, os.path.join(PATH_PYTHONS, d, 'bin','python')):
logger.info('%s (*)' % d)
cur = None
else:
+44
View File
@@ -0,0 +1,44 @@
import os
from pythonbrew.basecommand import Command
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
from pythonbrew.util import Package, symlink, unlink
class SymlinkCommand(Command):
name = "symlink"
usage = "%prog"
summary = "Create/Remove a symbolic link to python"
def __init__(self):
super(SymlinkCommand, self).__init__()
self.parser.add_option(
"-p", "--python",
dest="pythons",
action="append",
default=[],
help="Using specified python versions."
)
self.parser.add_option(
"-r", "--remove",
dest="remove",
action="store_true",
default=False,
help="Remove a symbolic link."
)
def run_command(self, options, args):
pythons = self._get_pythons(options.pythons)
for python in pythons:
version = Package(python).version
src = os.path.join(PATH_PYTHONS, python, 'bin', 'python')
dst = os.path.join(PATH_BIN, 'py%s' % (version))
if options.remove:
unlink(dst)
else:
symlink(src, dst)
def _get_pythons(self, _pythons):
pythons = [Package(p).name for p in _pythons]
return [d for d in sorted(os.listdir(PATH_PYTHONS))
if not pythons or d in pythons]
SymlinkCommand()
+3 -3
View File
@@ -119,9 +119,9 @@ class PythonInstaller(object):
if is_url(name):
self.download_url = name
filename = Link(self.download_url).filename
pkg = Package(filename)
pkg = Package(filename, options.alias)
else:
pkg = Package(name)
pkg = Package(name, options.alias)
self.download_url = get_python_version_url(pkg.version)
if not self.download_url:
logger.info("Unknown python version: `%s`" % pkg.name)
@@ -166,7 +166,7 @@ class PythonInstaller(object):
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.version)
logger.info(" pythonbrew switch %s" % self.pkg.alias)
def ensure(self):
if is_macosx_snowleopard():
+7 -3
View File
@@ -242,18 +242,22 @@ class Subprocess(object):
raise ShellCommandException('Failed to `%s` command' % cmd)
class Package(object):
def __init__(self, name):
def __init__(self, name, alias=None):
self.name = None
self.version = None
self.alias = None
if is_archive_file(name):
name = splitext(name)[0]
m = re.search("^Python-(.*)$", name)
if m:
self.name = name
self.version = m.group(1)
self.version = self.alias = m.group(1)
else:
self.name = "Python-%s" % name
self.version = name
self.version = self.alias = name
if alias:
self.name = 'Python-%s' % alias
self.alias = alias
class Link(object):
def __init__(self, url):