diff --git a/PKG-INFO b/PKG-INFO index 5733b62..a575371 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -38,12 +38,18 @@ Install some Pythons:: Switch python in the $PATH:: pythonbrew switch 2.6.6 - pythonbrew switch Python-2.5.5 + pythonbrew switch 2.5.5 Using python in the PATH:: pythonbrew use 2.6.6 +Runs a named python file against specified and/or all pythons:: + + pythonbrew py test.py + pythonbrew py -v test.py # Show version + pythonbrew py -p 2.6.6 -p 3.1.2 test.py # Using specified python versions + List the installed versions of Python:: pythonbrew list @@ -76,7 +82,7 @@ COMMANDS ======== install - Build and install the given version of Python. + Build and install the given version of python. Setuptools and pip is automatically installed. @@ -92,10 +98,10 @@ use Using the given version of python. list - List the installed versions of Python. + List the installed all pythons. list -k - List the available install version of python. + List the available install pythons. uninstall Uninstall the given version of python. @@ -116,7 +122,7 @@ Options ======= \-f | --force - Force installation of a Python. (skip `make test`) + Force installation of a python. (skip `make test`) \-C | --configure Custom configure options. diff --git a/README.rst b/README.rst index 8fcb020..b2d3093 100644 --- a/README.rst +++ b/README.rst @@ -43,6 +43,12 @@ Using python in the PATH:: pythonbrew use 2.6.6 +Runs a named python file against specified and/or all pythons:: + + pythonbrew py test.py + pythonbrew py -v test.py # Show version + pythonbrew py -p 2.6.6 -p 3.1.2 test.py # Using specified python versions + List the installed versions of Python:: pythonbrew list @@ -75,7 +81,7 @@ COMMANDS ======== install - Build and install the given version of Python. + Build and install the given version of python. Setuptools and pip is automatically installed. @@ -91,10 +97,10 @@ use Using the given version of python. list - List the installed versions of Python. + List the installed all pythons. list -k - List the available install version of python. + List the available install pythons. uninstall Uninstall the given version of python. @@ -115,7 +121,7 @@ Options ======= \-f | --force - Force installation of a Python. (skip `make test`) + Force installation of a python. (skip `make test`) \-C | --configure Custom configure options. diff --git a/pythonbrew/commands/list.py b/pythonbrew/commands/list.py index 3952ec5..e3a2e7b 100644 --- a/pythonbrew/commands/list.py +++ b/pythonbrew/commands/list.py @@ -9,7 +9,7 @@ from pythonbrew.log import logger class ListCommand(Command): name = "list" usage = "%prog [VERSION]" - summary = "List the installed versions of Python" + summary = "List the installed all pythons" def __init__(self): super(ListCommand, self).__init__() @@ -37,7 +37,7 @@ class ListCommand(Command): def installed(self, options, args): logger.info('# installed pythons') cur = get_current_python_path() - for d in sorted(os.listdir('%s/' % PATH_PYTHONS)): + for d in sorted(os.listdir(PATH_PYTHONS)): if cur == os.path.join(PATH_PYTHONS, d, 'bin','python'): logger.info('%s (*)' % d) cur = None diff --git a/pythonbrew/commands/py.py b/pythonbrew/commands/py.py new file mode 100644 index 0000000..d6b90fa --- /dev/null +++ b/pythonbrew/commands/py.py @@ -0,0 +1,51 @@ +import os +import sys +from pythonbrew.basecommand import Command +from pythonbrew.define import PATH_PYTHONS +from pythonbrew.util import Package +from pythonbrew.log import logger +from subprocess import PIPE, Popen + +class PyCommand(Command): + name = "py" + usage = "%prog PYTHON_FILE" + summary = "Runs a named python file against specified and/or all pythons" + + def __init__(self): + super(PyCommand, self).__init__() + self.parser.add_option( + "-p", "--python", + dest="pythons", + action="append", + default=[], + help="Using specified python versions." + ) + self.parser.add_option( + "-v", "--verbose", + dest="verbose", + action="store_true", + default=False, + help="Show python version." + ) + + def run_command(self, options, args): + if not args: + logger.info("Unrecognized command line argument: argument not found.") + sys.exit(1) + python_file = args[0] + + pythons = self._get_pythons(options.pythons) + for d in pythons: + path = os.path.join(PATH_PYTHONS, d, 'bin', 'python') + if os.path.isfile(path) and os.access(path, os.X_OK): + if options.verbose: + logger.info('*** %s ***' % d) + p = Popen("%s %s" % (path, python_file), shell=True) + p.wait() + + 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] + +PyCommand()