summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 22:22:20 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-23 22:22:20 +0000
commitaa539ba4c9dc3e99a4e55f21a10fb79b9402637c (patch)
tree9cc8977263c4a73e65c7a52f96447bff83531265 /remoting
parente51bdf3d4f7bb89497344af0b4a99ff10512c0d5 (diff)
downloadchromium_src-aa539ba4c9dc3e99a4e55f21a10fb79b9402637c.zip
chromium_src-aa539ba4c9dc3e99a4e55f21a10fb79b9402637c.tar.gz
chromium_src-aa539ba4c9dc3e99a4e55f21a10fb79b9402637c.tar.bz2
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
Diffstat (limited to 'remoting')
-rwxr-xr-xremoting/tools/gettoken.py104
-rwxr-xr-xremoting/tools/register_host.py146
-rwxr-xr-xremoting/tools/runclient.py93
-rwxr-xr-x[-rw-r--r--]remoting/webapp/build-webapp.py7
-rwxr-xr-xremoting/webapp/verify-translations.py16
-rwxr-xr-xremoting/webapp/verify-webapp.py8
6 files changed, 201 insertions, 173 deletions
diff --git a/remoting/tools/gettoken.py b/remoting/tools/gettoken.py
index a36408b..4f867bf 100755
--- a/remoting/tools/gettoken.py
+++ b/remoting/tools/gettoken.py
@@ -1,11 +1,12 @@
#!/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())
diff --git a/remoting/tools/register_host.py b/remoting/tools/register_host.py
index ffdb955..6530d0e 100755
--- a/remoting/tools/register_host.py
+++ b/remoting/tools/register_host.py
@@ -1,11 +1,12 @@
#!/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())
diff --git a/remoting/tools/runclient.py b/remoting/tools/runclient.py
index 12a4c5f..76e1af2 100755
--- a/remoting/tools/runclient.py
+++ b/remoting/tools/runclient.py
@@ -1,49 +1,56 @@
#!/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())
diff --git a/remoting/webapp/build-webapp.py b/remoting/webapp/build-webapp.py
index c73835a..14b8a6d 100644..100755
--- a/remoting/webapp/build-webapp.py
+++ b/remoting/webapp/build-webapp.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.
@@ -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())
diff --git a/remoting/webapp/verify-translations.py b/remoting/webapp/verify-translations.py
index 65b253b..c6ffe3a 100755
--- a/remoting/webapp/verify-translations.py
+++ b/remoting/webapp/verify-translations.py
@@ -1,11 +1,13 @@
-#!/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())
diff --git a/remoting/webapp/verify-webapp.py b/remoting/webapp/verify-webapp.py
index 1f0cc4f..038de01 100755
--- a/remoting/webapp/verify-webapp.py
+++ b/remoting/webapp/verify-webapp.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.
@@ -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())