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

Side by Side Diff: recipes.py

Issue 2848443003: [recipes.py] add missing helpstrings, merge test subcommands into main parser. (Closed)
Patch Set: rebase Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « recipe_engine/test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 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 """Tool to interact with recipe repositories. 6 """Tool to interact with recipe repositories.
7 7
8 This tool operates on the nearest ancestor directory containing an 8 This tool operates on the nearest ancestor directory containing an
9 infra/config/recipes.cfg. 9 infra/config/recipes.cfg.
10 """ 10 """
(...skipping 19 matching lines...) Expand all
30 30
31 import argparse # this is vendored 31 import argparse # this is vendored
32 from recipe_engine import arguments_pb2 32 from recipe_engine import arguments_pb2
33 from google.protobuf import json_format as jsonpb 33 from google.protobuf import json_format as jsonpb
34 34
35 35
36 from recipe_engine import fetch, lint_test, bundle, depgraph, autoroll 36 from recipe_engine import fetch, lint_test, bundle, depgraph, autoroll
37 from recipe_engine import remote, refs, doc, test, run 37 from recipe_engine import remote, refs, doc, test, run
38 38
39 39
40 # Each of these subcommands has a method:
41 #
42 # def add_subparsers(argparse._SubParsersAction): ...
43 #
44 # which is expected to add a subparser by calling .add_parser on it. In
45 # addition, the add_subparsers method should call .set_defaults on the created
46 # sub-parser, and set the following values:
47 # func (fn(package_deps, args)) - The function called if the sub command is
48 # invoked.
49 # postprocess_func (fn(parser, args)) - A validation/normalization function
50 # which is called if the sub command is invoked. This function can
51 # check/adjust the parsed args, calling parser.error if a problem is
52 # encountered. This function is optional.
53 # bare_command (bool) - This sub command's func will be called before parsing
54 # package_deps. This is only used for the `remote` subcommand. See the
55 # comment in add_common_args for why.
56 #
57 # Example:
58 #
59 # def add_subparsers(parser):
60 # sub = parser.add_parser("subcommand", help="a cool subcommand")
61 # sub.add_argument("--cool_arg", help="it's gotta be cool")
62 #
63 # def postprocess_args(parser, args):
64 # if "cool" not in args.cool_arg:
65 # parser.error("your cool_arg is not cool!")
66 #
67 # sub.set_defaults(func=main)
68 #
69 # def main(package_deps, args):
70 # print args.cool_arg
40 _SUBCOMMANDS = [ 71 _SUBCOMMANDS = [
72 run,
73 test,
74
41 autoroll, 75 autoroll,
42 bundle, 76 bundle,
43 depgraph, 77 depgraph,
44 doc, 78 doc,
45 fetch, 79 fetch,
46 lint_test, 80 lint_test,
47 refs, 81 refs,
48 remote, 82 remote,
49 run,
50 test,
51 ] 83 ]
52 84
53 85
54 def add_common_args(parser): 86 def add_common_args(parser):
55 from recipe_engine import package_io 87 from recipe_engine import package_io
56 88
57 class ProjectOverrideAction(argparse.Action): 89 class ProjectOverrideAction(argparse.Action):
58 def __call__(self, parser, namespace, values, option_string=None): 90 def __call__(self, parser, namespace, values, option_string=None):
59 p = values.split('=', 2) 91 p = values.split('=', 2)
60 if len(p) != 2: 92 if len(p) != 2:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 parser.error('%s forbids --package' % args.command) 175 parser.error('%s forbids --package' % args.command)
144 else: 176 else:
145 if not args.package: 177 if not args.package:
146 parser.error('%s requires --package' % args.command) 178 parser.error('%s requires --package' % args.command)
147 179
148 return post_process_args 180 return post_process_args
149 181
150 182
151 def main(): 183 def main():
152 parser = argparse.ArgumentParser( 184 parser = argparse.ArgumentParser(
153 description='Interact with the recipe system.') 185 description='Interact with the recipe system.')
154 186
155 common_postprocess_func = add_common_args(parser) 187 common_postprocess_func = add_common_args(parser)
156 188
157 subp = parser.add_subparsers() 189 subp = parser.add_subparsers()
158 for module in _SUBCOMMANDS: 190 for module in _SUBCOMMANDS:
159 module.add_subparser(subp) 191 module.add_subparser(subp)
160 192
161 args = parser.parse_args() 193 args = parser.parse_args()
162 common_postprocess_func(parser, args) 194 common_postprocess_func(parser, args)
163 args.postprocess_func(parser, args) 195 args.postprocess_func(parser, args)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 273
242 if not isinstance(ret, int): 274 if not isinstance(ret, int):
243 if ret is None: 275 if ret is None:
244 ret = 0 276 ret = 0
245 else: 277 else:
246 print >> sys.stderr, ret 278 print >> sys.stderr, ret
247 ret = 1 279 ret = 1
248 sys.stdout.flush() 280 sys.stdout.flush()
249 sys.stderr.flush() 281 sys.stderr.flush()
250 os._exit(ret) 282 os._exit(ret)
OLDNEW
« no previous file with comments | « recipe_engine/test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698