OLD | NEW |
---|---|
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 return recipe_result.result['status_code'] | 84 return recipe_result.result['status_code'] |
85 else: | 85 else: |
86 return 0 | 86 return 0 |
87 | 87 |
88 | 88 |
89 def run(package_deps, args, op_args): | 89 def run(package_deps, args, op_args): |
90 from recipe_engine import run as recipe_run | 90 from recipe_engine import run as recipe_run |
91 from recipe_engine import loader | 91 from recipe_engine import loader |
92 from recipe_engine import step_runner | 92 from recipe_engine import step_runner |
93 from recipe_engine import stream | 93 from recipe_engine import stream |
94 from recipe_engine import stream_logdog | |
94 | 95 |
95 def get_properties_from_args(args): | 96 def get_properties_from_args(args): |
96 properties = dict(x.split('=', 1) for x in args) | 97 properties = dict(x.split('=', 1) for x in args) |
97 for key, val in properties.iteritems(): | 98 for key, val in properties.iteritems(): |
98 try: | 99 try: |
99 properties[key] = json.loads(val) | 100 properties[key] = json.loads(val) |
100 except (ValueError, SyntaxError): | 101 except (ValueError, SyntaxError): |
101 pass # If a value couldn't be evaluated, keep the string version | 102 pass # If a value couldn't be evaluated, keep the string version |
102 return properties | 103 return properties |
103 | 104 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 package_deps, config_file), package_deps.root_package) | 145 package_deps, config_file), package_deps.root_package) |
145 | 146 |
146 workdir = (args.workdir or | 147 workdir = (args.workdir or |
147 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 148 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
148 logging.info('Using %s as work directory' % workdir) | 149 logging.info('Using %s as work directory' % workdir) |
149 if not os.path.exists(workdir): | 150 if not os.path.exists(workdir): |
150 os.makedirs(workdir) | 151 os.makedirs(workdir) |
151 | 152 |
152 old_cwd = os.getcwd() | 153 old_cwd = os.getcwd() |
153 os.chdir(workdir) | 154 os.chdir(workdir) |
154 stream_engine = stream.ProductStreamEngine( | 155 |
155 stream.StreamEngineInvariants(), | 156 # Construct our stream engine. |
156 stream.AnnotatorStreamEngine( | 157 # |
158 # We begin with a ProductStreamEngine seeded with StreamEngineInvariants. As | |
159 # we evaluate our configuration, we will append additional StreamEngine | |
160 # instances to the ProductStreamEngine. | |
161 stream_engine = stream.ProductStreamEngine(stream.StreamEngineInvariants()) | |
162 | |
163 def build_annotation_stream_engine(): | |
164 return stream.AnnotatorStreamEngine( | |
157 sys.stdout, | 165 sys.stdout, |
158 emit_timestamps=(args.timestamps or | 166 emit_timestamps=(args.timestamps or |
159 op_args.annotation_flags.emit_timestamp))) | 167 op_args.annotation_flags.emit_timestamp), |
168 ) | |
169 | |
170 if op_args.logdog.streamserver_uri: | |
171 # We're using LogDog. | |
martiniss
2016/09/01 21:59:48
add some logging?
dnj
2016/09/07 17:54:58
Done.
| |
172 stream_engine.append_stream_engine(stream_logdog.StreamEngine( | |
173 streamserver_uri=op_args.logdog.streamserver_uri, | |
174 name_base=(op_args.logdog.name_base or None), | |
175 annotation_name=(op_args.logdog.annotation_name or None), | |
176 )) | |
177 | |
178 # If we're teeing, also fold in a standard annotation stream engine. | |
179 if op_args.logdog.tee: | |
180 stream_engine.append_stream_engine(build_annotation_stream_engine()) | |
181 else: | |
182 # Not using LogDog; use a standard annotation stream engine. | |
183 stream_engine.append_stream_engine(build_annotation_stream_engine()) | |
184 | |
160 with stream_engine: | 185 with stream_engine: |
161 # Emit initial properties if configured to do so. | 186 # Emit initial properties if configured to do so. |
162 if op_args.annotation_flags.emit_initial_properties: | 187 if op_args.annotation_flags.emit_initial_properties: |
163 with stream_engine.new_step_stream('Initial Properties') as s: | 188 with stream_engine.new_step_stream('Initial Properties') as s: |
164 for key in sorted(properties.iterkeys()): | 189 for key in sorted(properties.iterkeys()): |
165 s.set_build_property(key, json.dumps(properties[key], sort_keys=True)) | 190 s.set_build_property(key, json.dumps(properties[key], sort_keys=True)) |
166 | 191 |
167 try: | 192 try: |
168 ret = recipe_run.run_steps( | 193 ret = recipe_run.run_steps( |
169 properties, stream_engine, | 194 properties, stream_engine, |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 ret = main() | 592 ret = main() |
568 if not isinstance(ret, int): | 593 if not isinstance(ret, int): |
569 if ret is None: | 594 if ret is None: |
570 ret = 0 | 595 ret = 0 |
571 else: | 596 else: |
572 print >> sys.stderr, ret | 597 print >> sys.stderr, ret |
573 ret = 1 | 598 ret = 1 |
574 sys.stdout.flush() | 599 sys.stdout.flush() |
575 sys.stderr.flush() | 600 sys.stderr.flush() |
576 os._exit(ret) | 601 os._exit(ret) |
OLD | NEW |