diff options
98 files changed, 498 insertions, 559 deletions
diff --git a/tools/bisect-builds.py b/tools/bisect-builds.py index a4a3f75..6a4d09d 100755 --- a/tools/bisect-builds.py +++ b/tools/bisect-builds.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -45,6 +45,7 @@ import urllib from xml.etree import ElementTree import zipfile + class PathContext(object): """A PathContext is used to carry the information used to construct URLs and paths when dealing with the storage server and archives.""" @@ -267,6 +268,7 @@ def RunRevision(context, revision, zipfile, profile, args): return (subproc.returncode, stdout, stderr) + def AskIsGoodBuild(rev, status, stdout, stderr): """Ask the user whether build |rev| is good or bad.""" # Loop until we get a response that we can parse. @@ -277,6 +279,7 @@ def AskIsGoodBuild(rev, status, stdout, stderr): if response and response == 'q': raise SystemExit() + def Bisect(platform, good_rev=0, bad_rev=0, @@ -534,5 +537,6 @@ def main(): print 'Built at revision:' print BUILD_VIEWVC_URL % first_known_bad_rev + if __name__ == '__main__': sys.exit(main()) diff --git a/tools/checkdeps/checkdeps.py b/tools/checkdeps/checkdeps.py index f4dee41..02d8d14 100755 --- a/tools/checkdeps/checkdeps.py +++ b/tools/checkdeps/checkdeps.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -91,6 +91,7 @@ BASE_DIRECTORY = "" # The directories which contain the sources managed by git. GIT_SOURCE_DIRECTORY = set() + # Specifies a single rule for an include, which can be either allow or disallow. class Rule(object): def __init__(self, allow, dir, source): @@ -445,7 +446,8 @@ Examples: python checkdeps.py python checkdeps.py --root c:\\source chrome""" -def main(options, args): + +def checkdeps(options, args): global VERBOSE if options.verbose: VERBOSE = True @@ -469,7 +471,7 @@ def main(options, args): else: # More than one argument, we don't handle this. PrintUsage() - sys.exit(1) + return 1 print "Using base directory:", BASE_DIRECTORY print "Checking:", start_dir @@ -491,11 +493,12 @@ def main(options, args): success = CheckDirectory(base_rules, start_dir) if not success: print "\nFAILED\n" - sys.exit(1) + return 1 print "\nSUCCESS\n" - sys.exit(0) + return 0 -if '__main__' == __name__: + +def main(): option_parser = optparse.OptionParser() option_parser.add_option("", "--root", default="", dest="base_directory", help='Specifies the repository root. This defaults ' @@ -504,4 +507,8 @@ if '__main__' == __name__: option_parser.add_option("-v", "--verbose", action="store_true", default=False, help="Print debug logging") options, args = option_parser.parse_args() - main(options, args) + return checkdeps(options, args) + + +if '__main__' == __name__: + sys.exit(main()) diff --git a/tools/checklicenses/checklicenses.py b/tools/checklicenses/checklicenses.py index 4fd2c05..9b40d19 100755 --- a/tools/checklicenses/checklicenses.py +++ b/tools/checklicenses/checklicenses.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -411,7 +411,7 @@ PATH_SPECIFIC_WHITELISTED_LICENSES = { } -def main(options, args): +def check_licenses(options, args): # Figure out which directory we have to check. if len(args) == 0: # No directory to check specified, use the repository root. @@ -423,7 +423,7 @@ def main(options, args): else: # More than one argument, we don't handle this. PrintUsage() - sys.exit(1) + return 1 print "Using base directory:", options.base_directory print "Checking:", start_dir @@ -447,7 +447,7 @@ def main(options, args): print stderr print '--------- end licensecheck stderr ---------' print "\nFAILED\n" - sys.exit(1) + return 1 success = True for line in stdout.splitlines(): @@ -484,7 +484,7 @@ def main(options, args): if success: print "\nSUCCESS\n" - sys.exit(0) + return 0 else: print "\nFAILED\n" print "Please read", @@ -493,11 +493,10 @@ def main(options, args): print print "Please respect OWNERS of checklicenses.py. Changes violating" print "this requirement may be reverted." + return 1 - sys.exit(1) - -if '__main__' == __name__: +def main(): default_root = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..')) option_parser = optparse.OptionParser() @@ -513,4 +512,8 @@ if '__main__' == __name__: default=False, help='Ignore path-specific license whitelist.') options, args = option_parser.parse_args() - main(options, args) + return check_licenses(options, args) + + +if '__main__' == __name__: + sys.exit(main()) diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py index 887b089..6983619 100644..100755 --- a/tools/clang/scripts/update.py +++ b/tools/clang/scripts/update.py @@ -1,18 +1,20 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Windows can't run .sh files, so this is a small python wrapper around -# update.sh. +"""Windows can't run .sh files, so this is a small python wrapper around +update.sh. +""" import os import subprocess import sys -if __name__ == '__main__': + +def main(): if sys.platform in ['win32', 'cygwin']: - sys.exit(0) + return 0 # This script is called by gclient. gclient opens its hooks subprocesses with # (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does custom @@ -24,6 +26,10 @@ if __name__ == '__main__': # is writable, try # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') # TODO: Fix gclient instead, http://crbug.com/95350 - subprocess.call( + return subprocess.call( [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], stderr=sys.stdin) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/code_coverage/coverage.py b/tools/code_coverage/coverage.py index a34a230..6e524ea 100644..100755 --- a/tools/code_coverage/coverage.py +++ b/tools/code_coverage/coverage.py @@ -1,5 +1,5 @@ #!/bin/env python -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -107,7 +107,6 @@ class Coverage(object): self._dir = tempfile.mkdtemp() self._archive = archive - def SetUp(self, binaries): """Set up the platform specific environment and instrument the binaries for coverage. @@ -157,7 +156,6 @@ class Coverage(object): self.instrumented = True return True - def TearDown(self): """Tear down method. @@ -188,7 +186,6 @@ class Coverage(object): # Reset the instrumented flag. self.instrumented = False - def RunTest(self, src_root, test): """Run tests and collect the .coverage file @@ -238,7 +235,6 @@ class Coverage(object): # Return the intermediate .coverage file return coverage_file - def Upload(self, list_coverage, upload_path, sym_path=None, src_root=None): """Upload the results to the dashboard. diff --git a/tools/code_coverage/croc.py b/tools/code_coverage/croc.py index 6999bf5..770e7f5 100755 --- a/tools/code_coverage/croc.py +++ b/tools/code_coverage/croc.py @@ -1,33 +1,7 @@ #!/usr/bin/env python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Crocodile - compute coverage numbers for Chrome coverage dashboard.""" @@ -741,7 +715,5 @@ def Main(argv): return 0 -#------------------------------------------------------------------------------ - if __name__ == '__main__': sys.exit(Main(sys.argv)) diff --git a/tools/code_coverage/croc_html.py b/tools/code_coverage/croc_html.py index 79ec85d..0e07a5a 100644 --- a/tools/code_coverage/croc_html.py +++ b/tools/code_coverage/croc_html.py @@ -1,33 +1,6 @@ -#!/usr/bin/python2.4 -# -# Copyright 2009, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Crocodile HTML output.""" @@ -450,4 +423,3 @@ class CrocHtml(object): # Write files in root directory self.WriteRoot() - diff --git a/tools/code_coverage/croc_scan.py b/tools/code_coverage/croc_scan.py index e40b45e..8d0e2e8 100644 --- a/tools/code_coverage/croc_scan.py +++ b/tools/code_coverage/croc_scan.py @@ -1,33 +1,6 @@ -#!/usr/bin/python2.4 -# -# Copyright 2009, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Crocodile source scanners.""" diff --git a/tools/code_coverage/croc_scan_test.py b/tools/code_coverage/croc_scan_test.py index 17fc7fa..a69b28a 100644..100755 --- a/tools/code_coverage/croc_scan_test.py +++ b/tools/code_coverage/croc_scan_test.py @@ -1,45 +1,14 @@ -#!/usr/bin/python2.4 -# -# Copyright 2009, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Unit tests for croc_scan.py.""" -#import os import re -#import sys -#import StringIO import unittest import croc_scan -#------------------------------------------------------------------------------ - class TestScanner(unittest.TestCase): """Tests for croc_scan.Scanner.""" @@ -213,7 +182,6 @@ class TestScanFile(unittest.TestCase): self.assertEqual(croc_scan.ScanFile('bar4', 'ObjC++'), 'scan cpp bar4') self.assertEqual(croc_scan.ScanFile('bar', 'fortran'), []) -#------------------------------------------------------------------------------ if __name__ == '__main__': unittest.main() diff --git a/tools/code_coverage/croc_test.py b/tools/code_coverage/croc_test.py index 36fc546..7c2521c 100644..100755 --- a/tools/code_coverage/croc_test.py +++ b/tools/code_coverage/croc_test.py @@ -1,33 +1,7 @@ -#!/usr/bin/python2.4 -# -# Copyright 2009, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Unit tests for Crocodile.""" @@ -36,8 +10,6 @@ import StringIO import unittest import croc -#------------------------------------------------------------------------------ - class TestCoverageStats(unittest.TestCase): """Tests for croc.CoverageStats.""" @@ -62,8 +34,6 @@ class TestCoverageStats(unittest.TestCase): c.Add({'a': 4, 'd': 3}) self.assertEqual(c, {'a': 5, 'b': 0, 'c': 5, 'd': 3}) -#------------------------------------------------------------------------------ - class TestCoveredFile(unittest.TestCase): """Tests for croc.CoveredFile.""" @@ -144,8 +114,6 @@ class TestCoveredFile(unittest.TestCase): 'files_covered': 1, }) -#------------------------------------------------------------------------------ - class TestCoveredDir(unittest.TestCase): """Tests for croc.CoveredDir.""" @@ -193,8 +161,6 @@ class TestCoveredDir(unittest.TestCase): d2.subdirs = {'/a/b/d': d4, '/a/b/e': d5} self.assertEqual(d1.GetTree(), 'a/\n b/\n d/\n e/\n c/') -#------------------------------------------------------------------------------ - class TestCoverage(unittest.TestCase): """Tests for croc.Coverage.""" @@ -787,7 +753,6 @@ GetStat('nosuch') = 42 # ParseLcovFile() # PrintTree() -#------------------------------------------------------------------------------ if __name__ == '__main__': unittest.main() diff --git a/tools/code_coverage/process_coverage.py b/tools/code_coverage/process_coverage.py index 8f6ccbf..07d83ac 100644..100755 --- a/tools/code_coverage/process_coverage.py +++ b/tools/code_coverage/process_coverage.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -345,9 +345,9 @@ def SendPost(req): def main(): - if sys.platform[:5] != 'linux': # Run this only on Linux + if not sys.platform.startswith('linux'): print 'This script is supported only on Linux' - os.exit(1) + return 0 # Command line parsing parser = optparse.OptionParser() @@ -395,18 +395,19 @@ def main(): if percent == None: # TODO(niranjan): Add logging. print 'Failed to generate code coverage' - os.exit(1) + return 1 else: # TODO(niranjan): Do something with the code coverage numbers pass else: print 'Unsupported platform' - os.exit(1) + return 1 # Prep coverage results for dashboard and post new set. parsed_data = ParseCoverageDataForDashboard(options.lcov_path) PostResultsToDashboard(options.lcov_path, parsed_data, options.post_url) + return 0 if __name__ == '__main__': - main() + sys.exit(main()) diff --git a/tools/coverity/coverity.py b/tools/coverity/coverity.py index 2080e74..6fed7ca 100644..100755 --- a/tools/coverity/coverity.py +++ b/tools/coverity/coverity.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -77,6 +77,7 @@ COVERITY_USER = 'admin' # Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script. LOCK_FILE = 'coverity.lock' + def _ReadPassword(pwfilename): """Reads the coverity password in from a file where it was stashed""" pwfile = open(pwfilename, 'r') @@ -84,6 +85,7 @@ def _ReadPassword(pwfilename): pwfile.close() return password.rstrip() + def _RunCommand(cmd, dry_run, shell=False, echo_cmd=True): """Runs the command if dry_run is false, otherwise just prints the command.""" if echo_cmd: @@ -93,12 +95,14 @@ def _RunCommand(cmd, dry_run, shell=False, echo_cmd=True): else: return 0 + def _ReleaseLock(lock_file, lock_filename): """Removes the lockfile. Function-ized so we can bail from anywhere""" os.close(lock_file) os.remove(lock_filename) -def main(options, args): + +def run_coverity(options, args): """Runs all the selected tests for the given build type and target.""" # Create the lock file to prevent another instance of this script from # running. @@ -130,7 +134,7 @@ def main(options, args): if gclient_exit != 0: print 'gclient aborted with status %s' % gclient_exit _ReleaseLock(lock_file, lock_filename) - sys.exit(1) + return 1 print 'Elapsed time: %ds' % (time.time() - start_time) @@ -145,7 +149,7 @@ def main(options, args): else: print 'Platform "%s" unrecognized, aborting' % sys.platform _ReleaseLock(lock_file, lock_filename) - sys.exit(1) + return 1 if options.dry_run: print 'shutil.rmtree(%s)' % repr(rm_path) @@ -229,7 +233,8 @@ def main(options, args): return 0 -if '__main__' == __name__: + +def main(): option_parser = optparse.OptionParser() option_parser.add_option('', '--dry-run', action='store_true', default=False, help='print but don\'t run the commands') @@ -296,6 +301,8 @@ if '__main__' == __name__: default=False) options, args = option_parser.parse_args() + return run_coverity(options, args) - result = main(options, args) - sys.exit(result) + +if '__main__' == __name__: + sys.exit(main()) diff --git a/tools/crx_id/PRESUBMIT.py b/tools/crx_id/PRESUBMIT.py index 1473a3c..e8daa88 100644 --- a/tools/crx_id/PRESUBMIT.py +++ b/tools/crx_id/PRESUBMIT.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/crx_id/crx_id.py b/tools/crx_id/crx_id.py index 6350068..299e1d6 100755 --- a/tools/crx_id/crx_id.py +++ b/tools/crx_id/crx_id.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -13,12 +13,14 @@ for docs on the format. import sys import hashlib -def usage(argv): - print "%s: crx_file" % argv[0] EXPECTED_CRX_MAGIC_NUM = 'Cr24' EXPECTED_CRX_VERSION = 2 + +def usage(argv): + print "%s: crx_file" % argv[0] + def HexToInt(hex_chars): """ Convert bytes like \xab -> 171 """ val = 0 @@ -81,6 +83,7 @@ def GetCRXAppID(filename): # AppID is the MPDecimal of only the first 128 bits of the hash. return HexToMPDecimal(pub_key_hash[:128/8]) + def main(argv): if len(argv) != 2: usage(argv) @@ -88,5 +91,6 @@ def main(argv): print 'Raw Bytes: %s' % GetCRXHash(sys.argv[1]) print 'AppID: %s' % GetCRXAppID(sys.argv[1]) + if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py b/tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py index 97c410c..15d8446 100644..100755 --- a/tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py +++ b/tools/dromaeo_benchmark_runner/dromaeo_benchmark_runner.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -# -# Copyright 2009 Google Inc. All Rights Reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Dromaeo benchmark automation script. @@ -48,6 +49,7 @@ import gdata.spreadsheet.service max_spreadsheet_columns = 20 test_props = ['mean', 'error'] + def ParseArguments(): parser = OptionParser() parser.add_option("-b", "--browser", @@ -257,7 +259,8 @@ def main(): spreadsheet_writer.WriteBrowserBenchmarkResults(test_name, test_data) server.socket.close() + return 0 -if __name__ == '__main__': - main() +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/export_tarball/export_tarball.py b/tools/export_tarball/export_tarball.py index 97cba10..861503e 100644..100755 --- a/tools/export_tarball/export_tarball.py +++ b/tools/export_tarball/export_tarball.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -22,6 +22,7 @@ import subprocess import sys import tarfile + NONESSENTIAL_DIRS = ( 'chrome/common/extensions/docs', 'chrome/test/data', @@ -57,10 +58,12 @@ NONESSENTIAL_DIRS = ( 'webkit/tools/test/reference_build', ) + def GetSourceDirectory(): return os.path.realpath( os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) + # Workaround lack of the exclude parameter in add method in python-2.4. # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. class MyTarFile(tarfile.TarFile): @@ -80,6 +83,7 @@ class MyTarFile(tarfile.TarFile): tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) + def main(argv): parser = optparse.OptionParser() parser.add_option("--remove-nonessential-files", @@ -109,5 +113,6 @@ def main(argv): return 0 + if __name__ == "__main__": sys.exit(main(sys.argv[1:])) diff --git a/tools/export_tarball/export_v8_tarball.py b/tools/export_tarball/export_v8_tarball.py index 3119954..14f8267 100644..100755 --- a/tools/export_tarball/export_v8_tarball.py +++ b/tools/export_tarball/export_v8_tarball.py @@ -1,10 +1,9 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -""" -This tool creates a tarball with V8 sources, but without .svn directories. +"""Creates a tarball with V8 sources, but without .svn directories. This allows easy packaging of V8, synchronized with browser releases. @@ -33,6 +32,7 @@ _V8_PATTERNS = [ _V8_BUILD_NUMBER_PATTERN, _V8_PATCH_LEVEL_PATTERN] + def GetV8Version(v8_directory): """ Returns version number as string based on the string @@ -50,13 +50,16 @@ def GetV8Version(v8_directory): return '.'.join(version_components) + def GetSourceDirectory(): return os.path.realpath( os.path.join(os.path.dirname(__file__), '..', '..', '..', 'src')) + def GetV8Directory(): return os.path.join(GetSourceDirectory(), 'v8') + # Workaround lack of the exclude parameter in add method in python-2.4. # TODO(phajdan.jr): remove the workaround when it's not needed on the bot. class MyTarFile(tarfile.TarFile): @@ -67,6 +70,7 @@ class MyTarFile(tarfile.TarFile): tarfile.TarFile.add(self, name, arcname=arcname, recursive=recursive) + def main(argv): parser = optparse.OptionParser() options, args = parser.parse_args(argv) @@ -99,5 +103,6 @@ def main(argv): return 0 + if __name__ == '__main__': sys.exit(main(sys.argv[1:])) diff --git a/tools/flakiness/find_flakiness.py b/tools/flakiness/find_flakiness.py index 21629e4..21629e4 100644..100755 --- a/tools/flakiness/find_flakiness.py +++ b/tools/flakiness/find_flakiness.py diff --git a/tools/gdb/gdb_chrome.py b/tools/gdb/gdb_chrome.py index 2c25834..7c9284a 100644 --- a/tools/gdb/gdb_chrome.py +++ b/tools/gdb/gdb_chrome.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py b/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py index 9052efa..9860bd7 100755 --- a/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py +++ b/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/generate_stubs/generate_stubs.py b/tools/generate_stubs/generate_stubs.py index 0e0333f..d2313a1 100755 --- a/tools/generate_stubs/generate_stubs.py +++ b/tools/generate_stubs/generate_stubs.py @@ -1,5 +1,4 @@ -#!/usr/bin/python -# +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/generate_stubs/generate_stubs_unittest.py b/tools/generate_stubs/generate_stubs_unittest.py index cfab996..10936f1 100755 --- a/tools/generate_stubs/generate_stubs_unittest.py +++ b/tools/generate_stubs/generate_stubs_unittest.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/git/for-all-touched-files.py b/tools/git/for-all-touched-files.py index d776743..a7e784a 100755 --- a/tools/git/for-all-touched-files.py +++ b/tools/git/for-all-touched-files.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py index 7018db9..7018db9 100644..100755 --- a/tools/gypv8sh.py +++ b/tools/gypv8sh.py diff --git a/tools/heapcheck/chrome_tests.py b/tools/heapcheck/chrome_tests.py index e4cadd2..f01231d 100755 --- a/tools/heapcheck/chrome_tests.py +++ b/tools/heapcheck/chrome_tests.py @@ -1,5 +1,4 @@ -#!/usr/bin/python - +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -417,7 +416,11 @@ class ChromeTests(object): # summary list for long, but will be useful for someone reviewing this bot. return ret -def _main(_): + +def main(): + if not sys.platform.startswith('linux'): + logging.error("Heap checking works only on Linux at the moment.") + return 1 parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> " "[-t <test> ...]") parser.disable_interspersed_args() @@ -457,9 +460,4 @@ def _main(_): if __name__ == "__main__": - if sys.platform.startswith('linux'): - ret = _main(sys.argv) - else: - logging.error("Heap checking works only on Linux at the moment.") - ret = 1 - sys.exit(ret) + sys.exit(main()) diff --git a/tools/heapcheck/heapcheck_test.py b/tools/heapcheck/heapcheck_test.py index 6342589..c80ce0d 100644 --- a/tools/heapcheck/heapcheck_test.py +++ b/tools/heapcheck/heapcheck_test.py @@ -1,10 +1,7 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# heapcheck_test.py - """Wrapper for running the test under heapchecker and analyzing the output.""" import datetime diff --git a/tools/heapcheck/suppressions.py b/tools/heapcheck/suppressions.py index 91c5238..506caa6 100644..100755 --- a/tools/heapcheck/suppressions.py +++ b/tools/heapcheck/suppressions.py @@ -1,10 +1,8 @@ -#!/usr/bin/python -# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# suppressions.py - """Valgrind-style suppressions for heapchecker reports. Suppressions are defined as follows: @@ -167,5 +165,6 @@ def MatchTest(): assert not re_chars.Match(['foobar']) print 'PASS' + if __name__ == '__main__': MatchTest() diff --git a/tools/include_tracer.py b/tools/include_tracer.py index 6c8308f..5d908d1 100755 --- a/tools/include_tracer.py +++ b/tools/include_tracer.py @@ -1,14 +1,16 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # based on an almost identical script by: jyrki@google.com (Jyrki Alakuijala) -# -# This script prints out include dependencies in chrome. Since it ignores -# defines, it gives just a rough estimation of file size. -# -# Usage: -# python tools/include_tracer.py chrome/browser/ui/browser.h + +"""Prints out include dependencies in chrome. + +Since it ignores defines, it gives just a rough estimation of file size. + +Usage: + tools/include_tracer.py chrome/browser/ui/browser.h +""" import os import sys @@ -194,6 +196,11 @@ def Walk(seen, filename, parent, indent): return total_bytes + len("".join(lines)) -bytes = Walk(set(), sys.argv[1], '', 0) -print -print float(bytes) / (1 << 20), "megabytes of chrome source" +def main(): + bytes = Walk(set(), sys.argv[1], '', 0) + print + print float(bytes) / (1 << 20), "megabytes of chrome source" + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/licenses.py b/tools/licenses.py index 211133f2..ea0b8d4 100755 --- a/tools/licenses.py +++ b/tools/licenses.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -236,6 +236,7 @@ def FindThirdPartyDirs(): return third_party_dirs + def ScanThirdPartyDirs(): """Scan a list of directories and report on any problems we find.""" third_party_dirs = FindThirdPartyDirs() @@ -253,6 +254,7 @@ def ScanThirdPartyDirs(): return len(errors) == 0 + def GenerateCredits(): """Generate about:credits, dumping the result to stdout.""" @@ -290,17 +292,22 @@ def GenerateCredits(): print EvaluateTemplate(file_template, {'entries': '\n'.join(entries)}, escape=False) -if __name__ == '__main__': + +def main(): command = 'help' if len(sys.argv) > 1: command = sys.argv[1] if command == 'scan': if not ScanThirdPartyDirs(): - sys.exit(1) + return 1 elif command == 'credits': if not GenerateCredits(): - sys.exit(1) + return 1 else: print __doc__ - sys.exit(1) + return 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/linux/dump-static-initializers.py b/tools/linux/dump-static-initializers.py index 894e58e..b3a70de 100755 --- a/tools/linux/dump-static-initializers.py +++ b/tools/linux/dump-static-initializers.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/net/netlog.py b/tools/net/netlog.py index 610052b..f66d5f0 100755 --- a/tools/net/netlog.py +++ b/tools/net/netlog.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -172,6 +172,4 @@ def main(_): if '__main__' == __name__: - ret = main(sys.argv) - sys.exit(ret) - + sys.exit(main(sys.argv)) diff --git a/tools/nocompile_driver.py b/tools/nocompile_driver.py index 2c5b354..ca71127 100755 --- a/tools/nocompile_driver.py +++ b/tools/nocompile_driver.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/perf_expectations/PRESUBMIT.py b/tools/perf_expectations/PRESUBMIT.py index 5897b3a..1c1c713 100644 --- a/tools/perf_expectations/PRESUBMIT.py +++ b/tools/perf_expectations/PRESUBMIT.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/playback_benchmark/playback_driver.py b/tools/playback_benchmark/playback_driver.py index cf8d2a0..ef6c7b4 100644 --- a/tools/playback_benchmark/playback_driver.py +++ b/tools/playback_benchmark/playback_driver.py @@ -1,7 +1,6 @@ -#!/usr/bin/env python -# -# Copyright 2010 Google Inc. All Rights Reserved. - +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Playback driver.""" import cgi diff --git a/tools/playback_benchmark/proxy_handler.py b/tools/playback_benchmark/proxy_handler.py index 05da078..b45f960 100644 --- a/tools/playback_benchmark/proxy_handler.py +++ b/tools/playback_benchmark/proxy_handler.py @@ -1,7 +1,6 @@ -#!/usr/bin/env python -# -# Copyright 2010 Google Inc. All Rights Reserved. - +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """HTTP proxy request handler with SSL support. RequestHandler: Utility class for parsing HTTP requests. diff --git a/tools/playback_benchmark/run.py b/tools/playback_benchmark/run.py index 231ee84..04ed12b 100644..100755 --- a/tools/playback_benchmark/run.py +++ b/tools/playback_benchmark/run.py @@ -1,8 +1,9 @@ #!/usr/bin/env python -# -# Copyright 2010 Google Inc. All Rights Reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. -"""Script for test playback. +"""Tests playback. Prerequisites: 1. OpenSSL library - http://www.openssl.org/ @@ -13,6 +14,7 @@ python run.py -t <test_dir> """ from optparse import OptionParser +import sys import playback_driver import proxy_handler @@ -26,7 +28,7 @@ def Run(options): httpd.serve_forever() -if __name__ == '__main__': +def main(): parser = OptionParser() parser.add_option("-t", "--test-dir", dest="test_dir", help="directory containing recorded test data") @@ -37,3 +39,6 @@ if __name__ == '__main__': Run(options) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/pragmaonce/pragmaonce.py b/tools/pragmaonce/pragmaonce.py index 15224c4..22f22a8 100644..100755 --- a/tools/pragmaonce/pragmaonce.py +++ b/tools/pragmaonce/pragmaonce.py @@ -1,13 +1,17 @@ -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +"""Tool to add "#pragma once" lines to files that don't have it yet. + +Usage: + find chrome -name '*.h' -exec tools/pragmaonce/pragmaonce.py {} \; +""" + import re import sys -# A tool to add "#pragma once" lines to files that don't have it yet. -# Intended usage: -# find chrome -name '*.h' -exec python tools/pragmaonce/pragmaonce.py {} \; # Some files have absurdly long comments at the top NUM_LINES_TO_SCAN_FOR_GUARD = 250 @@ -34,16 +38,17 @@ def main(filename): if index < len(lines) and re.match(r'#pragma once', lines[index]): # The pragma is already there. - return + return 0 lines.insert(index, "#pragma once\n") f = open(filename, 'w') f.write(''.join(lines)) f.close() + return 0 if __name__ == '__main__': if len(sys.argv) != 2: print >>sys.stderr, "Usage: %s inputfile" % sys.argv[0] sys.exit(1) - main(sys.argv[1]) + sys.exit(main(sys.argv[1])) diff --git a/tools/python/google/gethash_timer.py b/tools/python/google/gethash_timer.py index e59690b..9c4bd46 100644..100755 --- a/tools/python/google/gethash_timer.py +++ b/tools/python/google/gethash_timer.py @@ -1,24 +1,25 @@ -#!/usr/bin/python -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Issue a series of GetHash requests to the SafeBrowsing servers and measure the -# response times. -# -# Usage: -# -# $ ./gethash_timer.py --period=600 --samples=20 --output=resp.csv -# -# --period (or -p): The amount of time (in seconds) to wait between GetHash -# requests. Using a value of more than 300 (5 minutes) to -# include the effect of DNS. -# -# --samples (or -s): The number of requests to issue. If this parameter is not -# specified, the test will run indefinitely. -# -# --output (or -o): The path to a file where the output will be written in -# CSV format: sample_number,response_code,elapsed_time_ms +"""Issue a series of GetHash requests to the SafeBrowsing servers and measure +the response times. + +Usage: + + $ ./gethash_timer.py --period=600 --samples=20 --output=resp.csv + + --period (or -p): The amount of time (in seconds) to wait between GetHash + requests. Using a value of more than 300 (5 minutes) to + include the effect of DNS. + + --samples (or -s): The number of requests to issue. If this parameter is not + specified, the test will run indefinitely. + + --output (or -o): The path to a file where the output will be written in + CSV format: sample_number,response_code,elapsed_time_ms +""" import getopt import httplib @@ -26,7 +27,8 @@ import sys import time _GETHASH_HOST = 'safebrowsing.clients.google.com' -_GETHASH_REQUEST = '/safebrowsing/gethash?client=googleclient&appver=1.0&pver=2.1' +_GETHASH_REQUEST = ( + '/safebrowsing/gethash?client=googleclient&appver=1.0&pver=2.1') # Global logging file handle. g_file_handle = None @@ -115,7 +117,7 @@ def SetupOutputFile(file_name): g_file_handle = open(file_name, 'w') -if __name__ == '__main__': +def main(): period = 10 samples = None @@ -131,7 +133,7 @@ if __name__ == '__main__': file_name = value else: print 'Bad option: %s' % option - sys.exit(1) + return 1 try: print 'Starting Timed GetHash ----------' SetupOutputFile(file_name) @@ -142,3 +144,6 @@ if __name__ == '__main__': print 'Timed GetHash complete ----------' g_file_handle.close() + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/python/google/httpd_utils.py b/tools/python/google/httpd_utils.py index e7cfe09..4a03ffc 100644..100755 --- a/tools/python/google/httpd_utils.py +++ b/tools/python/google/httpd_utils.py @@ -1,5 +1,5 @@ -#!/bin/env python -# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -169,7 +169,8 @@ class ApacheHttpd(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE) -if '__main__' == __name__: + +def main(): # Provide some command line params for starting/stopping the http server # manually. option_parser = optparse.OptionParser() @@ -183,7 +184,7 @@ if '__main__' == __name__: if not options.server: print ("Usage: %s -k {start|stop} [-r document_root] [--apache2]" % sys.argv[0]) - sys.exit(0) + return 1 document_root = None if options.root: @@ -194,3 +195,6 @@ if '__main__' == __name__: else: StopServers(apache2=options.apache2) + +if '__main__' == __name__: + sys.exit(main()) diff --git a/tools/python/google/logging_utils.py b/tools/python/google/logging_utils.py index 5fd95d3..ef2d674 100644 --- a/tools/python/google/logging_utils.py +++ b/tools/python/google/logging_utils.py @@ -1,10 +1,7 @@ -#!/bin/env python -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# logging_utils.py - ''' Utility functions and objects for logging. ''' @@ -83,4 +80,3 @@ def config_root(level=logging.INFO, threshold=logging.WARNING, format=FORMAT, handler.setLevel(level) handler.setFormatter(formatter) root.addHandler(handler) - diff --git a/tools/python/google/path_utils.py b/tools/python/google/path_utils.py index 6f94a84..6ab4312 100644 --- a/tools/python/google/path_utils.py +++ b/tools/python/google/path_utils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -82,4 +82,3 @@ def MaybeMakeDirectory(*path): # errno.EEXIST is "File exists". If we see another error, re-raise. if e.errno != errno.EEXIST: raise - diff --git a/tools/python/google/platform_utils.py b/tools/python/google/platform_utils.py index 1489fa2..50bfb70 100644 --- a/tools/python/google/platform_utils.py +++ b/tools/python/google/platform_utils.py @@ -1,4 +1,3 @@ -#!/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/python/google/platform_utils_linux.py b/tools/python/google/platform_utils_linux.py index db4eb50..237565e3 100644 --- a/tools/python/google/platform_utils_linux.py +++ b/tools/python/google/platform_utils_linux.py @@ -1,5 +1,4 @@ -#!/usr/bin/python -# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/python/google/platform_utils_mac.py b/tools/python/google/platform_utils_mac.py index c0a13e8..2e56a3d 100644 --- a/tools/python/google/platform_utils_mac.py +++ b/tools/python/google/platform_utils_mac.py @@ -1,5 +1,4 @@ -#!/usr/bin/python -# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/python/google/platform_utils_win.py b/tools/python/google/platform_utils_win.py index eef2b50..65db96c 100644 --- a/tools/python/google/platform_utils_win.py +++ b/tools/python/google/platform_utils_win.py @@ -1,4 +1,4 @@ -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Platform-specific utility methods shared by several scripts.""" @@ -192,4 +192,3 @@ def GetCygwinPath(path): return '/cygdrive/%s/' % matchobj.group(1).lower() path = drive_regexp.sub(LowerDrive, path) return path.replace('\\', '/') - diff --git a/tools/site_compare/command_line.py b/tools/site_compare/command_line.py index 2c87fb9..de93d18 100644..100755 --- a/tools/site_compare/command_line.py +++ b/tools/site_compare/command_line.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -660,7 +660,8 @@ def DoHelpCommand(command): command.cmdline.Exit() -if __name__ == "__main__": + +def main(): # If we're invoked rather than imported, run some tests cmdline = CommandLine() @@ -797,3 +798,5 @@ if __name__ == "__main__": cmdline.ParseCommandLine(["help", "test"]) +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/commands/__init__.py b/tools/site_compare/commands/__init__.py index a699508..e69de29 100644..100755 --- a/tools/site_compare/commands/__init__.py +++ b/tools/site_compare/commands/__init__.py @@ -1,2 +0,0 @@ -#!/usr/bin/Python2.4 - diff --git a/tools/site_compare/commands/compare2.py b/tools/site_compare/commands/compare2.py index 045141b..7e15559 100644 --- a/tools/site_compare/commands/compare2.py +++ b/tools/site_compare/commands/compare2.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -169,4 +168,3 @@ def ExecuteCompare2(command): scrape_info_list[0].result, scrape_info_list[1].result, result)) - diff --git a/tools/site_compare/commands/maskmaker.py b/tools/site_compare/commands/maskmaker.py index 73b732c..8aeefcb 100644 --- a/tools/site_compare/commands/maskmaker.py +++ b/tools/site_compare/commands/maskmaker.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -271,4 +270,3 @@ def ExecuteMaskmaker(command): "reaching the giveup threshhold" % len(url_list)) for url in url_list: print " ", url.url - diff --git a/tools/site_compare/commands/measure.py b/tools/site_compare/commands/measure.py index 086fcbe..2bd71f5 100644 --- a/tools/site_compare/commands/measure.py +++ b/tools/site_compare/commands/measure.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -51,4 +50,3 @@ def ExecuteMeasure(command): # Close the log file and return. We're done. log_file.close() - diff --git a/tools/site_compare/commands/scrape.py b/tools/site_compare/commands/scrape.py index 1c47cab..8fee5a3 100644 --- a/tools/site_compare/commands/scrape.py +++ b/tools/site_compare/commands/scrape.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -58,4 +57,3 @@ def ExecuteScrape(command): # Close the log file and return. We're done. if log_file: log_file.close() - diff --git a/tools/site_compare/commands/timeload.py b/tools/site_compare/commands/timeload.py index ca5b0db..f34ee1d 100644 --- a/tools/site_compare/commands/timeload.py +++ b/tools/site_compare/commands/timeload.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -39,7 +38,8 @@ def CreateCommand(cmdline): ["-bp", "--browserpaths"], "List of paths to browsers. Comma-separated", type="string", required=False) cmd.AddArgument( - ["-bv", "--browserversions"], "List of versions of browsers. Comma-separated", + ["-bv", "--browserversions"], + "List of versions of browsers. Comma-separated", type="string", required=False) cmd.AddArgument( ["-u", "--url"], "URL to time") @@ -142,5 +142,3 @@ def ExecuteTimeLoad(command): log_file.write(url) for b in xrange(num_browsers): log_file.write(",%r" % results[url][b]) - - diff --git a/tools/site_compare/drivers/__init__.py b/tools/site_compare/drivers/__init__.py index fa9f1c2..9b46261 100644 --- a/tools/site_compare/drivers/__init__.py +++ b/tools/site_compare/drivers/__init__.py @@ -1,11 +1,9 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Imports a set of drivers appropriate to the current OS.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' - import sys platform_dir = sys.platform diff --git a/tools/site_compare/drivers/win32/keyboard.py b/tools/site_compare/drivers/win32/keyboard.py index 246e14c..e3410e1 100644..100755 --- a/tools/site_compare/drivers/win32/keyboard.py +++ b/tools/site_compare/drivers/win32/keyboard.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -166,7 +166,8 @@ def TypeString(string_to_type, if ctrl_held: PressKey(False, win32con.VK_CONTROL) if alt_held: PressKey(False, win32con.VK_MENU) -if __name__ == "__main__": + +def main(): # We're being invoked rather than imported. Let's do some tests # Press command-R to bring up the Run dialog @@ -196,3 +197,5 @@ if __name__ == "__main__": time_between_keystrokes=0.05) +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/drivers/win32/mouse.py b/tools/site_compare/drivers/win32/mouse.py index bd16272..0096af9 100644..100755 --- a/tools/site_compare/drivers/win32/mouse.py +++ b/tools/site_compare/drivers/win32/mouse.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -189,7 +189,8 @@ def DoubleClickInWindow( time.sleep(time_between_clicks) ClickInWindow(hwnd, offset, button, click_time) -if __name__ == "__main__": + +def main(): # We're being invoked rather than imported. Let's do some tests screen_size = win32gui.GetClientRect(win32gui.GetDesktopWindow()) @@ -216,3 +217,6 @@ if __name__ == "__main__": MoveToLocation((0, 0), 3) ClickButton() + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/drivers/win32/windowing.py b/tools/site_compare/drivers/win32/windowing.py index fe77c56..47d63f0 100644..100755 --- a/tools/site_compare/drivers/win32/windowing.py +++ b/tools/site_compare/drivers/win32/windowing.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -338,7 +338,8 @@ def PreparePath(path): except OSError, e: if e[0] != 17: raise e # error 17: path already exists -if __name__ == "__main__": + +def main(): PreparePath(r"c:\sitecompare\scrapes\ie7") # We're being invoked rather than imported. Let's do some tests @@ -360,3 +361,6 @@ if __name__ == "__main__": EndProcess(proc, 0) + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/operators/__init__.py b/tools/site_compare/operators/__init__.py index f60e8e8..5d6ffd7 100644 --- a/tools/site_compare/operators/__init__.py +++ b/tools/site_compare/operators/__init__.py @@ -1,11 +1,9 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Selects the appropriate operator.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' - def GetOperator(operator): """Given an operator by name, returns its module. @@ -23,4 +21,3 @@ def GetOperator(operator): module = __import__(operator, globals(), locals(), ['']) return module - diff --git a/tools/site_compare/operators/equals.py b/tools/site_compare/operators/equals.py index 4054fa6..311f530 100644 --- a/tools/site_compare/operators/equals.py +++ b/tools/site_compare/operators/equals.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -36,6 +35,3 @@ def Compare(file1, file2, **kwargs): return ("The images differ", diff) else: return None - - - diff --git a/tools/site_compare/operators/equals_with_mask.py b/tools/site_compare/operators/equals_with_mask.py index d6abd53..e42f7e1 100644 --- a/tools/site_compare/operators/equals_with_mask.py +++ b/tools/site_compare/operators/equals_with_mask.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -56,6 +55,3 @@ def Compare(file1, file2, **kwargs): return ("The images differ", diff) else: return None - - - diff --git a/tools/site_compare/scrapers/__init__.py b/tools/site_compare/scrapers/__init__.py index cb82b2b..5f6d778 100644..100755 --- a/tools/site_compare/scrapers/__init__.py +++ b/tools/site_compare/scrapers/__init__.py @@ -1,11 +1,10 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Selects the appropriate scraper for a given browser and version.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' - import types # TODO(jhaas): unify all optional scraper parameters into kwargs @@ -28,7 +27,7 @@ def GetScraper(browser): return module + # if invoked rather than imported, do some tests if __name__ == "__main__": print GetScraper("IE") - diff --git a/tools/site_compare/scrapers/chrome/__init__.py b/tools/site_compare/scrapers/chrome/__init__.py index 6342525..587a50d 100644..100755 --- a/tools/site_compare/scrapers/chrome/__init__.py +++ b/tools/site_compare/scrapers/chrome/__init__.py @@ -1,10 +1,10 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Selects the appropriate scraper for Chrome.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' def GetScraper(version): """Returns the scraper module for the given version. @@ -30,9 +30,7 @@ def GetScraper(version): return __import__(scraper_version, globals(), locals(), ['']) + # if invoked rather than imported, test if __name__ == "__main__": - version = "0.1.101.0" - - print GetScraper(version).version - + print GetScraper("0.1.101.0").version diff --git a/tools/site_compare/scrapers/chrome/chrome011010.py b/tools/site_compare/scrapers/chrome/chrome011010.py index b4f816f..6f0dfb4 100644 --- a/tools/site_compare/scrapers/chrome/chrome011010.py +++ b/tools/site_compare/scrapers/chrome/chrome011010.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -41,4 +40,3 @@ def Time(urls, size, timeout, **kwargs): chromebase.GetChromeRenderPane = GetChromeRenderPane return chromebase.Time(urls, size, timeout, kwargs) - diff --git a/tools/site_compare/scrapers/chrome/chrome01970.py b/tools/site_compare/scrapers/chrome/chrome01970.py index 54bc670..2f237fa 100644 --- a/tools/site_compare/scrapers/chrome/chrome01970.py +++ b/tools/site_compare/scrapers/chrome/chrome01970.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -41,4 +40,3 @@ def Time(urls, size, timeout, **kwargs): chromebase.GetChromeRenderPane = GetChromeRenderPane return chromebase.Time(urls, size, timeout, kwargs) - diff --git a/tools/site_compare/scrapers/chrome/chromebase.py b/tools/site_compare/scrapers/chrome/chromebase.py index aba17c1..2b8f177 100644..100755 --- a/tools/site_compare/scrapers/chrome/chromebase.py +++ b/tools/site_compare/scrapers/chrome/chromebase.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -12,10 +12,12 @@ from drivers import keyboard from drivers import mouse from drivers import windowing + # TODO: this has moved, use some logic to find it. For now, # expects a subst k:. DEFAULT_PATH = r"k:\chrome.exe" + def InvokeBrowser(path): """Invoke the Chrome browser. @@ -179,7 +181,7 @@ def Time(urls, size, timeout, kwargs): return ret -if __name__ == "__main__": +def main(): # We're being invoked rather than imported, so run some tests path = r"c:\sitecompare\scrapes\chrome\0.1.97.0" windowing.PreparePath(path) @@ -190,4 +192,8 @@ if __name__ == "__main__": "http://www.google.com", "http://www.sun.com"], path, (1024, 768), (0, 0)) + return 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/scrapers/firefox/__init__.py b/tools/site_compare/scrapers/firefox/__init__.py index 7eb9291..34c0699 100644..100755 --- a/tools/site_compare/scrapers/firefox/__init__.py +++ b/tools/site_compare/scrapers/firefox/__init__.py @@ -1,11 +1,10 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Selects the appropriate scraper for Firefox.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' - def GetScraper(version): """Returns the scraper module for the given version. @@ -23,9 +22,7 @@ def GetScraper(version): # We only have one version of the Firefox scraper for now return __import__("firefox2", globals(), locals(), ['']) + # if invoked rather than imported, test if __name__ == "__main__": - version = "2.0.0.6" - print GetScraper("2.0.0.6").version - diff --git a/tools/site_compare/scrapers/firefox/firefox2.py b/tools/site_compare/scrapers/firefox/firefox2.py index fa0d620..2181f58 100644..100755 --- a/tools/site_compare/scrapers/firefox/firefox2.py +++ b/tools/site_compare/scrapers/firefox/firefox2.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -232,7 +232,7 @@ def Time(urls, size, timeout, **kwargs): return ret -if __name__ == "__main__": +def main(): # We're being invoked rather than imported, so run some tests path = r"c:\sitecompare\scrapes\Firefox\2.0.0.6" windowing.PreparePath(path) @@ -242,4 +242,8 @@ if __name__ == "__main__": ["http://www.microsoft.com", "http://www.google.com", "http://www.sun.com"], path, (1024, 768), (0, 0)) + return 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/scrapers/ie/__init__.py b/tools/site_compare/scrapers/ie/__init__.py index 8fb95db..b4dab09 100644..100755 --- a/tools/site_compare/scrapers/ie/__init__.py +++ b/tools/site_compare/scrapers/ie/__init__.py @@ -1,11 +1,10 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. """Selects the appropriate scraper for Internet Explorer.""" -__author__ = 'jhaas@google.com (Jonathan Haas)' - def GetScraper(version): """Returns the scraper module for the given version. @@ -23,9 +22,7 @@ def GetScraper(version): # We only have one version of the IE scraper for now return __import__("ie7", globals(), locals(), ['']) + # if invoked rather than imported, test if __name__ == "__main__": - version = "7.0.5370.1" - - print GetScraper(version).version - + print GetScraper("7.0.5370.1").version diff --git a/tools/site_compare/scrapers/ie/ie7.py b/tools/site_compare/scrapers/ie/ie7.py index da26d9b..dcb83ca 100644..100755 --- a/tools/site_compare/scrapers/ie/ie7.py +++ b/tools/site_compare/scrapers/ie/ie7.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -192,7 +192,7 @@ def Time(urls, size, timeout, **kwargs): return ret -if __name__ == "__main__": +def main(): # We're being invoked rather than imported, so run some tests path = r"c:\sitecompare\scrapes\ie7\7.0.5380.11" windowing.PreparePath(path) @@ -203,4 +203,8 @@ if __name__ == "__main__": "http://www.google.com", "http://www.sun.com"], path, (1024, 768), (0, 0)) + return 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/site_compare/site_compare.py b/tools/site_compare/site_compare.py index 15359fa..db9216f 100644..100755 --- a/tools/site_compare/site_compare.py +++ b/tools/site_compare/site_compare.py @@ -1,5 +1,5 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -169,9 +169,8 @@ def main(): commands.scrape.CreateCommand(cmdline) cmdline.ParseCommandLine() - + return 0 if __name__ == "__main__": - main() - + sys.exit(main()) diff --git a/tools/site_compare/utils/__init__.py b/tools/site_compare/utils/__init__.py index 69f2237..e69de29 100644..100755 --- a/tools/site_compare/utils/__init__.py +++ b/tools/site_compare/utils/__init__.py @@ -1,7 +0,0 @@ -#!/usr/bin/python2.4 -# -# Copyright 2007 Google Inc. All Rights Reserved. - -"""Utilities for site_compare.""" - -__author__ = 'jhaas@google.com (Jonathan Haas)' diff --git a/tools/site_compare/utils/browser_iterate.py b/tools/site_compare/utils/browser_iterate.py index 6ea4e5f..596b475 100644 --- a/tools/site_compare/utils/browser_iterate.py +++ b/tools/site_compare/utils/browser_iterate.py @@ -1,5 +1,4 @@ -#!/usr/bin/python2.4 -# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -198,4 +197,3 @@ def Iterate(command, iteration_func): # We're done DetachFromBrowser() - diff --git a/tools/sort-headers.py b/tools/sort-headers.py index fb7dd25..168dfce 100755 --- a/tools/sort-headers.py +++ b/tools/sort-headers.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -15,6 +15,7 @@ import sys import termios import tty + def YesNo(prompt): """Prompts with a yes/no question, returns True if yes.""" print prompt, @@ -110,11 +111,11 @@ def main(): if len(filenames) < 1: parser.print_help() - sys.exit(1) + return 1 for filename in filenames: DiffAndConfirm(filename, opts.should_confirm) if __name__ == '__main__': - main() + sys.exit(main()) diff --git a/tools/swig/swig.py b/tools/swig/swig.py index c363c27..ddfaae4 100755 --- a/tools/swig/swig.py +++ b/tools/swig/swig.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -39,9 +39,8 @@ def main(): args = [swig_bin, platform_flags[sys.platform]] + sys.argv[1:] args = [x.replace('/', os.sep) for x in args] print "Executing", args - sys.exit(subprocess.call(args)) + return subprocess.call(args) if __name__ == "__main__": - main() - + sys.exit(main()) diff --git a/tools/symsrc/img_fingerprint.py b/tools/symsrc/img_fingerprint.py index 5b3c414..c4b6395 100644..100755 --- a/tools/symsrc/img_fingerprint.py +++ b/tools/symsrc/img_fingerprint.py @@ -1,28 +1,34 @@ #!/usr/bin/env python - -# Copyright (c) 2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""This will retrieve an image's "fingerprint". This is used when retrieving -the image from the symbol server. The .dll (or cab compressed .dl_) or .exe -is expected at a path like: - foo.dll/FINGERPRINT/foo.dll""" +"""Retrieves an image's "fingerprint". + +This is used when retrieving the image from the symbol server. The .dll (or cab +compressed .dl_) or .exe is expected at a path like: + foo.dll/FINGERPRINT/foo.dll +""" import sys import pefile + def GetImgFingerprint(filename): """Returns the fingerprint for an image file""" - pe = pefile.PE(filename) return "%08X%06x" % ( pe.FILE_HEADER.TimeDateStamp, pe.OPTIONAL_HEADER.SizeOfImage) -if __name__ == '__main__': +def main(): if len(sys.argv) != 2: print "usage: file.dll" - sys.exit(1) + return 1 print GetImgFingerprint(sys.argv[1]) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/symsrc/pdb_fingerprint_from_img.py b/tools/symsrc/pdb_fingerprint_from_img.py index c7dae50..e994475 100644..100755 --- a/tools/symsrc/pdb_fingerprint_from_img.py +++ b/tools/symsrc/pdb_fingerprint_from_img.py @@ -1,6 +1,5 @@ #!/usr/bin/env python - -# Copyright (c) 2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -16,12 +15,14 @@ DLL's reference to the PDB, and use that to retrieve the information.""" import sys import pefile + __CV_INFO_PDB70_format__ = ('CV_INFO_PDB70', ('4s,CvSignature', '16s,Signature', 'L,Age')) __GUID_format__ = ('GUID', ('L,Data1', 'H,Data2', 'H,Data3', '8s,Data4')) + def GetPDBInfoFromImg(filename): """Returns the PDB fingerprint and the pdb filename given an image file""" @@ -48,10 +49,16 @@ def GetPDBInfoFromImg(filename): break -if __name__ == '__main__': + +def main(): if len(sys.argv) != 2: print "usage: file.dll" - sys.exit(1) + return 1 + + (fingerprint, filename) = GetPDBInfoFromImg(sys.argv[1]) + print "%s %s" % (fingerprint, filename) + return 0 - (fingerprint, file) = GetPDBInfoFromImg(sys.argv[1]) - print "%s %s" % (fingerprint, file) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/symsrc/source_index.py b/tools/symsrc/source_index.py index 8160872..e2a58e0 100644..100755 --- a/tools/symsrc/source_index.py +++ b/tools/symsrc/source_index.py @@ -1,6 +1,5 @@ #!/usr/bin/env python - -# Copyright (c) 2008 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -45,6 +44,7 @@ REPO_MAP = { "http://google-url.googlecode.com/svn": None, } + def FindFile(filename): """Return the full windows path to a file in the same dir as this code.""" thisdir = os.path.dirname(os.path.join(os.path.curdir, __file__)) @@ -61,6 +61,7 @@ def ExtractSourceFiles(pdb_filename): raise "srctool failed: " + filelist return [x for x in filelist.split('\r\n') if len(x) != 0] + def ReadSourceStream(pdb_filename): """Read the contents of the source information stream from a PDB.""" srctool = subprocess.Popen([FindFile('pdbstr.exe'), @@ -74,6 +75,7 @@ def ReadSourceStream(pdb_filename): raise "pdbstr failed: " + data return data + def WriteSourceStream(pdb_filename, data): """Write the contents of the source information stream to a PDB.""" # Write out the data to a temporary filename that we can pass to pdbstr. @@ -95,6 +97,7 @@ def WriteSourceStream(pdb_filename, data): os.unlink(fname) + # TODO for performance, we should probably work in directories instead of # files. I'm scared of DEPS and generated files, so for now we query each # individual file, and don't make assumptions that all files in the same @@ -119,6 +122,7 @@ def ExtractSvnInfo(local_filename): return [root, path, rev] + def UpdatePDB(pdb_filename, verbose=False): """Update a pdb file with source information.""" dir_blacklist = { } @@ -190,13 +194,19 @@ def UpdatePDB(pdb_filename, verbose=False): WriteSourceStream(pdb_filename, '\r\n'.join(lines)) -if __name__ == '__main__': + +def main(): if len(sys.argv) < 2 or len(sys.argv) > 3: print "usage: file.pdb [-v]" - sys.exit(1) + return 1 verbose = False if len(sys.argv) == 3: verbose = (sys.argv[2] == '-v') UpdatePDB(sys.argv[1], verbose=verbose) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/sync-webkit-git.py b/tools/sync-webkit-git.py index 4a99886..4b98d9c 100755 --- a/tools/sync-webkit-git.py +++ b/tools/sync-webkit-git.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import re import subprocess import sys + def RunGit(command): """Run a git subcommand, returning its output.""" # On Windows, use shell=True to get PATH interpretation. @@ -30,11 +31,13 @@ def RunGit(command): logging.info('Returned "%s"' % out) return out + def GetOverrideShortBranchName(): """Returns the user-configured override branch name, if any.""" override_config_name = 'chromium.sync-branch' return RunGit(['config', '--get', override_config_name]) + def GetGClientBranchName(): """Returns the name of the magic branch that lets us know that DEPS is managing the update cycle.""" @@ -55,6 +58,7 @@ def GetGClientBranchName(): print "Please fix your git config value '%s'." % overide_config_name sys.exit(1) + def GetWebKitRev(): """Extract the 'webkit_revision' variable out of DEPS.""" locals = {'Var': lambda _: locals["vars"][_], @@ -62,6 +66,7 @@ def GetWebKitRev(): execfile('DEPS', {}, locals) return locals['vars']['webkit_revision'] + def FindSVNRev(target_rev): """Map an SVN revision to a git hash. Like 'git svn find-rev' but without the git-svn bits.""" @@ -106,6 +111,7 @@ def FindSVNRev(target_rev): print "Something has likely gone horribly wrong." return None + def GetRemote(): branch = GetOverrideShortBranchName() if not branch: @@ -116,6 +122,7 @@ def GetRemote(): return remote return 'origin' + def UpdateGClientBranch(webkit_rev, magic_gclient_branch): """Update the magic gclient branch to point at |webkit_rev|. @@ -139,6 +146,7 @@ def UpdateGClientBranch(webkit_rev, magic_gclient_branch): shell=(os.name == 'nt')) return True + def UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch): """Reset the current gclient branch if that's what we have checked out.""" branch = RunGit(['symbolic-ref', '-q', 'HEAD']) @@ -154,6 +162,7 @@ def UpdateCurrentCheckoutIfAppropriate(magic_gclient_branch): print "Resetting tree state to new revision." subprocess.check_call(['git', 'reset', '--hard'], shell=(os.name == 'nt')) + def main(): parser = optparse.OptionParser() parser.add_option('-v', '--verbose', action='store_true') @@ -182,5 +191,6 @@ def main(): print "Already on correct revision." return 0 + if __name__ == '__main__': sys.exit(main()) diff --git a/tools/traceline/traceline/scripts/__init__.py b/tools/traceline/traceline/scripts/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/traceline/traceline/scripts/__init__.py diff --git a/tools/traceline/traceline/scripts/alloc.py b/tools/traceline/traceline/scripts/alloc.py index d89447a..ee4af22 100755 --- a/tools/traceline/traceline/scripts/alloc.py +++ b/tools/traceline/traceline/scripts/alloc.py @@ -1,12 +1,12 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import sys -execfile(os.path.join( - os.path.dirname(os.path.join(os.path.curdir, __file__)), - 'syscalls.py')) +from syscalls import syscalls + def parseEvents(z): calls = { } @@ -18,4 +18,10 @@ def parseEvents(z): print '%f - %f - %x' % ( delta, ms, tid) -execfile(sys.argv[1]) + +def main(): + execfile(sys.argv[1]) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/traceline/traceline/scripts/crit_sec.py b/tools/traceline/traceline/scripts/crit_sec.py index f43f50d..ee710bd 100755 --- a/tools/traceline/traceline/scripts/crit_sec.py +++ b/tools/traceline/traceline/scripts/crit_sec.py @@ -1,13 +1,13 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import sys import os -execfile(os.path.join( - os.path.dirname(os.path.join(os.path.curdir, __file__)), - 'syscalls.py')) +from syscalls import syscalls + def parseEvents(z): crits = { } @@ -48,4 +48,10 @@ def parseEvents(z): #raise repr(tid_stack) pass -execfile(sys.argv[1]) + +def main(): + execfile(sys.argv[1]) + + +if __name__ == '__main__': + main() diff --git a/tools/traceline/traceline/scripts/filter_short.py b/tools/traceline/traceline/scripts/filter_short.py index 9d8466e..1b73bf9 100755 --- a/tools/traceline/traceline/scripts/filter_short.py +++ b/tools/traceline/traceline/scripts/filter_short.py @@ -1,14 +1,19 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# This script takes an input JSON, and filters out all system call events that -# took less than 0.2ms. This helps trim down the JSON data to only the most -# interesting / time critical events. +"""Takes an input JSON, and filters out all system call events that +took less than 0.2ms. + +This helps trim down the JSON data to only the most interesting / time critical +events. +""" import sys import re + def parseEvents(z): print 'parseEvents([' for e in z: @@ -20,4 +25,10 @@ def parseEvents(z): print '%s,' % re.sub('([0-9])L\\b', '\\1', str(e)) print '])' -execfile(sys.argv[1]) + +def main(): + execfile(sys.argv[1]) + + +if __name__ == '__main__': + main() diff --git a/tools/traceline/traceline/scripts/filter_split.sh b/tools/traceline/traceline/scripts/filter_split.sh index 19a2891..876488e 100644..100755 --- a/tools/traceline/traceline/scripts/filter_split.sh +++ b/tools/traceline/traceline/scripts/filter_split.sh @@ -1,6 +1,5 @@ #!/bin/bash - -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -10,6 +9,6 @@ echo "parseEvents([" > totalsplit for f in split.*; do - python scripts/filter_short.py "$f" | tail -n +2 | head -n -1 >> totalsplit + ./scripts/filter_short.py "$f" | tail -n +2 | head -n -1 >> totalsplit done echo "]);" >> totalsplit diff --git a/tools/traceline/traceline/scripts/scstats.py b/tools/traceline/traceline/scripts/scstats.py index 21f28d8..e2f28dc 100755 --- a/tools/traceline/traceline/scripts/scstats.py +++ b/tools/traceline/traceline/scripts/scstats.py @@ -1,12 +1,12 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import sys -execfile(os.path.join( - os.path.dirname(os.path.join(os.path.curdir, __file__)), - 'syscalls.py')) +from syscalls import syscalls + def parseEvents(z): calls = { } @@ -23,4 +23,10 @@ def parseEvents(z): #for syscall, delta in calls.items(): # print '%f - %d %s' % (delta, syscall, syscalls.get(syscall, 'unknown')) -execfile(sys.argv[1]) + +def main(): + execfile(sys.argv[1]) + + +if __name__ == '__main__': + main() diff --git a/tools/traceline/traceline/scripts/split.py b/tools/traceline/traceline/scripts/split.py index 9e9f7dd..3b7bf90 100755 --- a/tools/traceline/traceline/scripts/split.py +++ b/tools/traceline/traceline/scripts/split.py @@ -1,25 +1,31 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Splits a single json file (read from stdin) into separate files of 40k -# records, named split.X. +"""Splits a single json file (read from stdin) into separate files of 40k +records, named split.X. +""" import sys -filecount = 0; -count = 0; -f = open('split.0', 'wb'); +def main(): + filecount = 0 + count = 0 + f = open('split.0', 'wb') + for l in sys.stdin: + if l == "},\r\n": + count += 1 + if count == 40000: + f.write("}]);\r\n") + count = 0 + filecount += 1 + f = open('split.%d' % filecount, 'wb') + f.write("parseEvents([\r\n") + continue + f.write(l) -for l in sys.stdin: - if l == "},\r\n": - count += 1 - if count == 40000: - f.write("}]);\r\n") - count = 0; - filecount += 1 - f = open('split.%d' % filecount, 'wb'); - f.write("parseEvents([\r\n") - continue - f.write(l) + +if __name__ == '__main__': + main() diff --git a/tools/traceline/traceline/scripts/syscalls.py b/tools/traceline/traceline/scripts/syscalls.py index 6a25c77..6800b45 100755 --- a/tools/traceline/traceline/scripts/syscalls.py +++ b/tools/traceline/traceline/scripts/syscalls.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/unused-symbols-report.py b/tools/unused-symbols-report.py index 12eb053..900bf16 100755 --- a/tools/unused-symbols-report.py +++ b/tools/unused-symbols-report.py @@ -1,9 +1,9 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""Print a report of symbols stripped by the linker due to being unused. +"""Prints a report of symbols stripped by the linker due to being unused. To use, build with these linker flags: -Wl,--gc-sections @@ -166,5 +166,6 @@ def main(): only_paths=opts.only_paths) Output(iter) + if __name__ == '__main__': main() diff --git a/tools/valgrind/asan/asan_test.py b/tools/valgrind/asan/asan_test.py index dcdff8c..f0a4d16 100644 --- a/tools/valgrind/asan/asan_test.py +++ b/tools/valgrind/asan/asan_test.py @@ -1,10 +1,7 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# asan_test.py - """Wrapper for running the test under AddressSanitizer.""" import datetime diff --git a/tools/valgrind/asan/chrome_tests.py b/tools/valgrind/asan/chrome_tests.py index 8016ce8..2c56f1b 100755 --- a/tools/valgrind/asan/chrome_tests.py +++ b/tools/valgrind/asan/chrome_tests.py @@ -1,5 +1,4 @@ -#!/usr/bin/python - +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -416,7 +415,12 @@ class ChromeTests(object): # summary list for long, but will be useful for someone reviewing this bot. return ret -def _main(_): + +def main(): + if not sys.platform.startswith(('linux', 'darwin')): + logging.error("AddressSanitizer works only on Linux and Mac OS " + "at the moment.") + return 1 parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> " "[-t <test> ...]") parser.disable_interspersed_args() @@ -456,12 +460,4 @@ def _main(_): if __name__ == "__main__": - if sys.platform.startswith('linux'): - ret = _main(sys.argv) - elif sys.platform.startswith('darwin'): - ret = _main(sys.argv) - else: - logging.error("AddressSanitizer works only on Linux and Mac OS " - "at the moment.") - ret = 1 - sys.exit(ret) + sys.exit(main()) diff --git a/tools/valgrind/chrome_tests.py b/tools/valgrind/chrome_tests.py index c068d43..5e7ce3e 100755 --- a/tools/valgrind/chrome_tests.py +++ b/tools/valgrind/chrome_tests.py @@ -1,10 +1,8 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# chrome_tests.py - ''' Runs various chrome tests through valgrind_test.py.''' import glob @@ -459,7 +457,8 @@ class ChromeTests: "views": TestViews, "views_unittests": TestViews, } -def _main(_): + +def _main(): parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> " "[-t <test> ...]") parser.disable_interspersed_args() @@ -509,5 +508,4 @@ def _main(_): if __name__ == "__main__": - ret = _main(sys.argv) - sys.exit(ret) + sys.exit(_main()) diff --git a/tools/valgrind/drmemory_analyze.py b/tools/valgrind/drmemory_analyze.py index bfef8a8..87c1310 100755 --- a/tools/valgrind/drmemory_analyze.py +++ b/tools/valgrind/drmemory_analyze.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -99,16 +99,21 @@ class DrMemoryAnalyzer: logging.error("Total: %i error reports" % len(to_report)) return -1 -if __name__ == '__main__': - '''For testing only. The DrMemoryAnalyzer class should be imported instead.''' - retcode = 0 - parser = optparse.OptionParser("usage: %prog <files to analyze>") + +def main(): + '''For testing only. The DrMemoryAnalyze class should be imported instead.''' + parser = optparse.OptionParser("usage: %prog [options] <files to analyze>") + parser.add_option("", "--source_dir", + help="path to top of source tree for this build" + "(used to normalize source paths in baseline)") + (options, args) = parser.parse_args() if len(args) == 0: parser.error("no filename specified") filenames = args - analyzer = DrMemoryAnalyzer() - retcode = analyzer.Report(filenames, None, False) + return DrMemoryAnalyzer().Report(filenames, None, False) - sys.exit(retcode) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/valgrind/gdb_helper.py b/tools/valgrind/gdb_helper.py index 9b57c84..548ee94 100644 --- a/tools/valgrind/gdb_helper.py +++ b/tools/valgrind/gdb_helper.py @@ -1,10 +1,7 @@ -#!/usr/bin/python -# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# gdb_helper.py - ''' A bunch of helper functions for querying gdb.''' import logging @@ -74,12 +71,15 @@ class AddressTable(object): for binary in self._binaries.keys(): if binary != '' and binary in self._load_addresses: load_address = self._load_addresses[binary] - addr = ResolveAddressesWithinABinary(binary, load_address, self._binaries[binary]) + addr = ResolveAddressesWithinABinary( + binary, load_address, self._binaries[binary]) self._translation[binary] = addr self._all_resolved = True def GetFileLine(self, binary, addr): - ''' Get the (filename, linenum) result of a previously-registered lookup request. ''' + ''' Get the (filename, linenum) result of a previously-registered lookup + request. + ''' if self._all_resolved: if binary in self._translation: if addr in self._translation[binary]: diff --git a/tools/valgrind/memcheck_analyze.py b/tools/valgrind/memcheck_analyze.py index e73ad26..b07c5d7 100755 --- a/tools/valgrind/memcheck_analyze.py +++ b/tools/valgrind/memcheck_analyze.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -603,9 +603,9 @@ class MemcheckAnalyzer: logging.info("PASS! No errors found!") return 0 + def _main(): '''For testing only. The MemcheckAnalyzer class should be imported instead.''' - retcode = 0 parser = optparse.OptionParser("usage: %prog [options] <files to analyze>") parser.add_option("", "--source_dir", help="path to top of source tree for this build" @@ -617,9 +617,8 @@ def _main(): filenames = args analyzer = MemcheckAnalyzer(options.source_dir, use_gdb=True) - retcode = analyzer.Report(filenames, None) + return analyzer.Report(filenames, None) - sys.exit(retcode) if __name__ == "__main__": - _main() + sys.exit(_main()) diff --git a/tools/valgrind/suppressions.py b/tools/valgrind/suppressions.py index 90362bc..f9d8e90 100644..100755 --- a/tools/valgrind/suppressions.py +++ b/tools/valgrind/suppressions.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/valgrind/tsan/PRESUBMIT.py b/tools/valgrind/tsan/PRESUBMIT.py index 112b41d..7bc04f2 100755 --- a/tools/valgrind/tsan/PRESUBMIT.py +++ b/tools/valgrind/tsan/PRESUBMIT.py @@ -1,4 +1,4 @@ -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tools/valgrind/tsan_analyze.py b/tools/valgrind/tsan_analyze.py index af2d143..65134dd 100644..100755 --- a/tools/valgrind/tsan_analyze.py +++ b/tools/valgrind/tsan_analyze.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -252,9 +252,9 @@ class TsanAnalyzer(object): logging.info("PASS: No reports found") return 0 -if __name__ == '__main__': + +def main(): '''For testing only. The TsanAnalyzer class should be imported instead.''' - retcode = 0 parser = optparse.OptionParser("usage: %prog [options] <files to analyze>") parser.add_option("", "--source_dir", help="path to top of source tree for this build" @@ -266,6 +266,8 @@ if __name__ == '__main__': filenames = args analyzer = TsanAnalyzer(options.source_dir, use_gdb=True) - retcode = analyzer.Report(filenames, None) + return analyzer.Report(filenames, None) - sys.exit(retcode) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/valgrind/valgrind_test.py b/tools/valgrind/valgrind_test.py index a45c938..3ea32b5 100755 --- a/tools/valgrind/valgrind_test.py +++ b/tools/valgrind/valgrind_test.py @@ -1,10 +1,7 @@ -#!/usr/bin/python # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# valgrind_test.py - """Runs an exe through Valgrind and puts the intermediate files in a directory. """ @@ -1187,7 +1184,3 @@ class ToolFactory: def CreateTool(tool): return ToolFactory().Create(tool) - -if __name__ == '__main__': - logging.error(sys.argv[0] + " can not be run from command line") - sys.exit(1) diff --git a/tools/win/supalink/check_installed.py b/tools/win/supalink/check_installed.py index 00b2b59..00b2b59 100644..100755 --- a/tools/win/supalink/check_installed.py +++ b/tools/win/supalink/check_installed.py diff --git a/tools/win/supalink/install_supalink.py b/tools/win/supalink/install_supalink.py index 6aeaa06..6aeaa06 100644..100755 --- a/tools/win/supalink/install_supalink.py +++ b/tools/win/supalink/install_supalink.py |