diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 22:22:20 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 22:22:20 +0000 |
commit | aa539ba4c9dc3e99a4e55f21a10fb79b9402637c (patch) | |
tree | 9cc8977263c4a73e65c7a52f96447bff83531265 /remoting/tools | |
parent | e51bdf3d4f7bb89497344af0b4a99ff10512c0d5 (diff) | |
download | chromium_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/tools')
-rwxr-xr-x | remoting/tools/gettoken.py | 104 | ||||
-rwxr-xr-x | remoting/tools/register_host.py | 146 | ||||
-rwxr-xr-x | remoting/tools/runclient.py | 93 |
3 files changed, 183 insertions, 160 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()) |