Changeset 51969 in webkit
- Timestamp:
- Dec 10, 2009 3:47:36 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r51959 r51969 1 2009-12-10 Eric Seidel <eric@webkit.org> 2 3 Reviewed by Adam Barth. 4 5 Move run_command onto Executive to make code which uses run_command testable 6 https://bugs.webkit.org/show_bug.cgi?id=32396 7 8 * Scripts/modules/executive.py: 9 - Move run_command and error handlers onto Executive. 10 * Scripts/modules/scm.py: 11 * Scripts/modules/scm_unittest.py: 12 1 13 2009-12-09 Eric Seidel <eric@webkit.org> 2 14 -
trunk/WebKitTools/Scripts/modules/executive.py
r51891 r51969 58 58 return str(self) 59 59 60 def default_error_handler(error):61 raise error62 63 def ignore_error(error):64 pass65 60 66 61 # FIXME: This should not be a global static. 67 def run_command(args, cwd=None, input=None, error_handler=default_error_handler, return_exit_code=False, return_stderr=True): 68 if hasattr(input, 'read'): # Check if the input is a file. 69 stdin = input 70 string_to_communicate = None 71 else: 72 stdin = subprocess.PIPE if input else None 73 string_to_communicate = input 74 if return_stderr: 75 stderr = subprocess.STDOUT 76 else: 77 stderr = None 78 process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=stderr, cwd=cwd) 79 output = process.communicate(string_to_communicate)[0] 80 exit_code = process.wait() 81 if exit_code: 82 script_error = ScriptError(script_args=args, exit_code=exit_code, output=output, cwd=cwd) 83 error_handler(script_error) 84 if return_exit_code: 85 return exit_code 86 return output 62 # New code should use Executive.run_command directly instead 63 def run_command(*args, **kwargs): 64 return Executive().run_command(*args, **kwargs) 87 65 88 66 … … 114 92 if exit_code: 115 93 raise ScriptError(script_args=args, exit_code=exit_code, output=child_output) 94 95 # Error handlers do not need to be static methods once all callers are updated to use an Executive object. 96 @staticmethod 97 def default_error_handler(error): 98 raise error 99 100 @staticmethod 101 def ignore_error(error): 102 pass 103 104 # FIXME: This should be merged with run_and_throw_if_fail 105 def run_command(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True): 106 if hasattr(input, 'read'): # Check if the input is a file. 107 stdin = input 108 string_to_communicate = None 109 else: 110 stdin = subprocess.PIPE if input else None 111 string_to_communicate = input 112 if return_stderr: 113 stderr = subprocess.STDOUT 114 else: 115 stderr = None 116 process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=stderr, cwd=cwd) 117 output = process.communicate(string_to_communicate)[0] 118 exit_code = process.wait() 119 if exit_code: 120 script_error = ScriptError(script_args=args, exit_code=exit_code, output=output, cwd=cwd) 121 (error_handler or self.default_error_handler)(script_error) 122 if return_exit_code: 123 return exit_code 124 return output -
trunk/WebKitTools/Scripts/modules/scm.py
r51889 r51969 36 36 # Import WebKit-specific modules. 37 37 from modules.changelogs import ChangeLog 38 from modules.executive import run_command, ScriptError, default_error_handler, ignore_error38 from modules.executive import Executive, run_command, ScriptError 39 39 from modules.logging import error, log 40 40 … … 88 88 if re.search("resource out of date", error.output): 89 89 raise CheckoutNeedsUpdate(script_args=error.script_args, exit_code=error.exit_code, output=error.output, cwd=error.cwd) 90 default_error_handler(error)90 Executive.default_error_handler(error) 91 91 92 92 … … 105 105 def ensure_clean_working_directory(self, force_clean): 106 106 if not force_clean and not self.working_directory_is_clean(): 107 print run_command(self.status_command(), error_handler= ignore_error)107 print run_command(self.status_command(), error_handler=Executive.ignore_error) 108 108 raise ScriptError(message="Working directory has modifications, pass --force-clean or --no-clean to continue.") 109 109 … … 369 369 @classmethod 370 370 def in_working_directory(cls, path): 371 return run_command(['git', 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler= ignore_error).rstrip() == "true"371 return run_command(['git', 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true" 372 372 373 373 @classmethod … … 439 439 # I think this will always fail due to ChangeLogs. 440 440 # FIXME: We need to detec specific failure conditions and handle them. 441 run_command(['git', 'revert', '--no-commit', git_commit], error_handler= ignore_error)441 run_command(['git', 'revert', '--no-commit', git_commit], error_handler=Executive.ignore_error) 442 442 443 443 # Fix any ChangeLogs if necessary. -
trunk/WebKitTools/Scripts/modules/scm_unittest.py
r51889 r51969 39 39 40 40 from datetime import date 41 from modules.executive import run_command, ignore_error, ScriptError41 from modules.executive import Executive, run_command, ScriptError 42 42 from modules.scm import detect_scm_system, SCM, CheckoutNeedsUpdate, commit_error_handler 43 43 … … 148 148 command_does_not_exist = ['does_not_exist', 'invalid_option'] 149 149 self.assertRaises(OSError, run_command, command_does_not_exist) 150 self.assertRaises(OSError, run_command, command_does_not_exist, error_handler= ignore_error)150 self.assertRaises(OSError, run_command, command_does_not_exist, error_handler=Executive.ignore_error) 151 151 152 152 command_returns_non_zero = ['/bin/sh', '--invalid-option'] 153 153 self.assertRaises(ScriptError, run_command, command_returns_non_zero) 154 154 # Check if returns error text: 155 self.assertTrue(run_command(command_returns_non_zero, error_handler= ignore_error))155 self.assertTrue(run_command(command_returns_non_zero, error_handler=Executive.ignore_error)) 156 156 157 157 self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=git_failure_message))
Note: See TracChangeset
for help on using the changeset viewer.