OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium 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 """Applies an issue from Rietveld. | 6 """Applies an issue from Rietveld. |
7 """ | 7 """ |
8 | 8 |
9 import getpass | 9 import getpass |
10 import logging | 10 import logging |
(...skipping 17 matching lines...) Expand all Loading... |
28 def main(): | 28 def main(): |
29 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 29 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
30 parser.add_option( | 30 parser.add_option( |
31 '-v', '--verbose', action='count', default=0, | 31 '-v', '--verbose', action='count', default=0, |
32 help='Prints debugging infos') | 32 help='Prints debugging infos') |
33 parser.add_option( | 33 parser.add_option( |
34 '-e', '--email', default='', | 34 '-e', '--email', default='', |
35 help='Email address to access rietveld. If not specified, anonymous ' | 35 help='Email address to access rietveld. If not specified, anonymous ' |
36 'access will be used.') | 36 'access will be used.') |
37 parser.add_option( | 37 parser.add_option( |
38 '-w', '--password', default=None, help='Password for email addressed.') | 38 '-w', '--password', default=None, |
| 39 help='Password for email addressed. Use - to read password from stdin.') |
39 parser.add_option( | 40 parser.add_option( |
40 '-i', '--issue', type='int', help='Rietveld issue number') | 41 '-i', '--issue', type='int', help='Rietveld issue number') |
41 parser.add_option( | 42 parser.add_option( |
42 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') | 43 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') |
43 parser.add_option( | 44 parser.add_option( |
44 '-r', | 45 '-r', |
45 '--root_dir', | 46 '--root_dir', |
46 default=os.getcwd(), | 47 default=os.getcwd(), |
47 help='Root directory to apply the patch') | 48 help='Root directory to apply the patch') |
48 parser.add_option( | 49 parser.add_option( |
49 '-s', | 50 '-s', |
50 '--server', | 51 '--server', |
51 default='http://codereview.chromium.org', | 52 default='http://codereview.chromium.org', |
52 help='Rietveld server') | 53 help='Rietveld server') |
53 options, args = parser.parse_args() | 54 options, args = parser.parse_args() |
54 logging.basicConfig( | 55 logging.basicConfig( |
55 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', | 56 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
56 level=[logging.WARNING, logging.INFO, logging.DEBUG][ | 57 level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
57 min(2, options.verbose)]) | 58 min(2, options.verbose)]) |
58 if args: | 59 if args: |
59 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 60 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
60 if not options.issue: | 61 if not options.issue: |
61 parser.error('Require --issue') | 62 parser.error('Require --issue') |
62 options.server = options.server.rstrip('/') | 63 options.server = options.server.rstrip('/') |
63 if not options.server: | 64 if not options.server: |
64 parser.error('Require a valid server') | 65 parser.error('Require a valid server') |
65 | 66 |
| 67 if options.password == '-': |
| 68 options.password = sys.stdin.readline().strip() |
| 69 |
66 obj = rietveld.Rietveld(options.server, options.email, options.password) | 70 obj = rietveld.Rietveld(options.server, options.email, options.password) |
67 try: | 71 try: |
68 properties = obj.get_issue_properties(options.issue, False) | 72 properties = obj.get_issue_properties(options.issue, False) |
69 except rietveld.upload.ClientLoginError, e: | 73 except rietveld.upload.ClientLoginError, e: |
70 if sys.stdout.closed: | 74 if sys.stdout.closed: |
71 print >> sys.stderr, 'Accessing the issue requires login.' | 75 print >> sys.stderr, 'Accessing the issue requires login.' |
72 return 1 | 76 return 1 |
73 print('Accessing the issue requires login.') | 77 print('Accessing the issue requires login.') |
74 obj = rietveld.Rietveld(options.server, None, None) | 78 obj = rietveld.Rietveld(options.server, None, None) |
75 properties = obj.get_issue_properties(options.issue, False) | 79 properties = obj.get_issue_properties(options.issue, False) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 if sys.platform == 'win32': | 131 if sys.platform == 'win32': |
128 gclient_path += '.bat' | 132 gclient_path += '.bat' |
129 return subprocess.call( | 133 return subprocess.call( |
130 [gclient_path, 'sync', '--revision', base_rev], cwd=gclient_root) | 134 [gclient_path, 'sync', '--revision', base_rev], cwd=gclient_root) |
131 return 0 | 135 return 0 |
132 | 136 |
133 | 137 |
134 if __name__ == "__main__": | 138 if __name__ == "__main__": |
135 fix_encoding.fix_encoding() | 139 fix_encoding.fix_encoding() |
136 sys.exit(main()) | 140 sys.exit(main()) |
OLD | NEW |