Commit 7438104f authored by abarth@webkit.org's avatar abarth@webkit.org

Rubber stamped by Eric Seidel.

More pep8 compliance.

* Scripts/webkitpy/executive.py:
* Scripts/webkitpy/grammar.py:



git-svn-id: svn://svn.chromium.org/blink/trunk@53777 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f4b4c7e2
2010-01-24 Adam Barth <abarth@webkit.org>
Rubber stamped by Eric Seidel.
More pep8 compliance.
* Scripts/webkitpy/executive.py:
* Scripts/webkitpy/grammar.py:
2010-01-24 Adam Barth <abarth@webkit.org> 2010-01-24 Adam Barth <abarth@webkit.org>
Rubber stamped by Eric Seidel. Rubber stamped by Eric Seidel.
......
# Copyright (c) 2009, Google Inc. All rights reserved. # Copyright (c) 2009, Google Inc. All rights reserved.
# Copyright (c) 2009 Apple Inc. All rights reserved. # Copyright (c) 2009 Apple Inc. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are # modification, are permitted provided that the following conditions are
# met: # met:
# #
# * Redistributions of source code must retain the above copyright # * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer. # notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above # * Redistributions in binary form must reproduce the above
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# * Neither the name of Google Inc. nor the names of its # * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from # contributors may be used to endorse or promote products derived from
# this software without specific prior written permission. # this software without specific prior written permission.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -36,7 +36,13 @@ from webkitpy.webkit_logging import tee ...@@ -36,7 +36,13 @@ from webkitpy.webkit_logging import tee
class ScriptError(Exception): class ScriptError(Exception):
def __init__(self, message=None, script_args=None, exit_code=None, output=None, cwd=None):
def __init__(self,
message=None,
script_args=None,
exit_code=None,
output=None,
cwd=None):
if not message: if not message:
message = 'Failed to run "%s"' % script_args message = 'Failed to run "%s"' % script_args
if exit_code: if exit_code:
...@@ -53,7 +59,8 @@ class ScriptError(Exception): ...@@ -53,7 +59,8 @@ class ScriptError(Exception):
def message_with_output(self, output_limit=500): def message_with_output(self, output_limit=500):
if self.output: if self.output:
if output_limit and len(self.output) > output_limit: if output_limit and len(self.output) > output_limit:
return "%s\nLast %s characters of output:\n%s" % (self, output_limit, self.output[-output_limit:]) return "%s\nLast %s characters of output:\n%s" % \
(self, output_limit, self.output[-output_limit:])
return "%s\n%s" % (self, self.output) return "%s\n%s" % (self, self.output)
return str(self) return str(self)
...@@ -64,17 +71,21 @@ class ScriptError(Exception): ...@@ -64,17 +71,21 @@ class ScriptError(Exception):
return os.path.basename(command_path) return os.path.basename(command_path)
# FIXME: This should not be a global static.
# New code should use Executive.run_command directly instead
def run_command(*args, **kwargs): def run_command(*args, **kwargs):
# FIXME: This should not be a global static.
# New code should use Executive.run_command directly instead
return Executive().run_command(*args, **kwargs) return Executive().run_command(*args, **kwargs)
class Executive(object): class Executive(object):
def _run_command_with_teed_output(self, args, teed_output): def _run_command_with_teed_output(self, args, teed_output):
child_process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) child_process = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
# Use our own custom wait loop because Popen ignores a tee'd stderr/stdout. # Use our own custom wait loop because Popen ignores a tee'd
# stderr/stdout.
# FIXME: This could be improved not to flatten output to stdout. # FIXME: This could be improved not to flatten output to stdout.
while True: while True:
output_line = child_process.stdout.readline() output_line = child_process.stdout.readline()
...@@ -96,7 +107,9 @@ class Executive(object): ...@@ -96,7 +107,9 @@ class Executive(object):
child_out_file.close() child_out_file.close()
if exit_code: if exit_code:
raise ScriptError(script_args=args, exit_code=exit_code, output=child_output) raise ScriptError(script_args=args,
exit_code=exit_code,
output=child_output)
@staticmethod @staticmethod
def cpu_count(): def cpu_count():
...@@ -104,10 +117,14 @@ class Executive(object): ...@@ -104,10 +117,14 @@ class Executive(object):
try: try:
import multiprocessing import multiprocessing
return multiprocessing.cpu_count() return multiprocessing.cpu_count()
except (ImportError,NotImplementedError): except (ImportError, NotImplementedError):
return 2 # This quantity is a lie but probably a reasonable guess for modern machines. # This quantity is a lie but probably a reasonable guess for modern
# machines.
return 2
# Error handlers do not need to be static methods once all callers are
# updated to use an Executive object.
# Error handlers do not need to be static methods once all callers are updated to use an Executive object.
@staticmethod @staticmethod
def default_error_handler(error): def default_error_handler(error):
raise error raise error
...@@ -117,7 +134,14 @@ class Executive(object): ...@@ -117,7 +134,14 @@ class Executive(object):
pass pass
# FIXME: This should be merged with run_and_throw_if_fail # 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):
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. if hasattr(input, 'read'): # Check if the input is a file.
stdin = input stdin = input
string_to_communicate = None string_to_communicate = None
...@@ -129,16 +153,24 @@ class Executive(object): ...@@ -129,16 +153,24 @@ class Executive(object):
else: else:
stderr = None stderr = None
try: try:
process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=stderr, cwd=cwd) process = subprocess.Popen(args,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=stderr,
cwd=cwd)
output = process.communicate(string_to_communicate)[0] output = process.communicate(string_to_communicate)[0]
exit_code = process.wait() exit_code = process.wait()
except OSError, e: except OSError, e:
# Catch OSError exceptions. For example, "no such file or directory" (i.e. OSError errno 2), # Catch OSError exceptions. For example, "no such file or
# when the command cannot be found. # directory" (i.e. OSError errno 2), when the command cannot be
# found.
output = e.strerror output = e.strerror
exit_code = e.errno exit_code = e.errno
if exit_code: if exit_code:
script_error = ScriptError(script_args=args, exit_code=exit_code, output=output, cwd=cwd) script_error = ScriptError(script_args=args,
exit_code=exit_code,
output=output,
cwd=cwd)
(error_handler or self.default_error_handler)(script_error) (error_handler or self.default_error_handler)(script_error)
if return_exit_code: if return_exit_code:
return exit_code return exit_code
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are # modification, are permitted provided that the following conditions are
# met: # met:
# #
# * Redistributions of source code must retain the above copyright # * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer. # notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above # * Redistributions in binary form must reproduce the above
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# * Neither the name of Google Inc. nor the names of its # * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from # contributors may be used to endorse or promote products derived from
# this software without specific prior written permission. # this software without specific prior written permission.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -30,13 +30,15 @@ ...@@ -30,13 +30,15 @@
import re import re
def plural(noun): def plural(noun):
# This is a dumb plural() implementation which was just enough for our uses. # This is a dumb plural() implementation that is just enough for our uses.
if re.search("h$", noun): if re.search("h$", noun):
return noun + "es" return noun + "es"
else: else:
return noun + "s" return noun + "s"
def pluralize(noun, count): def pluralize(noun, count):
if count != 1: if count != 1:
noun = plural(noun) noun = plural(noun)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment