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

Side by Side Diff: recipes.py

Issue 2265673002: Add LogDog / annotation protobuf support. (Closed) Base URL: https://github.com/luci/recipes-py@step-formal-struct
Patch Set: Stronger flush meta logic, moar test. 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 unified diff | Download patch
« no previous file with comments | « recipe_modules/step/config.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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 engines. We may want to share stream events with more
157 stream.AnnotatorStreamEngine( 158 # than one StreamEngine implementation, so we will accumulate them in a
159 # "stream_engines" list and compose them into a MultiStreamEngine.
160 def build_annotation_stream_engine():
161 return stream.AnnotatorStreamEngine(
158 sys.stdout, 162 sys.stdout,
159 emit_timestamps=(args.timestamps or 163 emit_timestamps=(args.timestamps or
160 op_args.annotation_flags.emit_timestamp))) 164 op_args.annotation_flags.emit_timestamp),
161 with stream_engine: 165 )
166
167 stream_engines = []
168 if op_args.logdog.streamserver_uri:
169 logging.debug('Using LogDog with parameters: [%s]', op_args.logdog)
170 stream_engines.append(stream_logdog.StreamEngine(
171 streamserver_uri=op_args.logdog.streamserver_uri,
172 name_base=(op_args.logdog.name_base or None),
173 ))
174
175 # If we're teeing, also fold in a standard annotation stream engine.
176 if op_args.logdog.tee:
177 stream_engines.append(build_annotation_stream_engine())
178 else:
179 # Not using LogDog; use a standard annotation stream engine.
180 stream_engines.append(build_annotation_stream_engine())
181 multi_stream_engine = stream.MultiStreamEngine.create(*stream_engines)
182
183 # Have a top-level set of invariants to enforce StreamEngine expectations.
184 with stream.StreamEngineInvariants.wrap(multi_stream_engine) as stream_engine:
162 # Emit initial properties if configured to do so. 185 # Emit initial properties if configured to do so.
163 if op_args.annotation_flags.emit_initial_properties: 186 if op_args.annotation_flags.emit_initial_properties:
164 with stream_engine.new_step_stream('Initial Properties') as s: 187 with stream_engine.new_step_stream('Initial Properties') as s:
165 for key in sorted(properties.iterkeys()): 188 for key in sorted(properties.iterkeys()):
166 s.set_build_property(key, json.dumps(properties[key], sort_keys=True)) 189 s.set_build_property(key, json.dumps(properties[key], sort_keys=True))
167 190
168 try: 191 try:
169 ret = recipe_run.run_steps( 192 ret = recipe_run.run_steps(
170 properties, stream_engine, 193 properties, stream_engine,
171 step_runner.SubprocessStepRunner(stream_engine), 194 step_runner.SubprocessStepRunner(stream_engine),
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 598
576 if not isinstance(ret, int): 599 if not isinstance(ret, int):
577 if ret is None: 600 if ret is None:
578 ret = 0 601 ret = 0
579 else: 602 else:
580 print >> sys.stderr, ret 603 print >> sys.stderr, ret
581 ret = 1 604 ret = 1
582 sys.stdout.flush() 605 sys.stdout.flush()
583 sys.stderr.flush() 606 sys.stderr.flush()
584 os._exit(ret) 607 os._exit(ret)
OLDNEW
« no previous file with comments | « recipe_modules/step/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698