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

Side by Side Diff: recipes.py

Issue 1861203002: Make recipes.py run give better messages. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Fix test, remove unneeded description. Created 4 years, 4 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/run.py ('k') | unittests/errors_test.py » ('j') | 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 for key, val in properties.iteritems(): 95 for key, val in properties.iteritems():
96 try: 96 try:
97 properties[key] = json.loads(val) 97 properties[key] = json.loads(val)
98 except (ValueError, SyntaxError): 98 except (ValueError, SyntaxError):
99 pass # If a value couldn't be evaluated, keep the string version 99 pass # If a value couldn't be evaluated, keep the string version
100 return properties 100 return properties
101 101
102 def get_properties_from_file(filename): 102 def get_properties_from_file(filename):
103 properties_file = sys.stdin if filename == '-' else open(filename) 103 properties_file = sys.stdin if filename == '-' else open(filename)
104 properties = json.load(properties_file) 104 properties = json.load(properties_file)
105 if filename == '-':
106 properties_file.close()
105 assert isinstance(properties, dict) 107 assert isinstance(properties, dict)
106 return properties 108 return properties
107 109
108 def get_properties_from_json(props): 110 def get_properties_from_json(props):
109 return json.loads(props) 111 return json.loads(props)
110 112
111 arg_properties = get_properties_from_args(args.props) 113 arg_properties = get_properties_from_args(args.props)
112 assert len(filter(bool, 114 assert len(filter(bool,
113 [arg_properties, args.properties_file, args.properties])) <= 1, ( 115 [arg_properties, args.properties_file, args.properties])) <= 1, (
114 'Only one source of properties is allowed') 116 'Only one source of properties is allowed')
115 if args.properties: 117 if args.properties:
116 properties = get_properties_from_json(args.properties) 118 properties = get_properties_from_json(args.properties)
117 elif args.properties_file: 119 elif args.properties_file:
118 properties = get_properties_from_file(args.properties_file) 120 properties = get_properties_from_file(args.properties_file)
119 else: 121 else:
120 properties = arg_properties 122 properties = arg_properties
121 123
122 properties['recipe'] = args.recipe 124 properties['recipe'] = args.recipe
123 125
124 os.environ['PYTHONUNBUFFERED'] = '1' 126 os.environ['PYTHONUNBUFFERED'] = '1'
125 os.environ['PYTHONIOENCODING'] = 'UTF-8' 127 os.environ['PYTHONIOENCODING'] = 'UTF-8'
126 128
127 _, config_file = get_package_config(args) 129 _, config_file = get_package_config(args)
128 universe = loader.UniverseView( 130 universe_view = loader.UniverseView(
129 loader.RecipeUniverse( 131 loader.RecipeUniverse(
130 package_deps, config_file), package_deps.root_package) 132 package_deps, config_file), package_deps.root_package)
131 133
132 workdir = (args.workdir or 134 workdir = (args.workdir or
133 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) 135 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir'))
134 logging.info('Using %s as work directory' % workdir) 136 logging.info('Using %s as work directory' % workdir)
135 if not os.path.exists(workdir): 137 if not os.path.exists(workdir):
136 os.makedirs(workdir) 138 os.makedirs(workdir)
137 139
138 old_cwd = os.getcwd() 140 old_cwd = os.getcwd()
139 os.chdir(workdir) 141 os.chdir(workdir)
140 stream_engine = stream.ProductStreamEngine( 142 stream_engine = stream.ProductStreamEngine(
141 stream.StreamEngineInvariants(), 143 stream.StreamEngineInvariants(),
142 stream.AnnotatorStreamEngine(sys.stdout, emit_timestamps=args.timestamps)) 144 stream.AnnotatorStreamEngine(sys.stdout, emit_timestamps=args.timestamps))
143 with stream_engine: 145 with stream_engine:
144 try: 146 try:
145 ret = recipe_run.run_steps( 147 ret = recipe_run.run_steps(
146 properties, stream_engine, 148 properties, stream_engine,
147 step_runner.SubprocessStepRunner(stream_engine), 149 step_runner.SubprocessStepRunner(stream_engine),
148 universe=universe) 150 universe_view=universe_view)
149 finally: 151 finally:
150 os.chdir(old_cwd) 152 os.chdir(old_cwd)
151 153
152 return handle_recipe_return(ret, args.output_result_json, stream_engine) 154 return handle_recipe_return(ret, args.output_result_json, stream_engine)
153 155
154 156
155 def remote(args): 157 def remote(args):
156 from recipe_engine import remote 158 from recipe_engine import remote
157 159
158 return remote.main(args) 160 return remote.main(args)
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ret = main() 493 ret = main()
492 if not isinstance(ret, int): 494 if not isinstance(ret, int):
493 if ret is None: 495 if ret is None:
494 ret = 0 496 ret = 0
495 else: 497 else:
496 print >> sys.stderr, ret 498 print >> sys.stderr, ret
497 ret = 1 499 ret = 1
498 sys.stdout.flush() 500 sys.stdout.flush()
499 sys.stderr.flush() 501 sys.stderr.flush()
500 os._exit(ret) 502 os._exit(ret)
OLDNEW
« no previous file with comments | « recipe_engine/run.py ('k') | unittests/errors_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698