Commit aa539ba4 authored by maruel@chromium.org's avatar maruel@chromium.org

Fix many* python scripts in src/

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.

* Do not fix them all at once otherwise the CL would be too large.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111427 0039d316-1c4b-4281-b951-d872f2087c98
parent e51bdf3d
#!/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.
......
# 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.
......@@ -108,7 +109,8 @@ def Main():
del os.environ['VS_UNICODE_OUTPUT']
CombineLibraries(output, remove_re, args)
return 0
if __name__ == '__main__':
Main()
sys.exit(Main())
# 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.
'''This is a simple helper script to shut down the Chrome Frame helper process.
It needs the Python Win32 extensions.'''
"""This is a simple helper script to shut down the Chrome Frame helper process.
Requires Python Win32 extensions.
"""
import pywintypes
import sys
import win32gui
import win32con
def main():
exit_code = 0
window = win32gui.FindWindow('ChromeFrameHelperWindowClass',
......@@ -23,8 +27,8 @@ def main():
print 'Failed to shutdown Chrome Frame helper process: '
print ex
exit_code = 1
return exit_code
if __name__ == '__main__':
sys.exit(main())
# 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.
'''This script builds and runs the Chrome Frame unit and integration tests,
"""Builds and runs the Chrome Frame unit and integration tests,
the exit status of the scrip is the number of failed tests.
'''
"""
import os.path
import sys
import win32com.client
......
#!/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.
......@@ -5992,7 +5991,9 @@ def main(argv):
if gen.errors > 0:
print "%d errors" % gen.errors
sys.exit(1)
return 1
return 0
if __name__ == '__main__':
main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
#!/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.
......@@ -20,39 +20,48 @@ import subprocess
import sys
def usage():
print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0]
sys.exit(1)
print 'usage: %s {--cflags|--ldflags|--libs}' % sys.argv[0]
def run_cups_config(mode):
"""Run cups-config with all --cflags etc modes, parse out the mode we want,
and return those flags as a list."""
cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'],
stdout=subprocess.PIPE)
flags = cups.communicate()[0].strip()
flags_subset = []
for flag in flags.split():
flag_mode = None
if flag.startswith('-l'):
flag_mode = '--libs'
elif (flag.startswith('-L') or flag.startswith('-Wl,')):
flag_mode = '--ldflags'
elif (flag.startswith('-I') or flag.startswith('-D')):
flag_mode = '--cflags'
# Be conservative: for flags where we don't know which mode they
# belong in, always include them.
if flag_mode is None or flag_mode == mode:
flags_subset.append(flag)
return flags_subset
if len(sys.argv) != 2:
"""Run cups-config with all --cflags etc modes, parse out the mode we want,
and return those flags as a list."""
cups = subprocess.Popen(['cups-config', '--cflags', '--ldflags', '--libs'],
stdout=subprocess.PIPE)
flags = cups.communicate()[0].strip()
flags_subset = []
for flag in flags.split():
flag_mode = None
if flag.startswith('-l'):
flag_mode = '--libs'
elif (flag.startswith('-L') or flag.startswith('-Wl,')):
flag_mode = '--ldflags'
elif (flag.startswith('-I') or flag.startswith('-D')):
flag_mode = '--cflags'
# Be conservative: for flags where we don't know which mode they
# belong in, always include them.
if flag_mode is None or flag_mode == mode:
flags_subset.append(flag)
return flags_subset
def main():
if len(sys.argv) != 2:
usage()
return 1
mode = sys.argv[1]
if mode not in ('--cflags', '--libs', '--ldflags'):
mode = sys.argv[1]
if mode not in ('--cflags', '--libs', '--ldflags'):
usage()
flags = run_cups_config(mode)
print ' '.join(flags)
return 1
flags = run_cups_config(mode)
print ' '.join(flags)
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
#
# gettoken.py can be used to get auth token from Gaia. It asks username and
# password and then prints token on the screen.
"""Get auth token from Gaia.
It asks username and password and then prints token on the screen.
"""
import getpass
import os
......@@ -13,46 +14,53 @@ import urllib
import gaia_auth
chromoting_auth_filepath = os.path.join(os.path.expanduser('~'),
'.chromotingAuthToken')
chromoting_dir_auth_filepath = os.path.join(os.path.expanduser('~'),
'.chromotingDirectoryAuthToken')
print "Email:",
email = raw_input()
passwd = getpass.getpass("Password: ")
chromoting_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
chromoting_auth_token = chromoting_authenticator.authenticate(email, passwd)
chromoting_dir_authenticator = gaia_auth.GaiaAuthenticator('chromoting');
chromoting_dir_auth_token = \
chromoting_dir_authenticator.authenticate(email, passwd)
# Set permission mask for created files.
os.umask(0066)
chromoting_auth_file = open(chromoting_auth_filepath, 'w')
chromoting_auth_file.write(email)
chromoting_auth_file.write('\n')
chromoting_auth_file.write(chromoting_auth_token)
chromoting_auth_file.close()
print
print 'Chromoting (sync) Auth Token:'
print
print chromoting_auth_token
print '...saved in', chromoting_auth_filepath
chromoting_dir_auth_file = open(chromoting_dir_auth_filepath, 'w')
chromoting_dir_auth_file.write(email)
chromoting_dir_auth_file.write('\n')
chromoting_dir_auth_file.write(chromoting_dir_auth_token)
chromoting_dir_auth_file.close()
print
print 'Chromoting Directory Auth Token:'
print
print chromoting_dir_auth_token
print '...saved in', chromoting_dir_auth_filepath
def main():
basepath = os.path.expanduser('~')
chromoting_auth_filepath = os.path.join(basepath, '.chromotingAuthToken')
chromoting_dir_auth_filepath = os.path.join(
basepath, '.chromotingDirectoryAuthToken')
print "Email:",
email = raw_input()
passwd = getpass.getpass("Password: ")
chromoting_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
chromoting_auth_token = chromoting_authenticator.authenticate(email, passwd)
chromoting_dir_authenticator = gaia_auth.GaiaAuthenticator('chromoting');
chromoting_dir_auth_token = chromoting_dir_authenticator.authenticate(
email, passwd)
# Set permission mask for created files.
os.umask(0066)
chromoting_auth_file = open(chromoting_auth_filepath, 'w')
chromoting_auth_file.write(email)
chromoting_auth_file.write('\n')
chromoting_auth_file.write(chromoting_auth_token)
chromoting_auth_file.close()
print
print 'Chromoting (sync) Auth Token:'
print
print chromoting_auth_token
print '...saved in', chromoting_auth_filepath
chromoting_dir_auth_file = open(chromoting_dir_auth_filepath, 'w')
chromoting_dir_auth_file.write(email)
chromoting_dir_auth_file.write('\n')
chromoting_dir_auth_file.write(chromoting_dir_auth_token)
chromoting_dir_auth_file.close()
print
print 'Chromoting Directory Auth Token:'
print
print chromoting_dir_auth_token
print '...saved in', chromoting_dir_auth_filepath
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
#
# register_host.py registers new hosts in chromoting directory. It
# asks for username/password and then writes these settings to config file.
"""Registers new hosts in chromoting directory.
It asks for username/password and then writes these settings to config file.
"""
import getpass
import os
......@@ -22,67 +23,74 @@ def random_uuid():
return ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x" %
tuple(map(lambda x: random.randrange(0,65536), range(8))))
server = 'www.googleapis.com'
url = 'https://' + server + '/chromoting/v1/@me/hosts'
settings_filepath = os.path.join(os.path.expanduser('~'),
'.ChromotingConfig.json')
print "Email:",
email = raw_input()
password = getpass.getpass("Password: ")
chromoting_auth = gaia_auth.GaiaAuthenticator('chromoting')
auth_token = chromoting_auth.authenticate(email, password)
host_id = random_uuid()
print "HostId:", host_id
host_name = socket.gethostname()
print "HostName:", host_name
print "Generating RSA key pair...",
(private_key, public_key) = keygen.generateRSAKeyPair()
print "Done"
params = ('{"data":{' + \
'"hostId": "%(hostId)s",' + \
'"hostName": "%(hostName)s",' + \
'"publicKey": "%(publicKey)s"}}') % \
{'hostId': host_id, 'hostName': host_name,
'publicKey': public_key}
headers = {"Authorization": "GoogleLogin auth=" + auth_token,
"Content-Type": "application/json" }
request = urllib2.Request(url, params, headers)
opener = urllib2.OpenerDirector()
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
print
print "Registering host with directory service..."
try:
res = urllib2.urlopen(request)
data = res.read()
except urllib2.HTTPError, err:
print >> sys.stderr, "Directory returned error:", err
print >> sys.stderr, err.fp.read()
sys.exit(1)
print "Done"
# Get token that the host will use to athenticate in talk network.
authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
auth_token = authenticator.authenticate(email, password)
# Write settings file.
os.umask(0066) # Set permission mask for created file.
settings_file = open(settings_filepath, 'w')
settings_file.write('{\n');
settings_file.write(' "xmpp_login" : "' + email + '",\n')
settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n')
settings_file.write(' "host_id" : "' + host_id + '",\n')
settings_file.write(' "host_name" : "' + host_name + '",\n')
settings_file.write(' "private_key" : "' + private_key + '",\n')
settings_file.write('}\n')
settings_file.close()
print 'Configuration saved in', settings_filepath
def main():
server = 'www.googleapis.com'
url = 'https://' + server + '/chromoting/v1/@me/hosts'
settings_filepath = os.path.join(os.path.expanduser('~'),
'.ChromotingConfig.json')
print "Email:",
email = raw_input()
password = getpass.getpass("Password: ")
chromoting_auth = gaia_auth.GaiaAuthenticator('chromoting')
auth_token = chromoting_auth.authenticate(email, password)
host_id = random_uuid()
print "HostId:", host_id
host_name = socket.gethostname()
print "HostName:", host_name
print "Generating RSA key pair...",
(private_key, public_key) = keygen.generateRSAKeyPair()
print "Done"
params = ('{"data":{' +
'"hostId": "%(hostId)s",' +
'"hostName": "%(hostName)s",' +
'"publicKey": "%(publicKey)s"}}') %
{'hostId': host_id, 'hostName': host_name,
'publicKey': public_key}
headers = {"Authorization": "GoogleLogin auth=" + auth_token,
"Content-Type": "application/json" }
request = urllib2.Request(url, params, headers)
opener = urllib2.OpenerDirector()
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
print
print "Registering host with directory service..."
try:
res = urllib2.urlopen(request)
data = res.read()
except urllib2.HTTPError, err:
print >> sys.stderr, "Directory returned error:", err
print >> sys.stderr, err.fp.read()
return 1
print "Done"
# Get token that the host will use to athenticate in talk network.
authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
auth_token = authenticator.authenticate(email, password)
# Write settings file.
os.umask(0066) # Set permission mask for created file.
settings_file = open(settings_filepath, 'w')
settings_file.write('{\n');
settings_file.write(' "xmpp_login" : "' + email + '",\n')
settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n')
settings_file.write(' "host_id" : "' + host_id + '",\n')
settings_file.write(' "host_name" : "' + host_name + '",\n')
settings_file.write(' "private_key" : "' + private_key + '",\n')
settings_file.write('}\n')
settings_file.close()
print 'Configuration saved in', settings_filepath
return 0
if __name__ == '__main__':
sys.exit(main())
#!/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.
#
# runclient.py gets the chromoting host info from an input arg and then
# tries to find the authentication info in the .chromotingAuthToken file
# so that the host authentication arguments can be automatically set.
"""Gets the chromoting host info from an input arg and then
tries to find the authentication info in the .chromotingAuthToken file
so that the host authentication arguments can be automatically set.
"""
import os
import platform
auth_filepath = os.path.join(os.path.expanduser('~'), '.chromotingAuthToken')
script_path = os.path.dirname(__file__)
if platform.system() == "Windows":
# TODO(garykac): Make this work on Windows.
print 'Not yet supported on Windows.'
exit(1)
elif platform.system() == "Darwin": # Darwin == MacOSX
client_path = '../../xcodebuild/Debug/chromoting_simple_client'
else:
client_path = '../../out/Debug/chromoting_x11_client'
client_path = os.path.join(script_path, client_path)
# Read username and auth token from token file.
auth = open(auth_filepath)
authinfo = auth.readlines()
username = authinfo[0].rstrip()
authtoken = authinfo[1].rstrip()
# Request final 8 characters of Host JID from user.
# This assumes that the host is published under the same username as the
# client attempting to connect.
print 'Host JID:', username + '/chromoting',
hostjid_suffix = raw_input()
hostjid = username + '/chromoting' + hostjid_suffix.upper()
command = []
command.append(client_path)
command.append('--host_jid ' + hostjid)
command.append('--jid ' + username)
command.append('--token ' + authtoken)
# Launch the client
os.system(' '.join(command))
import sys
def main():
auth_filepath = os.path.join(os.path.expanduser('~'), '.chromotingAuthToken')
script_path = os.path.dirname(__file__)
if platform.system() == "Windows":
# TODO(garykac): Make this work on Windows.
print 'Not yet supported on Windows.'
return 1
elif platform.system() == "Darwin": # Darwin == MacOSX
client_path = '../../xcodebuild/Debug/chromoting_simple_client'
else:
client_path = '../../out/Debug/chromoting_x11_client'
client_path = os.path.join(script_path, client_path)
# Read username and auth token from token file.
auth = open(auth_filepath)
authinfo = auth.readlines()
username = authinfo[0].rstrip()
authtoken = authinfo[1].rstrip()
# Request final 8 characters of Host JID from user.
# This assumes that the host is published under the same username as the
# client attempting to connect.
print 'Host JID:', username + '/chromoting',
hostjid_suffix = raw_input()
hostjid = username + '/chromoting' + hostjid_suffix.upper()
command = []
command.append(client_path)
command.append('--host_jid ' + hostjid)
command.append('--jid ' + username)
command.append('--token ' + authtoken)
# Launch the client
os.system(' '.join(command))
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.
......@@ -183,7 +183,7 @@ def main():
print ('Usage: build-webapp.py '
'<build-type> <mime-type> <dst> <zip-path> <plugin> '
'<other files...> --locales <locales...>')
sys.exit(1)
return 1
reading_locales = False
files = []
......@@ -198,7 +198,8 @@ def main():
buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5],
files, locales)
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.
"""Verifies that the message tags in the 2nd and subsequent JSON message files
match those specified in the first. This is typically run when the
translations are updated before a release, to check that nothing got missed.
match those specified in the first.
This is typically run when the translations are updated before a release, to
check that nothing got missed.
"""
import json
......@@ -31,10 +33,11 @@ def CheckTranslation(filename, translation, messages):
return False
def main():
if len(sys.argv) < 3:
print 'Usage: verify-translations.py <messages> <translation-files...>'
sys.exit(1)
return 1
en_messages = json.load(open(sys.argv[1], 'r'))
exit_code = 0
......@@ -43,7 +46,8 @@ def main():
if not CheckTranslation(f, translation, en_messages):
exit_code = 1
sys.exit(exit_code)
return exit_code
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.
......@@ -78,7 +78,7 @@ def CheckFileForUnknownTag(filename, messages):
def main():
if len(sys.argv) < 4:
print 'Usage: verify-webapp.py <touch> <messages> <message_users...>'
sys.exit(1)
return 1
touch_file = sys.argv[1]
messages = json.load(open(sys.argv[2], 'r'))
......@@ -101,8 +101,8 @@ def main():
f.close()
os.utime(touch_file, None)
sys.exit(exit_code)
return exit_code
if __name__ == '__main__':
main()
sys.exit(main())
#!/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.
import string
import sys
HEADER = """\
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
......@@ -447,6 +448,8 @@ def main():
for args in xrange(0, 6 + 1):
GenerateCreateFunctor(prebound, args)
print FOOTER
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.
......@@ -482,6 +481,7 @@ FUNCTION_SETS = [
'../../../third_party/mesa/MesaLib/include/GL/glxext.h']],
]
def GenerateHeader(file, functions, set_name, used_extension_functions):
"""Generates gl_binding_autogen_x.h"""
......@@ -754,6 +754,7 @@ def GenerateMockSource(file, functions):
file.write('\n')
file.write('} // namespace gfx\n')
def ParseExtensionFunctionsFromHeader(header_file):
"""Parse a C extension header file and return a map from extension names to
a list of functions.
......@@ -790,6 +791,7 @@ def ParseExtensionFunctionsFromHeader(header_file):
extensions[current_extension].append(match.group(1))
return extensions
def GetExtensionFunctions(extension_headers):
"""Parse extension functions from a list of header files.
......@@ -803,6 +805,7 @@ def GetExtensionFunctions(extension_headers):
extensions.update(ParseExtensionFunctionsFromHeader(open(header)))
return extensions
def GetFunctionToExtensionMap(extensions):
"""Construct map from a function names to extensions which define the
function.
......@@ -820,12 +823,14 @@ def GetFunctionToExtensionMap(extensions):
function_to_extension[function] = extension
return function_to_extension
def LooksLikeExtensionFunction(function):
"""Heuristic to see if a function name is consistent with extension function
naming."""
vendor = re.match(r'\w+?([A-Z][A-Z]+)$', function)
return vendor is not None and not vendor.group(1) in ['GL', 'API', 'DC']
def GetUsedExtensionFunctions(functions, extension_headers):
"""Determine which functions belong to extensions.
......@@ -863,6 +868,7 @@ def GetUsedExtensionFunctions(functions, extension_headers):
key = lambda item: ExtensionSortKey(item[0]))
return used_extension_functions
def main(argv):
"""This is the main function."""
......@@ -888,7 +894,8 @@ def main(argv):
source_file = open(os.path.join(dir, 'gl_bindings_autogen_mock.cc'), 'wb')
GenerateMockSource(source_file, GL_FUNCTIONS)
source_file.close()
return 0
if __name__ == '__main__':
main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
#!/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.
......
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