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

Side by Side Diff: recipes.py

Issue 2798393002: Work around unicode issues by re-encoding properties as utf-8 (Closed)
Patch Set: comment 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 | « recipe_modules/json/api.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 """
11 11
12 import argparse 12 import argparse
13 import json 13 import json
14 import logging 14 import logging
15 import os 15 import os
16 import shutil 16 import shutil
17 import subprocess 17 import subprocess
18 import sys 18 import sys
19 import tempfile 19 import tempfile
20 20
21 # This is necessary to ensure that str literals are by-default assumed to hold
22 # utf-8. It also makes the implicit str(unicode(...)) act like
23 # unicode(...).encode('utf-8'), rather than unicode(...).encode('ascii') .
24 reload(sys)
25 sys.setdefaultencoding('UTF8')
26
21 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 27 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
22 sys.path.insert(0, ROOT_DIR) 28 sys.path.insert(0, ROOT_DIR)
23 29
24 from recipe_engine import env 30 from recipe_engine import env
25 from recipe_engine import arguments_pb2 31 from recipe_engine import arguments_pb2
32 from recipe_engine import util as recipe_util
26 from google.protobuf import json_format as jsonpb 33 from google.protobuf import json_format as jsonpb
27 34
28 35
29 def get_package_config(args): 36 def get_package_config(args):
30 from recipe_engine import package 37 from recipe_engine import package
31 38
32 assert args.package, 'No recipe config (--package) given.' 39 assert args.package, 'No recipe config (--package) given.'
33 assert os.path.exists(args.package), ( 40 assert os.path.exists(args.package), (
34 'Given recipes config file %s does not exist.' % args.package) 41 'Given recipes config file %s does not exist.' % args.package)
35 return ( 42 return (
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 properties = get_properties_from_json(args.properties) 232 properties = get_properties_from_json(args.properties)
226 elif args.properties_file: 233 elif args.properties_file:
227 properties = get_properties_from_file(args.properties_file) 234 properties = get_properties_from_file(args.properties_file)
228 elif op_properties is not None: 235 elif op_properties is not None:
229 properties = op_properties 236 properties = op_properties
230 else: 237 else:
231 properties = arg_properties 238 properties = arg_properties
232 239
233 properties['recipe'] = args.recipe 240 properties['recipe'] = args.recipe
234 241
242 properties = recipe_util.strip_unicode(properties)
243
235 os.environ['PYTHONUNBUFFERED'] = '1' 244 os.environ['PYTHONUNBUFFERED'] = '1'
236 os.environ['PYTHONIOENCODING'] = 'UTF-8' 245 os.environ['PYTHONIOENCODING'] = 'UTF-8'
237 246
238 _, config_file = get_package_config(args) 247 _, config_file = get_package_config(args)
239 universe_view = loader.UniverseView( 248 universe_view = loader.UniverseView(
240 loader.RecipeUniverse( 249 loader.RecipeUniverse(
241 package_deps, config_file), package_deps.root_package) 250 package_deps, config_file), package_deps.root_package)
242 251
243 workdir = (args.workdir or 252 workdir = (args.workdir or
244 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) 253 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir'))
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 771
763 if not isinstance(ret, int): 772 if not isinstance(ret, int):
764 if ret is None: 773 if ret is None:
765 ret = 0 774 ret = 0
766 else: 775 else:
767 print >> sys.stderr, ret 776 print >> sys.stderr, ret
768 ret = 1 777 ret = 1
769 sys.stdout.flush() 778 sys.stdout.flush()
770 sys.stderr.flush() 779 sys.stderr.flush()
771 os._exit(ret) 780 os._exit(ret)
OLDNEW
« no previous file with comments | « recipe_modules/json/api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698