diff --git a/pythonbrew/commands/py.py b/pythonbrew/commands/py.py index e7785e5..78de2bc 100644 --- a/pythonbrew/commands/py.py +++ b/pythonbrew/commands/py.py @@ -28,6 +28,18 @@ class PyCommand(Command): default=False, help="Show the running python version." ) + self.parser.add_option( + "-b", "--bin", + dest="bin", + default='python', + help="Use the specified script in python's bin directory." + ) + self.parser.add_option( + "-o", "--options", + dest="options", + default='', + help="Options passed directly to runs script." + ) def run_command(self, options, args): if not args: @@ -37,16 +49,18 @@ class PyCommand(Command): pythons = self._get_pythons(options.pythons) for d in pythons: - path = os.path.join(PATH_PYTHONS, d, 'bin', 'python') + path = os.path.join(PATH_PYTHONS, d, 'bin', options.bin) 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 = Popen("%s %s %s" % (path, options.options, python_file), shell=True) p.wait() + else: + logger.info('%s: No such file or directory.' % path) def _get_pythons(self, _pythons): pythons = [Package(p).name for p in _pythons] - return [d for d in sorted(os.listdir(PATH_PYTHONS)) + return [d for d in sorted(os.listdir(PATH_PYTHONS)) if not pythons or d in pythons] PyCommand() diff --git a/tests/test_09_py.py b/tests/test_09_py.py index 9a62b78..77a0705 100644 --- a/tests/test_09_py.py +++ b/tests/test_09_py.py @@ -3,6 +3,8 @@ from tests import TESTPY_FILE class PyOptions(object): pythons = [] verbose = False + bin = "python" + options = "" def _create_pyfile(): fp = open(TESTPY_FILE, 'w')