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

Side by Side Diff: Tools/Scripts/webkitpy/common/system/executive.py

Issue 663023008: Remove deprecated and unused run_and_throw_if_fail from webkitpy (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
OLDNEW
1 # Copyright (c) 2009, Google Inc. All rights reserved. 1 # Copyright (c) 2009, Google Inc. All rights reserved.
2 # Copyright (c) 2009 Apple Inc. All rights reserved. 2 # Copyright (c) 2009 Apple Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 while True: 108 while True:
109 output_line = child_process.stdout.readline() 109 output_line = child_process.stdout.readline()
110 if output_line == "" and child_process.poll() != None: 110 if output_line == "" and child_process.poll() != None:
111 # poll() is not threadsafe and can throw OSError due to: 111 # poll() is not threadsafe and can throw OSError due to:
112 # http://bugs.python.org/issue1731717 112 # http://bugs.python.org/issue1731717
113 return child_process.poll() 113 return child_process.poll()
114 # We assume that the child process wrote to us in utf-8, 114 # We assume that the child process wrote to us in utf-8,
115 # so no re-encoding is necessary before writing here. 115 # so no re-encoding is necessary before writing here.
116 teed_output.write(output_line) 116 teed_output.write(output_line)
117 117
118 # FIXME: Remove this deprecated method and move callers to run_command.
119 # FIXME: This method is a hack to allow running command which both
120 # capture their output and print out to stdin. Useful for things
121 # like "build-webkit" where we want to display to the user that we're buildi ng
122 # but still have the output to stuff into a log file.
123 def run_and_throw_if_fail(self, args, quiet=False, decode_output=True, **kwa rgs):
124 # Cache the child's output locally so it can be used for error reports.
125 child_out_file = StringIO.StringIO()
126 tee_stdout = sys.stdout
127 if quiet:
128 dev_null = open(os.devnull, "w") # FIXME: Does this need an encodin g?
129 tee_stdout = dev_null
130 child_stdout = Tee(child_out_file, tee_stdout)
131 exit_code = self._run_command_with_teed_output(args, child_stdout, **kwa rgs)
132 if quiet:
133 dev_null.close()
134
135 child_output = child_out_file.getvalue()
136 child_out_file.close()
137
138 if decode_output:
139 child_output = child_output.decode(self._child_process_encoding())
140
141 if exit_code:
142 raise ScriptError(script_args=args,
143 exit_code=exit_code,
144 output=child_output)
145 return child_output
146
147 def cpu_count(self): 118 def cpu_count(self):
148 return multiprocessing.cpu_count() 119 return multiprocessing.cpu_count()
149 120
150 @staticmethod 121 @staticmethod
151 def interpreter_for_script(script_path, fs=None): 122 def interpreter_for_script(script_path, fs=None):
152 fs = fs or FileSystem() 123 fs = fs or FileSystem()
153 lines = fs.read_text_file(script_path).splitlines() 124 lines = fs.read_text_file(script_path).splitlines()
154 if not len(lines): 125 if not len(lines):
155 return None 126 return None
156 first_line = lines[0] 127 first_line = lines[0]
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 args = self._stringify_args(args) 332 args = self._stringify_args(args)
362 escaped_args = [] 333 escaped_args = []
363 for arg in args: 334 for arg in args:
364 if isinstance(arg, unicode): 335 if isinstance(arg, unicode):
365 # Escape any non-ascii characters for easy copy/paste 336 # Escape any non-ascii characters for easy copy/paste
366 arg = arg.encode("unicode_escape") 337 arg = arg.encode("unicode_escape")
367 # FIXME: Do we need to fix quotes here? 338 # FIXME: Do we need to fix quotes here?
368 escaped_args.append(arg) 339 escaped_args.append(arg)
369 return " ".join(escaped_args) 340 return " ".join(escaped_args)
370 341
371 # FIXME: run_and_throw_if_fail should be merged into this method.
372 def run_command(self, 342 def run_command(self,
373 args, 343 args,
374 cwd=None, 344 cwd=None,
375 env=None, 345 env=None,
376 input=None, 346 input=None,
377 error_handler=None, 347 error_handler=None,
378 return_exit_code=False, 348 return_exit_code=False,
379 return_stderr=True, 349 return_stderr=True,
380 decode_output=True, debug_logging=True): 350 decode_output=True, debug_logging=True):
381 """Popen wrapper for convenience and to work around python bugs.""" 351 """Popen wrapper for convenience and to work around python bugs."""
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 pool.close() 453 pool.close()
484 pool.join() 454 pool.join()
485 455
486 456
487 def _run_command_thunk(cmd_line_and_cwd): 457 def _run_command_thunk(cmd_line_and_cwd):
488 # Note that this needs to be a bare module (and hence Picklable) method to w ork with multiprocessing.Pool. 458 # Note that this needs to be a bare module (and hence Picklable) method to w ork with multiprocessing.Pool.
489 (cmd_line, cwd) = cmd_line_and_cwd 459 (cmd_line, cwd) = cmd_line_and_cwd
490 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su bprocess.PIPE) 460 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su bprocess.PIPE)
491 stdout, stderr = proc.communicate() 461 stdout, stderr = proc.communicate()
492 return (proc.returncode, stdout, stderr) 462 return (proc.returncode, stdout, stderr)
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py ('k') | Tools/Scripts/webkitpy/common/system/executive_mock.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698