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()