| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs a command with PYTHONPATH set up for the Chromium build setup. | 6 """Runs a command with PYTHONPATH set up for the Chromium build setup. |
| 7 | 7 |
| 8 This is helpful for running scripts locally on a development machine. | 8 This is helpful for running scripts locally on a development machine. |
| 9 | 9 |
| 10 Try `scripts/common/runit.py python` | 10 Try `scripts/common/runit.py python` |
| 11 or (in scripts/slave): `../common/runit.py runtest.py --help` | 11 or (in scripts/slave): `../common/runit.py runtest.py --help` |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 # Import 'common.env' to load our Infra PYTHONPATH | 19 # Import 'common.env' to load our Infra PYTHONPATH |
| 20 sys.path.insert(0, os.path.join( | 20 sys.path.insert(0, os.path.join( |
| 21 os.path.dirname(os.path.realpath(__file__)), os.pardir)) | 21 os.path.dirname(os.path.realpath(__file__)), os.pardir)) |
| 22 import common.env | 22 import common.env |
| 23 | 23 |
| 24 USAGE = '%s [options] <command to run>' % os.path.basename(sys.argv[0]) | 24 USAGE = '%s [options] <command to run>' % os.path.basename(sys.argv[0]) |
| 25 | 25 |
| 26 # These third_party libs interfere with other imports in PYTHONPATH and should | |
| 27 # be put last. Please file bugs to clean up each entry here. | |
| 28 troublemakers = [] | |
| 29 | |
| 30 | 26 |
| 31 def main(): | 27 def main(): |
| 32 option_parser = optparse.OptionParser(usage=USAGE) | 28 option_parser = optparse.OptionParser(usage=USAGE) |
| 33 option_parser.add_option('-s', '--show-path', action='store_true', | 29 option_parser.add_option('-s', '--show-path', action='store_true', |
| 34 help='display new PYTHONPATH before running command') | 30 help='display new PYTHONPATH before running command') |
| 35 option_parser.disable_interspersed_args() | 31 option_parser.disable_interspersed_args() |
| 36 options, args = option_parser.parse_args() | 32 options, args = option_parser.parse_args() |
| 37 if not args: | 33 if not args: |
| 38 option_parser.error('Must provide a command to run.') | 34 option_parser.error('Must provide a command to run.') |
| 39 | 35 |
| 40 # If the first argument is 'python', replace it with the system executable. | 36 # If the first argument is 'python', replace it with the system executable. |
| 41 if args[0] == 'python': | 37 if args[0] == 'python': |
| 42 args[0] = sys.executable | 38 args[0] = sys.executable |
| 43 | 39 |
| 44 with common.env.GetInfraPythonPath().Enter(): | 40 with common.env.GetInfraPythonPath().Enter(): |
| 45 if options.show_path: | 41 if options.show_path: |
| 46 print 'Set PYTHONPATH: %s' % os.environ['PYTHONPATH'] | 42 print 'Set PYTHONPATH: %s' % os.environ['PYTHONPATH'] |
| 47 # Use subprocess instead of execv because otherwise windows destroys | 43 # Use subprocess instead of execv because otherwise windows destroys |
| 48 # quoting. | 44 # quoting. |
| 49 p = subprocess.Popen(args) | 45 p = subprocess.Popen(args) |
| 50 p.wait() | 46 p.wait() |
| 51 return p.returncode | 47 return p.returncode |
| 52 | 48 |
| 53 | 49 |
| 54 if __name__ == '__main__': | 50 if __name__ == '__main__': |
| 55 sys.exit(main()) | 51 sys.exit(main()) |
| OLD | NEW |