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

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

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 self.script_args = script_args # 'args' is already used by Exception 71 self.script_args = script_args # 'args' is already used by Exception
72 self.exit_code = exit_code 72 self.exit_code = exit_code
73 self.output = output 73 self.output = output
74 self.cwd = cwd 74 self.cwd = cwd
75 75
76 def message_with_output(self): 76 def message_with_output(self):
77 return unicode(self) 77 return unicode(self)
78 78
79 def command_name(self): 79 def command_name(self):
80 command_path = self.script_args 80 command_path = self.script_args
81 if type(command_path) is list: 81 if isinstance(command_path, list):
82 command_path = command_path[0] 82 command_path = command_path[0]
83 return os.path.basename(command_path) 83 return os.path.basename(command_path)
84 84
85 85
86 class Executive(object): 86 class Executive(object):
87 PIPE = subprocess.PIPE 87 PIPE = subprocess.PIPE
88 STDOUT = subprocess.STDOUT 88 STDOUT = subprocess.STDOUT
89 DEVNULL = open(os.devnull, 'wb') 89 DEVNULL = open(os.devnull, 'wb')
90 90
91 def _should_close_fds(self): 91 def _should_close_fds(self):
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 # According to http://docs.python.org/library/os.html 139 # According to http://docs.python.org/library/os.html
140 # os.kill isn't available on Windows. python 2.5.5 os.kill appears 140 # os.kill isn't available on Windows. python 2.5.5 os.kill appears
141 # to work in cygwin, however it occasionally raises EAGAIN. 141 # to work in cygwin, however it occasionally raises EAGAIN.
142 retries_left = 10 if sys.platform == "cygwin" else 1 142 retries_left = 10 if sys.platform == "cygwin" else 1
143 while retries_left > 0: 143 while retries_left > 0:
144 try: 144 try:
145 retries_left -= 1 145 retries_left -= 1
146 os.kill(pid, signal.SIGKILL) 146 os.kill(pid, signal.SIGKILL)
147 _ = os.waitpid(pid, os.WNOHANG) 147 _ = os.waitpid(pid, os.WNOHANG)
148 except OSError, e: 148 except OSError as e:
149 if e.errno == errno.EAGAIN: 149 if e.errno == errno.EAGAIN:
150 if retries_left <= 0: 150 if retries_left <= 0:
151 _log.warn("Failed to kill pid %s. Too many EAGAIN error s." % pid) 151 _log.warn("Failed to kill pid %s. Too many EAGAIN error s." % pid)
152 continue 152 continue
153 if e.errno == errno.ESRCH: # The process does not exist. 153 if e.errno == errno.ESRCH: # The process does not exist.
154 return 154 return
155 if e.errno == errno.EPIPE: # The process has exited already on cygwin 155 if e.errno == errno.EPIPE: # The process has exited already on cygwin
156 return 156 return
157 if e.errno == errno.ECHILD: 157 if e.errno == errno.ECHILD:
158 # Can't wait on a non-child process, but the kill worked. 158 # Can't wait on a non-child process, but the kill worked.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if not process_name_filter: 237 if not process_name_filter:
238 process_name_filter = lambda process_name: True 238 process_name_filter = lambda process_name: True
239 239
240 running_pids = [] 240 running_pids = []
241 for line in self._running_processes(): 241 for line in self._running_processes():
242 try: 242 try:
243 process_name = line[0] 243 process_name = line[0]
244 pid = line[1] 244 pid = line[1]
245 if process_name_filter(process_name): 245 if process_name_filter(process_name):
246 running_pids.append(int(pid)) 246 running_pids.append(int(pid))
247 except (ValueError, IndexError), e: 247 except (ValueError, IndexError) as e:
248 pass 248 pass
249 249
250 return sorted(running_pids) 250 return sorted(running_pids)
251 251
252 def process_dump(self): 252 def process_dump(self):
253 ps_process = None 253 ps_process = None
254 if sys.platform in ("win32", "cygwin"): 254 if sys.platform in ("win32", "cygwin"):
255 ps_process = self.popen( 255 ps_process = self.popen(
256 ['wmic', 'process', 'get', 256 ['wmic', 'process', 'get',
257 'ProcessId,ParentProcessId,CommandLine'], 257 'ProcessId,ParentProcessId,CommandLine'],
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 pool.close() 457 pool.close()
458 pool.join() 458 pool.join()
459 459
460 460
461 def _run_command_thunk(cmd_line_and_cwd): 461 def _run_command_thunk(cmd_line_and_cwd):
462 # Note that this needs to be a bare module (and hence Picklable) method to w ork with multiprocessing.Pool. 462 # Note that this needs to be a bare module (and hence Picklable) method to w ork with multiprocessing.Pool.
463 (cmd_line, cwd) = cmd_line_and_cwd 463 (cmd_line, cwd) = cmd_line_and_cwd
464 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su bprocess.PIPE) 464 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su bprocess.PIPE)
465 stdout, stderr = proc.communicate() 465 stdout, stderr = proc.communicate()
466 return (proc.returncode, stdout, stderr) 466 return (proc.returncode, stdout, stderr)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698