From 3a220f342aaaa1ff29e4fde5595fad1a574fba09 Mon Sep 17 00:00:00 2001 From: Yuta Date: Sun, 17 Apr 2011 10:43:54 +0900 Subject: [PATCH] Added -b option to symlink command --- pythonbrew/commands/list.py | 4 ++-- pythonbrew/commands/symlink.py | 35 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pythonbrew/commands/list.py b/pythonbrew/commands/list.py index fe9b39f..46bb494 100644 --- a/pythonbrew/commands/list.py +++ b/pythonbrew/commands/list.py @@ -18,14 +18,14 @@ class ListCommand(Command): dest='all_versions', action='store_true', default=False, - help='All versions of Python are visible' + help='Show the all python versions' ) self.parser.add_option( '-k', '--known', dest='known', action='store_true', default=False, - help='List the available install versions of Python' + help='List the available latest python versions' ) def run_command(self, options, args): diff --git a/pythonbrew/commands/symlink.py b/pythonbrew/commands/symlink.py index a79c2bd..10fe9b1 100644 --- a/pythonbrew/commands/symlink.py +++ b/pythonbrew/commands/symlink.py @@ -15,28 +15,47 @@ class SymlinkCommand(Command): dest="pythons", action="append", default=[], - help="Using specified python versions." + help="Use the specified python versions" ) self.parser.add_option( "-r", "--remove", dest="remove", action="store_true", default=False, - help="Remove a symbolic link." + help="Remove the all symbolic link" + ) + self.parser.add_option( + "-b", "--bin", + dest="bin", + action="append", + default=[], + help="Create the specified binary 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)) + for pkgname in pythons: if options.remove: - unlink(dst) + for bin in os.listdir(PATH_BIN): + path = os.path.join(PATH_BIN, bin) + if os.path.islink(path): + unlink(path) else: - symlink(src, dst) + self._symlink('python', 'py', pkgname) + for bin in options.bin: + self._symlink(bin, bin, pkgname) + + def _symlink(self, srcbin, dstbin, pkgname): + """Create the symlink + """ + version = Package(pkgname).version + src = os.path.join(PATH_PYTHONS, pkgname, 'bin', srcbin) + dst = os.path.join(PATH_BIN, '%s%s' % (dstbin, version)) + symlink(src, dst) def _get_pythons(self, _pythons): + """Get the installed python versions. + """ 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]