Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: remoting/tools/register_host.py

Issue 8665013: Fix many* python scripts in src/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed chrome_frame/tools/test/page_cycler/cf_cycler.py Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/tools/gettoken.py ('k') | remoting/tools/runclient.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/tools/register_host.py
diff --git a/remoting/tools/register_host.py b/remoting/tools/register_host.py
index ffdb955df6f0a5f2334758ee793f37b2544ea340..6530d0e90b338b8474796680ec910e80d8494ecd 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())
« no previous file with comments | « remoting/tools/gettoken.py ('k') | remoting/tools/runclient.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698