[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.17-1283-gcf603cf
eric at webkit.org
eric at webkit.org
Tue Jan 5 23:46:56 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 671dfc49481d41ee3b4aea7c082baecdf6bd405e
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Dec 10 23:47:36 2009 +0000
2009-12-10 Eric Seidel <eric at webkit.org>
Reviewed by Adam Barth.
Move run_command onto Executive to make code which uses run_command testable
https://bugs.webkit.org/show_bug.cgi?id=32396
* Scripts/modules/executive.py:
- Move run_command and error handlers onto Executive.
* Scripts/modules/scm.py:
* Scripts/modules/scm_unittest.py:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51969 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 9bb53a4..a816b8f 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,15 @@
+2009-12-10 Eric Seidel <eric at webkit.org>
+
+ Reviewed by Adam Barth.
+
+ Move run_command onto Executive to make code which uses run_command testable
+ https://bugs.webkit.org/show_bug.cgi?id=32396
+
+ * Scripts/modules/executive.py:
+ - Move run_command and error handlers onto Executive.
+ * Scripts/modules/scm.py:
+ * Scripts/modules/scm_unittest.py:
+
2009-12-09 Eric Seidel <eric at webkit.org>
Reviewed by Adam Barth.
diff --git a/WebKitTools/Scripts/modules/executive.py b/WebKitTools/Scripts/modules/executive.py
index bee0957..b73e17d 100644
--- a/WebKitTools/Scripts/modules/executive.py
+++ b/WebKitTools/Scripts/modules/executive.py
@@ -57,33 +57,11 @@ class ScriptError(Exception):
return "%s\n%s" % (self, self.output)
return str(self)
-def default_error_handler(error):
- raise error
-
-def ignore_error(error):
- pass
# FIXME: This should not be a global static.
-def run_command(args, cwd=None, input=None, error_handler=default_error_handler, return_exit_code=False, return_stderr=True):
- if hasattr(input, 'read'): # Check if the input is a file.
- stdin = input
- string_to_communicate = None
- else:
- stdin = subprocess.PIPE if input else None
- string_to_communicate = input
- if return_stderr:
- stderr = subprocess.STDOUT
- else:
- stderr = None
- process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=stderr, cwd=cwd)
- output = process.communicate(string_to_communicate)[0]
- exit_code = process.wait()
- if exit_code:
- script_error = ScriptError(script_args=args, exit_code=exit_code, output=output, cwd=cwd)
- error_handler(script_error)
- if return_exit_code:
- return exit_code
- return output
+# New code should use Executive.run_command directly instead
+def run_command(*args, **kwargs):
+ return Executive().run_command(*args, **kwargs)
class Executive(object):
@@ -113,3 +91,34 @@ class Executive(object):
if exit_code:
raise ScriptError(script_args=args, exit_code=exit_code, output=child_output)
+
+ # Error handlers do not need to be static methods once all callers are updated to use an Executive object.
+ @staticmethod
+ def default_error_handler(error):
+ raise error
+
+ @staticmethod
+ def ignore_error(error):
+ pass
+
+ # FIXME: This should be merged with run_and_throw_if_fail
+ def run_command(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True):
+ if hasattr(input, 'read'): # Check if the input is a file.
+ stdin = input
+ string_to_communicate = None
+ else:
+ stdin = subprocess.PIPE if input else None
+ string_to_communicate = input
+ if return_stderr:
+ stderr = subprocess.STDOUT
+ else:
+ stderr = None
+ process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=stderr, cwd=cwd)
+ output = process.communicate(string_to_communicate)[0]
+ exit_code = process.wait()
+ if exit_code:
+ script_error = ScriptError(script_args=args, exit_code=exit_code, output=output, cwd=cwd)
+ (error_handler or self.default_error_handler)(script_error)
+ if return_exit_code:
+ return exit_code
+ return output
diff --git a/WebKitTools/Scripts/modules/scm.py b/WebKitTools/Scripts/modules/scm.py
index 613f878..ff26693 100644
--- a/WebKitTools/Scripts/modules/scm.py
+++ b/WebKitTools/Scripts/modules/scm.py
@@ -35,7 +35,7 @@ import subprocess
# Import WebKit-specific modules.
from modules.changelogs import ChangeLog
-from modules.executive import run_command, ScriptError, default_error_handler, ignore_error
+from modules.executive import Executive, run_command, ScriptError
from modules.logging import error, log
def detect_scm_system(path):
@@ -87,7 +87,7 @@ class CheckoutNeedsUpdate(ScriptError):
def commit_error_handler(error):
if re.search("resource out of date", error.output):
raise CheckoutNeedsUpdate(script_args=error.script_args, exit_code=error.exit_code, output=error.output, cwd=error.cwd)
- default_error_handler(error)
+ Executive.default_error_handler(error)
class SCM:
@@ -104,7 +104,7 @@ class SCM:
def ensure_clean_working_directory(self, force_clean):
if not force_clean and not self.working_directory_is_clean():
- print run_command(self.status_command(), error_handler=ignore_error)
+ print run_command(self.status_command(), error_handler=Executive.ignore_error)
raise ScriptError(message="Working directory has modifications, pass --force-clean or --no-clean to continue.")
log("Cleaning working directory")
@@ -368,7 +368,7 @@ class Git(SCM):
@classmethod
def in_working_directory(cls, path):
- return run_command(['git', 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=ignore_error).rstrip() == "true"
+ return run_command(['git', 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
@classmethod
def find_checkout_root(cls, path):
@@ -438,7 +438,7 @@ class Git(SCM):
# I think this will always fail due to ChangeLogs.
# FIXME: We need to detec specific failure conditions and handle them.
- run_command(['git', 'revert', '--no-commit', git_commit], error_handler=ignore_error)
+ run_command(['git', 'revert', '--no-commit', git_commit], error_handler=Executive.ignore_error)
# Fix any ChangeLogs if necessary.
changelog_paths = self.modified_changelogs()
diff --git a/WebKitTools/Scripts/modules/scm_unittest.py b/WebKitTools/Scripts/modules/scm_unittest.py
index e89e276..8e82f3c 100644
--- a/WebKitTools/Scripts/modules/scm_unittest.py
+++ b/WebKitTools/Scripts/modules/scm_unittest.py
@@ -38,7 +38,7 @@ import unittest
import urllib
from datetime import date
-from modules.executive import run_command, ignore_error, ScriptError
+from modules.executive import Executive, run_command, ScriptError
from modules.scm import detect_scm_system, SCM, CheckoutNeedsUpdate, commit_error_handler
# Eventually we will want to write tests which work for both scms. (like update_webkit, changed_files, etc.)
@@ -147,12 +147,12 @@ svn: resource out of date; try updating
"""
command_does_not_exist = ['does_not_exist', 'invalid_option']
self.assertRaises(OSError, run_command, command_does_not_exist)
- self.assertRaises(OSError, run_command, command_does_not_exist, error_handler=ignore_error)
+ self.assertRaises(OSError, run_command, command_does_not_exist, error_handler=Executive.ignore_error)
command_returns_non_zero = ['/bin/sh', '--invalid-option']
self.assertRaises(ScriptError, run_command, command_returns_non_zero)
# Check if returns error text:
- self.assertTrue(run_command(command_returns_non_zero, error_handler=ignore_error))
+ self.assertTrue(run_command(command_returns_non_zero, error_handler=Executive.ignore_error))
self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=git_failure_message))
self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=svn_failure_message))
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list