Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The LUCI Authors. All rights reserved. | 2 # Copyright 2012 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs a command with optional isolated input/output. | 6 """Runs a command with optional isolated input/output. |
| 7 | 7 |
| 8 Despite name "run_isolated", can run a generic non-isolated command specified as | 8 Despite name "run_isolated", can run a generic non-isolated command specified as |
| 9 args. | 9 args. |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 Any ${SWARMING_BOT_FILE} on the command line will be replaced by the value of | 24 Any ${SWARMING_BOT_FILE} on the command line will be replaced by the value of |
| 25 the --bot-file parameter. This file is used by a swarming bot to communicate | 25 the --bot-file parameter. This file is used by a swarming bot to communicate |
| 26 state of the host to tasks. It is written to by the swarming bot's | 26 state of the host to tasks. It is written to by the swarming bot's |
| 27 on_before_task() hook in the swarming server's custom bot_config.py. | 27 on_before_task() hook in the swarming server's custom bot_config.py. |
| 28 """ | 28 """ |
| 29 | 29 |
| 30 __version__ = '0.8.5' | 30 __version__ = '0.8.5' |
| 31 | 31 |
| 32 import base64 | 32 import base64 |
| 33 import collections | 33 import collections |
| 34 import json | |
| 34 import logging | 35 import logging |
| 35 import optparse | 36 import optparse |
| 36 import os | 37 import os |
| 37 import sys | 38 import sys |
| 38 import tempfile | 39 import tempfile |
| 39 import time | 40 import time |
| 40 | 41 |
| 41 from third_party.depot_tools import fix_encoding | 42 from third_party.depot_tools import fix_encoding |
| 42 | 43 |
| 43 from utils import file_path | 44 from utils import file_path |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 'duration': total_duration, | 694 'duration': total_duration, |
| 694 'get_client_duration': get_client_duration, | 695 'get_client_duration': get_client_duration, |
| 695 }, | 696 }, |
| 696 'cipd_pins': { | 697 'cipd_pins': { |
| 697 'client_package': client_package, | 698 'client_package': client_package, |
| 698 'packages': package_pins, | 699 'packages': package_pins, |
| 699 } | 700 } |
| 700 } | 701 } |
| 701 | 702 |
| 702 | 703 |
| 703 def create_option_parser(): | 704 def create_option_parser(): |
|
M-A Ruel
2016/10/21 20:15:20
def create_option_parser(add_file_flag):
| |
| 704 parser = logging_utils.OptionParserWithLogging( | 705 parser = logging_utils.OptionParserWithLogging( |
| 705 usage='%prog <options> [command to run or extra args]', | 706 usage='%prog <options> [command to run or extra args]', |
| 706 version=__version__, | 707 version=__version__, |
| 707 log_file=RUN_ISOLATED_LOG_FILE) | 708 log_file=RUN_ISOLATED_LOG_FILE) |
|
M-A Ruel
2016/10/21 20:15:20
if add_file_flag:
parser.add_option('--file', '-
| |
| 708 parser.add_option( | 709 parser.add_option( |
| 709 '--clean', action='store_true', | 710 '--clean', action='store_true', |
| 710 help='Cleans the cache, trimming it necessary and remove corrupted items ' | 711 help='Cleans the cache, trimming it necessary and remove corrupted items ' |
| 711 'and returns without executing anything; use with -v to know what ' | 712 'and returns without executing anything; use with -v to know what ' |
| 712 'was done') | 713 'was done') |
| 713 parser.add_option( | 714 parser.add_option( |
| 714 '--no-clean', action='store_true', | 715 '--no-clean', action='store_true', |
| 715 help='Do not clean the cache automatically on startup. This is meant for ' | 716 help='Do not clean the cache automatically on startup. This is meant for ' |
| 716 'bots where a separate execution with --clean was done earlier so ' | 717 'bots where a separate execution with --clean was done earlier so ' |
| 717 'doing it again is redundant') | 718 'doing it again is redundant') |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 '--root-dir', help='Use a directory instead of a random one') | 753 '--root-dir', help='Use a directory instead of a random one') |
| 753 parser.add_option_group(debug_group) | 754 parser.add_option_group(debug_group) |
| 754 | 755 |
| 755 auth.add_auth_options(parser) | 756 auth.add_auth_options(parser) |
| 756 | 757 |
| 757 parser.set_defaults(cache='cache', cipd_cache='cipd_cache') | 758 parser.set_defaults(cache='cache', cipd_cache='cipd_cache') |
| 758 return parser | 759 return parser |
| 759 | 760 |
| 760 | 761 |
| 761 def main(args): | 762 def main(args): |
| 762 parser = create_option_parser() | 763 parser = create_option_parser() |
|
M-A Ruel
2016/10/21 20:15:20
parser = create_option_parser(True)
| |
| 763 options, args = parser.parse_args(args) | 764 options, args = parser.parse_args(args) |
| 764 | 765 |
|
M-A Ruel
2016/10/21 20:15:20
if options.file:
if args:
parser.error('Can\
aludwin
2016/10/21 20:32:00
Looks kind of dangerous, relying on an internal fu
aludwin
2016/10/24 13:33:31
So it looks like parser.parse_args can only be cal
| |
| 765 isolated_cache = isolateserver.process_cache_options(options) | 766 isolated_cache = isolateserver.process_cache_options(options) |
| 766 if options.clean: | 767 if options.clean: |
| 767 if options.isolated: | 768 if options.isolated: |
| 768 parser.error('Can\'t use --isolated with --clean.') | 769 parser.error('Can\'t use --isolated with --clean.') |
| 769 if options.isolate_server: | 770 if options.isolate_server: |
| 770 parser.error('Can\'t use --isolate-server with --clean.') | 771 parser.error('Can\'t use --isolate-server with --clean.') |
| 771 if options.json: | 772 if options.json: |
| 772 parser.error('Can\'t use --json with --clean.') | 773 parser.error('Can\'t use --json with --clean.') |
| 773 isolated_cache.cleanup() | 774 isolated_cache.cleanup() |
| 774 return 0 | 775 return 0 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 options.hard_timeout, options.grace_period, options.bot_file, args, | 816 options.hard_timeout, options.grace_period, options.bot_file, args, |
| 816 install_packages_fn, options.use_symlinks) | 817 install_packages_fn, options.use_symlinks) |
| 817 return run_tha_test( | 818 return run_tha_test( |
| 818 command, options.isolated, None, isolated_cache, options.leak_temp_dir, | 819 command, options.isolated, None, isolated_cache, options.leak_temp_dir, |
| 819 options.json, options.root_dir, options.hard_timeout, | 820 options.json, options.root_dir, options.hard_timeout, |
| 820 options.grace_period, options.bot_file, args, install_packages_fn, | 821 options.grace_period, options.bot_file, args, install_packages_fn, |
| 821 options.use_symlinks) | 822 options.use_symlinks) |
| 822 except cipd.Error as ex: | 823 except cipd.Error as ex: |
| 823 print >> sys.stderr, ex.message | 824 print >> sys.stderr, ex.message |
| 824 return 1 | 825 return 1 |
| 825 | 826 |
|
M-A Ruel
2016/10/21 20:15:20
2 lines
aludwin
2016/10/21 20:32:00
Done.
aludwin
2016/10/24 13:33:31
Actually, un-done - see comment above.
| |
| 827 def get_args(args): | |
| 828 if len(args) == 2 and args[0] == '-f': | |
| 829 # If the only args are "-f filename", load those | |
| 830 # instead. | |
| 831 argfile = args[1] | |
| 832 args = [] | |
| 833 try: | |
| 834 f = open(argfile, 'r') | |
| 835 args = json.loads(f.read()) | |
| 836 f.close() | |
| 837 except Exception as e: | |
| 838 print "Couldn't read arguments: %s"%e | |
| 839 return args | |
| 826 | 840 |
| 827 if __name__ == '__main__': | 841 if __name__ == '__main__': |
| 828 subprocess42.inhibit_os_error_reporting() | 842 subprocess42.inhibit_os_error_reporting() |
| 829 # Ensure that we are always running with the correct encoding. | 843 # Ensure that we are always running with the correct encoding. |
| 830 fix_encoding.fix_encoding() | 844 fix_encoding.fix_encoding() |
| 831 file_path.enable_symlink() | 845 file_path.enable_symlink() |
| 832 sys.exit(main(sys.argv[1:])) | 846 |
| 847 sys.exit(main(get_args(sys.argv[1:]))) | |
| OLD | NEW |