Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: client/run_isolated.py

Issue 2443663002: Pass args in file from task_runner to run_isolated (Closed)
Patch Set: Bump run_isolated version number Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/run_isolated.py
diff --git a/client/run_isolated.py b/client/run_isolated.py
index 7c3f063793c8f1356e4ceeb5697043fed212788a..c8343c0a601c60d30ed8f4a6899eba80f2e7282b 100755
--- a/client/run_isolated.py
+++ b/client/run_isolated.py
@@ -27,10 +27,12 @@ state of the host to tasks. It is written to by the swarming bot's
on_before_task() hook in the swarming server's custom bot_config.py.
"""
-__version__ = '0.8.5'
+__version__ = '0.8.6'
+import argparse
import base64
import collections
+import json
import logging
import optparse
import os
@@ -758,9 +760,33 @@ def create_option_parser():
return parser
-def main(args):
+def parse_args(args):
+ # Create a fake mini-parser just to get out the "-a" command. Note that
+ # it's not documented here; instead, it's documented in create_option_parser
M-A Ruel 2016/10/24 20:25:09 It's not?
aludwin 2016/10/24 21:03:53 Whoops, I forgot to actually document it in create
+ # even though that parser will never actually get to parse it. This is
+ # because -f is exclusive with all other options and arguments.
+ file_argparse = argparse.ArgumentParser()
M-A Ruel 2016/10/24 20:25:09 file_argparse = argparse.ArgumentParser(add_help=F
aludwin 2016/10/24 21:03:53 Done.
+ file_argparse.add_argument("-a", "--argsfile")
+ (file_args, nonfile_args) = file_argparse.parse_known_args(args)
+ if not file_args.argsfile == None:
+ if len(nonfile_args) > 0:
+ file_argparse.error('Can\'t specify --argsfile with'
+ 'any other arguments (%s)' % nonfile_args)
+ try:
+ with open(file_args.argsfile, 'r') as f:
+ args = json.loads(f.read())
+ except Exception as e:
M-A Ruel 2016/10/24 20:25:09 except (IOError, OSError, ValueError): as e: pri
aludwin 2016/10/24 21:03:53 We don't need to sys.exit or return. After this li
+ print "Couldn't read arguments: %s" % e
+
+ # Even if we failed to read the args, just call the normal parser now since it
+ # will print the correct help message.
parser = create_option_parser()
options, args = parser.parse_args(args)
+ return (parser, options, args)
+
+
+def main(args):
+ (parser, options, args) = parse_args(args)
isolated_cache = isolateserver.process_cache_options(options)
if options.clean:
@@ -829,4 +855,5 @@ if __name__ == '__main__':
# Ensure that we are always running with the correct encoding.
fix_encoding.fix_encoding()
file_path.enable_symlink()
+
sys.exit(main(sys.argv[1:]))

Powered by Google App Engine
This is Rietveld 408576698