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

Side by Side Diff: recipes.py

Issue 2798393002: Work around unicode issues by re-encoding properties as utf-8 (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 with stream_engine.make_step_stream('Failure reason') as s: 176 with stream_engine.make_step_stream('Failure reason') as s:
177 with s.new_log_stream('reason') as l: 177 with s.new_log_stream('reason') as l:
178 l.write_split(f.human_reason) 178 l.write_split(f.human_reason)
179 179
180 return 1 180 return 1
181 181
182 return 0 182 return 0
183 183
184 184
185 def strip_unicode(obj):
iannucci 2017/04/06 18:10:12 Could we move this function to e.g. util.py and th
186 if isinstance(obj, unicode):
187 return obj.encode('utf-8', 'replace')
188
189 if isinstance(obj, list):
190 return map(strip_unicode, obj)
191
192 if isinstance(obj, dict):
193 new_obj = type(obj)(
194 (strip_unicode(k), strip_unicode(v)) for k, v in obj.iteritems() )
195 return new_obj
196
197 return obj
198
199
185 def run(package_deps, args, op_args): 200 def run(package_deps, args, op_args):
186 from recipe_engine import run as recipe_run 201 from recipe_engine import run as recipe_run
187 from recipe_engine import loader 202 from recipe_engine import loader
188 from recipe_engine import step_runner 203 from recipe_engine import step_runner
189 from recipe_engine import stream 204 from recipe_engine import stream
190 from recipe_engine import stream_logdog 205 from recipe_engine import stream_logdog
191 206
192 def get_properties_from_args(args): 207 def get_properties_from_args(args):
193 properties = dict(x.split('=', 1) for x in args) 208 properties = dict(x.split('=', 1) for x in args)
194 for key, val in properties.iteritems(): 209 for key, val in properties.iteritems():
(...skipping 30 matching lines...) Expand all
225 properties = get_properties_from_json(args.properties) 240 properties = get_properties_from_json(args.properties)
226 elif args.properties_file: 241 elif args.properties_file:
227 properties = get_properties_from_file(args.properties_file) 242 properties = get_properties_from_file(args.properties_file)
228 elif op_properties is not None: 243 elif op_properties is not None:
229 properties = op_properties 244 properties = op_properties
230 else: 245 else:
231 properties = arg_properties 246 properties = arg_properties
232 247
233 properties['recipe'] = args.recipe 248 properties['recipe'] = args.recipe
234 249
250 # Work around unicode issues by re-encoding properties as utf-8.
251 properties = strip_unicode(properties)
252 reload(sys)
iannucci 2017/04/06 18:10:12 Now that I think about this, I would actually do t
253 sys.setdefaultencoding('UTF8')
254
235 os.environ['PYTHONUNBUFFERED'] = '1' 255 os.environ['PYTHONUNBUFFERED'] = '1'
236 os.environ['PYTHONIOENCODING'] = 'UTF-8' 256 os.environ['PYTHONIOENCODING'] = 'UTF-8'
237 257
238 _, config_file = get_package_config(args) 258 _, config_file = get_package_config(args)
239 universe_view = loader.UniverseView( 259 universe_view = loader.UniverseView(
240 loader.RecipeUniverse( 260 loader.RecipeUniverse(
241 package_deps, config_file), package_deps.root_package) 261 package_deps, config_file), package_deps.root_package)
242 262
243 workdir = (args.workdir or 263 workdir = (args.workdir or
244 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) 264 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir'))
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 782
763 if not isinstance(ret, int): 783 if not isinstance(ret, int):
764 if ret is None: 784 if ret is None:
765 ret = 0 785 ret = 0
766 else: 786 else:
767 print >> sys.stderr, ret 787 print >> sys.stderr, ret
768 ret = 1 788 ret = 1
769 sys.stdout.flush() 789 sys.stdout.flush()
770 sys.stderr.flush() 790 sys.stderr.flush()
771 os._exit(ret) 791 os._exit(ret)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698