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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return recipe_result.result['status_code'] | 85 return recipe_result.result['status_code'] |
86 else: | 86 else: |
87 return 0 | 87 return 0 |
88 | 88 |
89 | 89 |
90 def run(package_deps, args, op_args): | 90 def run(package_deps, args, op_args): |
91 from recipe_engine import run as recipe_run | 91 from recipe_engine import run as recipe_run |
92 from recipe_engine import loader | 92 from recipe_engine import loader |
93 from recipe_engine import step_runner | 93 from recipe_engine import step_runner |
94 from recipe_engine import stream | 94 from recipe_engine import stream |
| 95 from recipe_engine import stream_logdog |
95 | 96 |
96 def get_properties_from_args(args): | 97 def get_properties_from_args(args): |
97 properties = dict(x.split('=', 1) for x in args) | 98 properties = dict(x.split('=', 1) for x in args) |
98 for key, val in properties.iteritems(): | 99 for key, val in properties.iteritems(): |
99 try: | 100 try: |
100 properties[key] = json.loads(val) | 101 properties[key] = json.loads(val) |
101 except (ValueError, SyntaxError): | 102 except (ValueError, SyntaxError): |
102 pass # If a value couldn't be evaluated, keep the string version | 103 pass # If a value couldn't be evaluated, keep the string version |
103 return properties | 104 return properties |
104 | 105 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 package_deps, config_file), package_deps.root_package) | 146 package_deps, config_file), package_deps.root_package) |
146 | 147 |
147 workdir = (args.workdir or | 148 workdir = (args.workdir or |
148 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 149 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
149 logging.info('Using %s as work directory' % workdir) | 150 logging.info('Using %s as work directory' % workdir) |
150 if not os.path.exists(workdir): | 151 if not os.path.exists(workdir): |
151 os.makedirs(workdir) | 152 os.makedirs(workdir) |
152 | 153 |
153 old_cwd = os.getcwd() | 154 old_cwd = os.getcwd() |
154 os.chdir(workdir) | 155 os.chdir(workdir) |
155 stream_engine = stream.ProductStreamEngine( | 156 |
156 stream.StreamEngineInvariants(), | 157 # Construct our stream engine. |
157 stream.AnnotatorStreamEngine( | 158 # |
| 159 # We begin with a ProductStreamEngine seeded with StreamEngineInvariants. As |
| 160 # we evaluate our configuration, we will append additional StreamEngine |
| 161 # instances to the ProductStreamEngine. |
| 162 stream_engine = stream.ProductStreamEngine(stream.StreamEngineInvariants()) |
| 163 |
| 164 def build_annotation_stream_engine(): |
| 165 return stream.AnnotatorStreamEngine( |
158 sys.stdout, | 166 sys.stdout, |
159 emit_timestamps=(args.timestamps or | 167 emit_timestamps=(args.timestamps or |
160 op_args.annotation_flags.emit_timestamp))) | 168 op_args.annotation_flags.emit_timestamp), |
| 169 ) |
| 170 |
| 171 if op_args.logdog.streamserver_uri: |
| 172 logging.debug('Using LogDog with parameters [%v]', op_args.logdog) |
| 173 stream_engine.append_stream_engine(stream_logdog.StreamEngine( |
| 174 streamserver_uri=op_args.logdog.streamserver_uri, |
| 175 name_base=(op_args.logdog.name_base 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 |
161 with stream_engine: | 185 with stream_engine: |
162 # Emit initial properties if configured to do so. | 186 # Emit initial properties if configured to do so. |
163 if op_args.annotation_flags.emit_initial_properties: | 187 if op_args.annotation_flags.emit_initial_properties: |
164 with stream_engine.new_step_stream('Initial Properties') as s: | 188 with stream_engine.new_step_stream('Initial Properties') as s: |
165 for key in sorted(properties.iterkeys()): | 189 for key in sorted(properties.iterkeys()): |
166 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)) |
167 | 191 |
168 try: | 192 try: |
169 ret = recipe_run.run_steps( | 193 ret = recipe_run.run_steps( |
170 properties, stream_engine, | 194 properties, stream_engine, |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 599 |
576 if not isinstance(ret, int): | 600 if not isinstance(ret, int): |
577 if ret is None: | 601 if ret is None: |
578 ret = 0 | 602 ret = 0 |
579 else: | 603 else: |
580 print >> sys.stderr, ret | 604 print >> sys.stderr, ret |
581 ret = 1 | 605 ret = 1 |
582 sys.stdout.flush() | 606 sys.stdout.flush() |
583 sys.stderr.flush() | 607 sys.stderr.flush() |
584 os._exit(ret) | 608 os._exit(ret) |
OLD | NEW |