Commit 2fac3758 authored by maruel@chromium.org's avatar maruel@chromium.org

Fix python scripts in src/chrome/

Make sure that:
- shebang is only present for executable files
- shebang is #!/usr/bin/env python
- __main__ is only present for executable files
- file's executable bit is coherent

Also fix EOF LF to be only one.

Minor python style fixes.

TBR=nirnimesh@chromium.org
BUG=105108
TEST=

Review URL: http://codereview.chromium.org/8680018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111658 0039d316-1c4b-4281-b951-d872f2087c98
parent 07130292
# 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.
......
#!/usr/bin/python2
#!/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.
......@@ -413,5 +413,4 @@ class PolicyTemplateChecker(object):
if __name__ == '__main__':
checker = PolicyTemplateChecker()
sys.exit(checker.Run(sys.argv))
sys.exit(PolicyTemplateChecker().Run(sys.argv))
# 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.
......
#!/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.
......
#!/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.
......@@ -11,22 +11,23 @@ to the input .proto file.
Run it like:
litify_proto_file.py input.proto output.proto
"""
import fileinput
import sys
def main(argv):
if len(argv) != 3:
print 'Usage: litify_proto_file.py [input] [output]'
sys.exit(1)
return 1
output_file = open(sys.argv[2], 'w')
for line in fileinput.input(sys.argv[1]):
output_file.write(line)
output_file.write("\noption optimize_for = LITE_RUNTIME;\n")
return 0
if __name__ == '__main__':
main(sys.argv)
sys.exit(main(sys.argv))
#!/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.
......@@ -27,9 +27,11 @@ presented by <input type=file multiple> do not allow users to recurse a
selected directory, nor do they provide information about directory structure.
""")
def status(msg):
sys.stderr.write(msg + '\n')
def scan_path(dest, src, path):
abs_src = os.path.join(src, path)
statinfo = os.stat(abs_src)
......@@ -44,10 +46,11 @@ def scan_path(dest, src, path):
for child_path in glob.glob(abs_src + '/*'):
scan_path(dest, src, child_path[len(src) + 1:])
if __name__ == '__main__':
def main():
if len(sys.argv) < 3 or sys.argv[1][0] == '-':
usage()
return
return 1
dest = sys.argv[1]
for src in sys.argv[2:]:
......@@ -55,3 +58,8 @@ if __name__ == '__main__':
path = os.path.basename(abs_src)
abs_src = os.path.dirname(abs_src)
scan_path(dest, abs_src, path)
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
......
#!/usr/bin/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.
......
#!/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.
......@@ -215,13 +215,14 @@ def Main(argv):
if args or not options.platforms or (
not options.inputs and not options.outdir):
parser.print_help()
sys.exit(1)
return 1
if options.inputs:
PrintInputs(options.platforms)
else:
BuildIRT(options.platforms, options.outdir)
return 0
if __name__ == '__main__':
Main(sys.argv)
sys.exit(Main(sys.argv))
#!/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.
......
#!/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.
......@@ -76,6 +76,7 @@ kStringIds = [
# The ID of the first resource string.
kFirstResourceID = 1600
class TranslationStruct:
"""A helper struct that holds information about a single translation."""
def __init__(self, resource_id_str, language, translation):
......@@ -152,6 +153,7 @@ def CollectTranslatedStrings(branding):
translated_strings.sort()
return translated_strings
def WriteRCFile(translated_strings, out_filename):
"""Writes a resource (rc) file with all the language strings provided in
|translated_strings|."""
......@@ -177,6 +179,7 @@ def WriteRCFile(translated_strings, out_filename):
outfile.write(''.join(lines).encode('utf-16'))
outfile.close()
def WriteHeaderFile(translated_strings, out_filename):
"""Writes a .h file with resource ids. This file can be included by the
executable to refer to identifiers."""
......@@ -219,7 +222,12 @@ def WriteHeaderFile(translated_strings, out_filename):
outfile.write('\n#endif // ndef RC_INVOKED\n')
outfile.close()
def main(argv):
# TODO: Use optparse to parse command line flags.
if len(argv) < 2:
print 'Usage:\n %s <output_directory> [branding]' % argv[0]
return 1
branding = ''
if (len(sys.argv) > 2):
branding = argv[2]
......@@ -227,10 +235,8 @@ def main(argv):
kFilebase = os.path.join(argv[1], 'installer_util_strings')
WriteRCFile(translated_strings, kFilebase)
WriteHeaderFile(translated_strings, kFilebase)
return 0
if '__main__' == __name__:
if len(sys.argv) < 2:
print 'Usage:\n %s <output_directory> [branding]' % sys.argv[0]
sys.exit(1)
# Use optparse to parse command line flags.
main(sys.argv)
sys.exit(main(sys.argv))
#!/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 takes three command-line arguments:
# MUNGE-PHDR-PROGRAM file name of program built from
# nacl_helper_bootstrap_munge_phdr.c
# INFILE raw linked ELF file name
# OUTFILE output file name
#
# We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE.
# That modifies the file in place. Then we move it to OUTFILE.
#
# We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c
# wants to modify a file in place (and it would be a much longer and more
# fragile program if it created a fresh ELF output file instead).
"""This takes three command-line arguments:
MUNGE-PHDR-PROGRAM file name of program built from
nacl_helper_bootstrap_munge_phdr.c
INFILE raw linked ELF file name
OUTFILE output file name
We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE.
That modifies the file in place. Then we move it to OUTFILE.
We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c
wants to modify a file in place (and it would be a much longer and more
fragile program if it created a fresh ELF output file instead).
"""
import shutil
import subprocess
......@@ -24,13 +25,15 @@ import sys
def Main(argv):
if len(argv) != 4:
print 'Usage: %s MUNGE-PHDR-PROGRAM INFILE OUTFILE' % argv[0]
sys.exit(1)
return 1
[prog, munger, infile, outfile] = argv
tmpfile = outfile + '.tmp'
shutil.copy(infile, tmpfile)
segment_num = '2'
subprocess.check_call([munger, tmpfile, segment_num])
shutil.move(tmpfile, outfile)
return 0
if __name__ == '__main__':
Main(sys.argv)
sys.exit(Main(sys.argv))
#!/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.
......@@ -6,7 +7,6 @@ import sys
def main():
"""Converts a vertical serialization into a compact, horizontal serialization.
"""
COLUMNS = ['First name', 'Middle name', 'Last name', 'Email', 'Company name',
......@@ -59,7 +59,8 @@ def main():
profile_format = zip(column_formats, profile)
profile = [format_.format(value) for (format_, value) in profile_format]
print " | ".join(profile)
return 0
if __name__ == '__main__':
main()
\ No newline at end of file
sys.exit(main())
#!/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.
......@@ -6,9 +7,9 @@ import sys
from autofill_merge_common import SerializeProfiles, ColumnNameToFieldType
def main():
"""Serializes the output of the query 'SELECT * from autofill_profiles;'.
"""
COLUMNS = ['GUID', 'LABEL', 'FIRST_NAME', 'MIDDLE_NAME', 'LAST_NAME', 'EMAIL',
......@@ -32,7 +33,8 @@ def main():
profiles.append(zip(types, values))
print SerializeProfiles(profiles)
return 0
if __name__ == '__main__':
main()
\ No newline at end of file
sys.exit(main())
#!/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.
......@@ -8,17 +9,18 @@ import sys
from autofill_merge_common import SerializeProfiles, ColumnNameToFieldType
def main():
"""Serializes the autofill_profiles table from the specified database."""
if len(sys.argv) != 2:
print "Usage: python serialize_profiles.py <path/to/database>"
return
return 1
database = sys.argv[1]
if not os.path.isfile(database):
print "Cannot read database at \"%s\"" % database
return
return 1
# Read the autofill_profile_names table.
try:
......@@ -77,7 +79,8 @@ def main():
profiles[guid].append(("PHONE_HOME_WHOLE_NUMBER", profile[2]))
print SerializeProfiles(profiles.values())
return 0
if __name__ == '__main__':
main()
\ No newline at end of file
sys.exit(main())
#!/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.
......
#!/usr/bin/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.
......
#!/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.
......@@ -60,4 +59,3 @@ class ChromeDriverFactory(object):
def __del__(self):
self.Stop()
#!/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.
......
#!/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 +18,7 @@ Usage:
import dbus
import optparse
import os
import sys
class EnableChromeTestingOnChromeOS(object):
......@@ -46,8 +46,8 @@ class EnableChromeTestingOnChromeOS(object):
self.SESSION_MANAGER_PATH),
self.SESSION_MANAGER_INTERFACE)
print manager.EnableChromeTesting(True, self._options.extra_chrome_flags)
return 0
if __name__ == '__main__':
enabler = EnableChromeTestingOnChromeOS()
enabler.Run()
sys.exit(EnableChromeTestingOnChromeOS().Run())
#!/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.
......
#!/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.
......@@ -16,6 +15,7 @@ Usage:
import optparse
import os
import shutil
import sys
class SuidAction(object):
......@@ -29,7 +29,6 @@ class SuidAction(object):
if not self._options.action:
raise RuntimeError('No action specified.')
def Run(self):
self._ParseArgs()
assert os.geteuid() == 0, 'Needs superuser privileges.'
......@@ -37,6 +36,7 @@ class SuidAction(object):
assert handler and callable(handler), \
'No handler for %s' % self._options.action
handler()
return 0
## Actions ##
......@@ -54,5 +54,4 @@ class SuidAction(object):
if __name__ == '__main__':
suid_action = SuidAction()
suid_action.Run()
sys.exit(SuidAction().Run())
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......@@ -172,7 +171,8 @@ class FetchPrebuilt(object):
os.symlink(framework, dest)
print 'Prepared binaries in "%s"' % self._outdir
return 0
if __name__ == '__main__':
FetchPrebuilt().Run()
sys.exit(FetchPrebuilt().Run())
#!/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.
......@@ -36,7 +36,7 @@ def main():
if options.dir == os.getcwd():
print 'Export complete, files are located in %s' % options.dir
return
return 1
new_files = current_contents.difference(previous_contents)
for file_name in new_files:
......@@ -50,8 +50,8 @@ def main():
shutil.move(full_path, options.dir)
print 'Export complete, files are located in %s' % options.dir
return 0
if __name__ == '__main__':
main()
sys.exit(main())
#!/usr/bin/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.
......
#!/usr/bin/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.
......@@ -141,4 +139,3 @@ class OmniboxInfo(object):
def IsQueryInProgress(self):
"""Determine if a query is in progress."""
return self.Properties('query_in_progress')
#!/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.
......@@ -870,7 +869,8 @@ def main():
snapshotter.SetInteractiveMode()
snapshotter.HeapSnapshot()
return 0
if __name__ == '__main__':
main()
sys.exit(main())
#!/usr/bin/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.
......@@ -112,4 +110,3 @@ class PluginsInfo(object):
all = self.PluginForName(name)
if not all: return None
return all[0]
#!/usr/bin/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.
......
#!/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.
......
#!/usr/bin/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.
......
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......@@ -85,4 +83,3 @@ class TimerQueue(threading.Thread):
if self.terminate:
return
time.sleep(self.wait_time)
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......
#!/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.
......@@ -24,7 +24,7 @@ import chromedriver_tests
import py_unittest_util
if __name__ == '__main__':
def main():
parser = optparse.OptionParser()
parser.add_option(
'', '--filter', type='string', default='*',
......@@ -47,10 +47,10 @@ if __name__ == '__main__':
if options.list is True:
print '\n'.join(py_unittest_util.GetTestNamesFromSuite(filtered_suite))
sys.exit(0)
return 0
if sys.platform.startswith('darwin'):
print 'All tests temporarily disabled on mac, crbug.com/103434'
sys.exit(0)
return 0
driver_exe = options.driver_exe
if driver_exe is not None:
......@@ -61,4 +61,8 @@ if __name__ == '__main__':
ChromeDriverTest.GlobalSetUp(driver_exe, chrome_exe)
result = py_unittest_util.GTestTextTestRunner(verbosity=1).run(filtered_suite)
ChromeDriverTest.GlobalTearDown()
sys.exit(not result.wasSuccessful())
return not result.wasSuccessful()
if __name__ == '__main__':
sys.exit(main())
#!/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.
......
#!/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.
......
#!/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.
......
#!/usr/bin/env python
# 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.
# A python script that combines the javascript files needed by jstemplate into
# a single file.
"""Combines the javascript files needed by jstemplate into a single file."""
import httplib
import urllib
srcs ="util.js jsevalcontext.js jstemplate.js exports.js".split()
out = "jstemplate_compiled.js"
# Wrap the output in an anonymous function to prevent poluting the global
# namespace.
output_wrapper = "(function(){%s})()"
# Define the parameters for the POST request and encode them in a URL-safe
# format. See http://code.google.com/closure/compiler/docs/api-ref.html for API
# reference.
params = urllib.urlencode(
map(lambda src: ('js_code', file(src).read()), srcs) +
[
('compilation_level', 'ADVANCED_OPTIMIZATIONS'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
# Always use the following value for the Content-type header.
headers = {'Content-type': 'application/x-www-form-urlencoded'}
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
out_file = file(out, 'w')
out_file.write(output_wrapper % response.read())
out_file.close()
conn.close()
def main():
srcs = ['util.js', 'jsevalcontext.js', 'jstemplate.js', 'exports.js']
out = 'jstemplate_compiled.js'
# Wrap the output in an anonymous function to prevent poluting the global
# namespace.
output_wrapper = '(function(){%s})()'
# Define the parameters for the POST request and encode them in a URL-safe
# format. See http://code.google.com/closure/compiler/docs/api-ref.html for
# API reference.
params = urllib.urlencode(
map(lambda src: ('js_code', file(src).read()), srcs) +
[
('compilation_level', 'ADVANCED_OPTIMIZATIONS'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
# Always use the following value for the Content-type header.
headers = {'Content-type': 'application/x-www-form-urlencoded'}
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
out_file = file(out, 'w')
out_file.write(output_wrapper % response.read())
out_file.close()
conn.close()
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
......@@ -68,10 +67,7 @@ def CreateUIActionList(actions_per_command, num_commands, given_seed=None):
def ParseCommandLine():
"""Parses the command line.
Returns:
List of options and their values, and unparsed args.
"""Returns the list of options and their values, and unparsed args.
"""
parser = optparse.OptionParser()
parser.add_option('-o', '--output', dest='output_file', type='string',
......@@ -102,7 +98,8 @@ def main():
f.write(command_list)
f.close()
print command_list
return 0
if __name__ == '__main__':
main()
sys.exit(main())
#!/usr/bin/env python
# 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.
......
#!/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.
......@@ -51,7 +51,7 @@ def main():
if len(args) != 3:
print "exactly platform, chromium_os flag and input file must be specified."
parser.print_help()
sys.exit(2)
return 2
template_file_contents = _LoadJSONFile(args[2]);
if opts.header_path is not None:
_WritePolicyConstantHeader(template_file_contents, args, opts);
......@@ -63,6 +63,7 @@ def main():
_WriteProtobuf(template_file_contents, args, opts.proto_path)
if opts.decoder_path is not None:
_WriteProtobufParser(template_file_contents, args, opts.decoder_path)
return 0
#------------------ shared helpers ---------------------------------#
......@@ -462,6 +463,5 @@ def _WriteProtobufParser(template_file_contents, args, outfilepath):
f.write(CPP_FOOT)
#------------------ main() -----------------------------------------#
if __name__ == '__main__':
main();
sys.exit(main())
#!/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.
......
#!/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.
......@@ -40,6 +40,7 @@ def RunSystemCommand(cmd):
except:
raise Error("Failed to execute: " + cmd)
def RunDumpbin(binary_file):
"""Runs dumpbin and parses its output.
......@@ -196,8 +197,19 @@ def VerifyDependents(pe_name, dependents, delay_loaded, list_file, verbose):
return max(deps_result, delayed_result)
def main(options, args):
def main():
# PE means portable executable. It's any .DLL, .EXE, .SYS, .AX, etc.
usage = "usage: %prog [options] input output"
option_parser = optparse.OptionParser(usage=usage)
option_parser.add_option("-d",
"--debug",
dest="debug",
action="store_true",
default=False,
help="Display debugging information")
options, args = option_parser.parse_args()
if len(args) != 2:
option_parser.error("Incorrect number of arguments")
pe_name = args[0]
deps_file = args[1]
dependents, delay_loaded = RunDumpbin(pe_name)
......@@ -211,15 +223,4 @@ def main(options, args):
if '__main__' == __name__:
usage = "usage: %prog [options] input output"
option_parser = optparse.OptionParser(usage = usage)
option_parser.add_option("-d",
"--debug",
dest="debug",
action="store_true",
default=False,
help="Display debugging information")
options, args = option_parser.parse_args()
if len(args) != 2:
option_parser.error("Incorrect number of arguments")
sys.exit(main(options, args))
sys.exit(main())
#!/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,6 +13,7 @@ import os
import sys
import zipfile
def add_files_to_zip(zip_file, base_dir, file_list):
"""Pack a list of files into a zip archive, that is already
opened for writing.
......@@ -26,6 +28,7 @@ def add_files_to_zip(zip_file, base_dir, file_list):
zip_file.write(base_dir + file_path, file_path)
return 0
def get_grd_outputs(grit_cmd, grit_defines, grd_file, grd_strip_path_prefix):
grit_path = os.path.join(os.getcwd(), os.path.dirname(grit_cmd))
sys.path.append(grit_path)
......@@ -37,6 +40,7 @@ def get_grd_outputs(grit_cmd, grit_defines, grd_file, grd_strip_path_prefix):
result.append(item[len(grd_strip_path_prefix):])
return result
def main(argv):
"""Pack a list of files into a zip archive.
......@@ -73,6 +77,6 @@ def main(argv):
finally:
zip_file.close()
if '__main__' == __name__:
sys.exit(main(sys.argv))
#!/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.
"""Script used to scan for server DLLs at build time and build a header
included by setup.exe. This header contains an array of the names of
the DLLs that need registering at install time.
"""
import ConfigParser
......@@ -128,19 +127,11 @@ def RunSystemCommand(cmd):
raise "Error while running cmd: %s" % cmd
def main(options):
def main():
"""Main method that reads input file, scans <build_output>\servers for
matches to files described in the input file. A header file for the
setup project is then generated.
"""
config = Readconfig(options.output_dir, options.input_file)
registered_dll_list = ScanServerDlls(config, options.distribution,
options.output_dir)
CreateRegisteredDllIncludeFile(registered_dll_list,
options.header_output_dir)
if '__main__' == __name__:
option_parser = optparse.OptionParser()
option_parser.add_option('-o', '--output_dir', help='Build Output directory')
option_parser.add_option('-x', '--header_output_dir',
......@@ -150,4 +141,13 @@ if '__main__' == __name__:
help='Name of Chromium Distribution. Optional.')
options, args = option_parser.parse_args()
sys.exit(main(options))
config = Readconfig(options.output_dir, options.input_file)
registered_dll_list = ScanServerDlls(config, options.distribution,
options.output_dir)
CreateRegisteredDllIncludeFile(registered_dll_list,
options.header_output_dir)
return 0
if '__main__' == __name__:
sys.exit(main())
#!/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.
......@@ -63,7 +63,7 @@ def ScanSlnFile(filename):
return projects
def main(filename, project_to_scan, reverse):
def sln_deps(filename, project_to_scan, reverse):
"""Displays the project's dependencies."""
project_to_scan = project_to_scan.lower()
......@@ -91,9 +91,10 @@ def main(filename, project_to_scan, reverse):
deps_name = [projects[d].name for d in project.deps]
print "\n".join(str(" " + name) for name in sorted(deps_name,
key=str.lower))
return 0
if __name__ == '__main__':
def main():
usage = "usage: %prog [options] solution [project]"
description = ("Display the dependencies of a project in human readable"
......@@ -116,5 +117,8 @@ if __name__ == '__main__':
project_to_scan = ""
if len(args) == 2:
project_to_scan = args[1]
main(args[0], project_to_scan, options.reverse)
return sln_deps(args[0], project_to_scan, options.reverse)
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/python
# Copyright (c) 2006-2008 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
if len(sys.argv) != 2:
print """Usage: sort_sln.py <SOLUTIONNAME>.sln
to sort the solution file to a normalized scheme. Do this before checking in
changes to a solution file to avoid having a lot of unnecessary diffs."""
sys.exit(1)
filename = sys.argv[1]
print "Sorting " + filename;
try:
sln = open(filename, "r");
except IOError:
print "Unable to open " + filename + " for reading."
sys.exit(1)
output = ""
seclines = None
while 1:
line = sln.readline()
if not line:
break
if seclines is not None:
# Process the end of a section, dump the sorted lines
if line.lstrip().startswith('End'):
output = output + ''.join(sorted(seclines))
seclines = None
# Process within a section
else:
seclines.append(line)
continue
# Process the start of a section
if (line.lstrip().startswith('GlobalSection') or
line.lstrip().startswith('ProjectSection')):
if seclines: raise Exception('Already in a section')
seclines = []
output = output + line
sln.close()
try:
sln = open(filename, "w")
sln.write(output)
except IOError:
print "Unable to write to " + filename
sys.exit(1);
print "Done."
#!/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.
......@@ -111,7 +110,7 @@ def CheckForUnusedGrdIDsInSources(grd_files, src_dirs):
return 0
if __name__ == '__main__':
def main():
# script lives in src/chrome/tools
chrome_tools_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
src_dir = os.path.dirname(os.path.dirname(chrome_tools_dir))
......@@ -162,4 +161,8 @@ if __name__ == '__main__':
os.path.join(src_dir, 'third_party', 'mozilla_security_manager'),
]
sys.exit(CheckForUnusedGrdIDsInSources(grd_files, src_dirs))
return CheckForUnusedGrdIDsInSources(grd_files, src_dirs)
if __name__ == '__main__':
sys.exit(main())
#!/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.
......@@ -439,6 +439,8 @@ def main(argv):
if hash_output:
print "Done. Do not forget to add chromeactions.txt to your changelist"
return 0
if '__main__' == __name__:
main(sys.argv)
sys.exit(main(sys.argv))
#!/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.
......@@ -35,6 +35,7 @@ def GrepForHistograms(path, histograms):
if match:
histograms.add(match.group(1))
def WalkDirectory(root_path, histograms):
for path, dirs, files in os.walk(root_path):
if '.svn' in dirs:
......@@ -44,6 +45,7 @@ def WalkDirectory(root_path, histograms):
if ext == '.cc':
GrepForHistograms(os.path.join(path, file), histograms)
def main(argv):
histograms = set()
......@@ -53,6 +55,8 @@ def main(argv):
# Print out the histograms as a sorted list.
for histogram in sorted(histograms):
print histogram
return 0
if '__main__' == __name__:
main(sys.argv)
sys.exit(main(sys.argv))
#!/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.
......@@ -17,7 +17,18 @@ import subprocess
import sys
import urlparse
class URL:
# Some transition types, copied from page_transition_types.h.
TRANS_TYPES = {
0: 'link',
1: 'typed',
2: 'most-visited',
3: 'auto subframe',
7: 'form',
}
class URL(object):
"""Represents a broken-down URL from our most visited database."""
def __init__(self, id, url):
......@@ -67,7 +78,8 @@ class URL:
lines.append(line)
return '\n'.join(lines)
class Edge:
class Edge(object):
"""Represents an edge in the history graph, connecting two pages.
If a link is traversed twice, it is one Edge with two entries in
......@@ -97,6 +109,7 @@ class Edge:
# edge['chain'] = chain
return all
def ClusterBy(objs, pred):
"""Group a list of objects by a predicate.
......@@ -109,12 +122,14 @@ def ClusterBy(objs, pred):
clusters[cluster].append(obj)
return clusters
def EscapeDot(str):
def EscapeDot(string):
"""Escape a string suitable for embedding in a graphviz graph."""
# TODO(evanm): this is likely not sufficient.
return str.replace('\n', '\\n')
return string.replace('\n', '\\n')
class SQLite:
class SQLite(object):
"""Trivial interface to executing SQLite queries.
Spawns a new process with each call."""
def __init__(self, file=None):
......@@ -132,6 +147,7 @@ class SQLite:
row = line.strip().split('\t')
yield row
def LoadHistory(filename):
db = SQLite(filename)
......@@ -157,85 +173,81 @@ def LoadHistory(filename):
return urls, edges
# Some transition types, copied from page_transition_types.h.
TRANS_TYPES = {
0: 'link',
1: 'typed',
2: 'most-visited',
3: 'auto subframe',
7: 'form',
}
urls, edges = LoadHistory(sys.argv[1])
print 'digraph G {'
print ' graph [rankdir=LR]' # Display left to right.
print ' node [shape=box]' # Display nodes as boxes.
print ' subgraph { rank=source; 0 [label="start"] }'
# Output all the nodes within graph clusters.
hosts = ClusterBy(urls.values(), lambda url: url.host)
for i, (host, urls) in enumerate(hosts.items()):
# Cluster all URLs under this host if it has more than one entry.
host_clustered = len(urls) > 1
if host_clustered:
print 'subgraph clusterhost%d {' % i
print ' label="%s"' % host
paths = ClusterBy(urls, lambda url: url.path)
for j, (path, urls) in enumerate(paths.items()):
# Cluster all URLs under this host if it has more than one entry.
path_clustered = host_clustered and len(urls) > 1
if path_clustered:
print ' subgraph cluster%d%d {' % (i, j)
print ' label="%s"' % path
for url in urls:
if url.id == '0': continue # We already output the special start node.
pretty = url.PrettyPrint(include_host=not host_clustered,
include_path=not path_clustered)
print ' %s [label="%s"]' % (url.id, EscapeDot(pretty))
if path_clustered:
print ' }'
if host_clustered:
print '}'
# Output all the edges between nodes.
for src, dsts in edges.items():
for dst, edge in dsts.items():
# Gather up all the transitions into the label.
label = [] # Label for the edge.
transitions = edge.Transitions()
for trans, count in transitions.items():
text = ''
if count > 1:
text = '%dx ' % count
base_type = trans & 0xFF
redir = (trans & 0xC0000000) != 0
start = (trans & 0x10000000) != 0
end = (trans & 0x20000000) != 0
if start or end:
if start:
text += '<'
if end:
text += '>'
text += ' '
if redir:
text += 'R '
text += TRANS_TYPES.get(base_type, 'trans%d' % base_type)
label.append(text)
if len(label) == 0:
continue
edgeattrs = [] # Graphviz attributes for the edge.
# If the edge is from the start and the transitions are fishy, make it
# display as a dotted line.
if src == '0' and len(transitions.keys()) == 1 and transitions.has_key(0):
edgeattrs.append('style=dashed')
if len(label) > 0:
edgeattrs.append('label="%s"' % EscapeDot('\n'.join(label)))
out = '%s -> %s' % (src, dst)
if len(edgeattrs) > 0:
out += ' [%s]' % ','.join(edgeattrs)
print out
print '}'
def main():
urls, edges = LoadHistory(sys.argv[1])
print 'digraph G {'
print ' graph [rankdir=LR]' # Display left to right.
print ' node [shape=box]' # Display nodes as boxes.
print ' subgraph { rank=source; 0 [label="start"] }'
# Output all the nodes within graph clusters.
hosts = ClusterBy(urls.values(), lambda url: url.host)
for i, (host, urls) in enumerate(hosts.items()):
# Cluster all URLs under this host if it has more than one entry.
host_clustered = len(urls) > 1
if host_clustered:
print 'subgraph clusterhost%d {' % i
print ' label="%s"' % host
paths = ClusterBy(urls, lambda url: url.path)
for j, (path, urls) in enumerate(paths.items()):
# Cluster all URLs under this host if it has more than one entry.
path_clustered = host_clustered and len(urls) > 1
if path_clustered:
print ' subgraph cluster%d%d {' % (i, j)
print ' label="%s"' % path
for url in urls:
if url.id == '0': continue # We already output the special start node.
pretty = url.PrettyPrint(include_host=not host_clustered,
include_path=not path_clustered)
print ' %s [label="%s"]' % (url.id, EscapeDot(pretty))
if path_clustered:
print ' }'
if host_clustered:
print '}'
# Output all the edges between nodes.
for src, dsts in edges.items():
for dst, edge in dsts.items():
# Gather up all the transitions into the label.
label = [] # Label for the edge.
transitions = edge.Transitions()
for trans, count in transitions.items():
text = ''
if count > 1:
text = '%dx ' % count
base_type = trans & 0xFF
redir = (trans & 0xC0000000) != 0
start = (trans & 0x10000000) != 0
end = (trans & 0x20000000) != 0
if start or end:
if start:
text += '<'
if end:
text += '>'
text += ' '
if redir:
text += 'R '
text += TRANS_TYPES.get(base_type, 'trans%d' % base_type)
label.append(text)
if len(label) == 0:
continue
edgeattrs = [] # Graphviz attributes for the edge.
# If the edge is from the start and the transitions are fishy, make it
# display as a dotted line.
if src == '0' and len(transitions.keys()) == 1 and transitions.has_key(0):
edgeattrs.append('style=dashed')
if len(label) > 0:
edgeattrs.append('label="%s"' % EscapeDot('\n'.join(label)))
out = '%s -> %s' % (src, dst)
if len(edgeattrs) > 0:
out += ' [%s]' % ','.join(edgeattrs)
print out
print '}'
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
......@@ -38,6 +38,7 @@ def CountChars(text, str):
logging.debug(len(split) - 1)
return len(split) - 1
def PrevailingEOLName(crlf, cr, lf):
"""Describe the most common line ending.
......@@ -56,6 +57,7 @@ def PrevailingEOLName(crlf, cr, lf):
return 'crlf'
return 'lf'
def FixEndings(file, crlf, cr, lf):
"""Change the file's line endings to CRLF or LF, whichever is more common."""
most = max(crlf, cr, lf)
......@@ -99,7 +101,8 @@ def ProcessFiles(filelist):
print '%s: mostly %s' % (filename, PrevailingEOLName(crlf, cr, lf))
FixEndings(filename, crlf, cr, lf)
def main(options, args):
def process(options, args):
"""Process the files."""
if not args or len(args) < 1:
raise Error('No files given.')
......@@ -111,8 +114,10 @@ def main(options, args):
else:
filelist = args
ProcessFiles(filelist)
return 0
if '__main__' == __name__:
def main():
if DEBUGGING:
debug_level = logging.DEBUG
else:
......@@ -131,5 +136,8 @@ if '__main__' == __name__:
default=False,
help="Force any files with CRLF to LF instead.")
options, args = option_parser.parse_args()
return process(options, args)
sys.exit(main(options, args))
if '__main__' == __name__:
sys.exit(main())
#!/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.
......@@ -265,7 +265,9 @@ def main_linux(options, args):
return 0
if '__main__' == __name__:
def main():
if not sys.platform.startswith('linux'):
return 1
parser = optparse.OptionParser()
parser.add_option('', '--processor-dir', type='string', default='',
help='The directory where the processor is installed. '
......@@ -291,8 +293,8 @@ if '__main__' == __name__:
'Default: chrome')
(options, args) = parser.parse_args()
return main_linux(options, args)
if sys.platform.startswith('linux'):
sys.exit(main_linux(options, args))
else:
sys.exit(1)
if '__main__' == __name__:
sys.exit(main())
#!/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.
......@@ -722,7 +722,6 @@ class ThreadedCrawler(object):
def main():
# Command line options.
usage = 'usage: %prog [options] single_url_or_urls_filename'
parser = optparse.OptionParser(usage)
parser.add_option(
......@@ -734,7 +733,7 @@ def main():
if options.log_level not in ['DEBUG', 'INFO', 'WARNING', 'ERROR']:
print 'Wrong log_level argument.'
parser.print_help()
sys.exit(1)
return 1
options.log_level = getattr(logging, options.log_level)
if len(args) != 1:
......@@ -762,7 +761,8 @@ def main():
logger.info('Started at: %s\n', t0)
logger.info('Ended at: %s\n', t1)
logger.info('Total execution time: %s\n', delta_t)
return 0
if __name__ == "__main__":
main()
sys.exit(main())
#!/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.
......
#!/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 diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment