OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 import getpass | 7 import getpass |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 import tempfile | 12 import tempfile |
13 import urllib | 13 import urllib |
14 | 14 |
15 | 15 |
16 def Authenticate(): | 16 def Authenticate(): |
17 # Authenticate. | 17 # Authenticate. |
18 default_username = os.environ.get('LOGNAME', '') | 18 default_username = os.environ.get('LOGNAME', '') |
19 username = os.environ.get('GSDCURL_USERNAME') | 19 username = os.environ.get('GSDCURL_USERNAME') |
20 if username is None: | 20 if username is None: |
21 sys.stderr.write('Username [' + default_username + ']: ') | 21 sys.stderr.write('Username [' + default_username + ']: ') |
22 username = raw_input() | 22 username = raw_input() |
23 if username == '': | 23 if username == '': |
24 username = default_username + '@google.com' | 24 username = default_username + '@google.com' |
25 elif '@' not in username: | 25 elif '@' not in username: |
26 username = username + '@google.com' | 26 username = username + '@google.com' |
27 passwd = os.environ.get('GSDCURL_PASSWORD') | 27 passwd = os.environ.get('GSDCURL_PASSWORD') |
28 if passwd is None: | 28 if passwd is None: |
29 sys.stderr.write('Password: ') | 29 sys.stderr.write('Password: ') |
30 passwd = urllib.quote_plus(getpass.getpass(prompt='')) | 30 passwd = getpass.getpass(prompt='') |
31 cmd = [ | 31 cmd = [ |
32 'curl', '--silent', 'https://www.google.com/accounts/ClientLogin', | 32 'curl', '--silent', 'https://www.google.com/accounts/ClientLogin', |
33 '-d', 'Email=' + username, | 33 '-d', 'Email=' + username, |
34 '-d', 'Passwd=' + passwd, | 34 '-d', 'Passwd=' + urllib.quote_plus(passwd), |
35 '-d', 'accountType=GOOGLE', | 35 '-d', 'accountType=GOOGLE', |
36 '-d', 'source=Google-gsdcurl-ver1', | 36 '-d', 'source=Google-gsdcurl-ver1', |
37 '-d', 'service=cds', | 37 '-d', 'service=cds', |
38 ] | 38 ] |
39 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 39 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
40 (p_stdout, _) = p.communicate() | 40 (p_stdout, _) = p.communicate() |
41 assert p.returncode == 0 | 41 assert p.returncode == 0 |
42 m = re.search('\nAuth=([^\n]+)\n', p_stdout) | 42 m = re.search('\nAuth=([^\n]+)\n', p_stdout) |
43 if not m: | 43 if not m: |
44 sys.stderr.write('BAD LOGIN\n') | 44 sys.stderr.write('BAD LOGIN\n') |
(...skipping 16 matching lines...) Expand all Loading... |
61 os.remove(cookies) | 61 os.remove(cookies) |
62 | 62 |
63 | 63 |
64 def main(argv): | 64 def main(argv): |
65 auth = Authenticate() | 65 auth = Authenticate() |
66 return DoCurl(auth, argv) | 66 return DoCurl(auth, argv) |
67 | 67 |
68 | 68 |
69 if __name__ == '__main__': | 69 if __name__ == '__main__': |
70 sys.exit(main(sys.argv)) | 70 sys.exit(main(sys.argv)) |
OLD | NEW |