OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """\ | 6 """\ |
7 Wrapper script around Rietveld's upload.py that simplifies working with groups | 7 Wrapper script around Rietveld's upload.py that simplifies working with groups |
8 of files. | 8 of files. |
9 """ | 9 """ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 import simplejson as json # pylint: disable=F0401 | 32 import simplejson as json # pylint: disable=F0401 |
33 | 33 |
34 import breakpad # pylint: disable=W0611 | 34 import breakpad # pylint: disable=W0611 |
35 | 35 |
36 # gcl now depends on gclient. | 36 # gcl now depends on gclient. |
37 from scm import SVN | 37 from scm import SVN |
38 | 38 |
39 import fix_encoding | 39 import fix_encoding |
40 import gclient_utils | 40 import gclient_utils |
41 import presubmit_support | 41 import presubmit_support |
| 42 import subprocess2 |
42 | 43 |
43 __version__ = '1.2' | 44 __version__ = '1.2' |
44 | 45 |
45 | 46 |
46 CODEREVIEW_SETTINGS = { | 47 CODEREVIEW_SETTINGS = { |
47 # To make gcl send reviews to a server, check in a file named | 48 # To make gcl send reviews to a server, check in a file named |
48 # "codereview.settings" (see |CODEREVIEW_SETTINGS_FILE| below) to your | 49 # "codereview.settings" (see |CODEREVIEW_SETTINGS_FILE| below) to your |
49 # project's base directory and add the following line to codereview.settings: | 50 # project's base directory and add the following line to codereview.settings: |
50 # CODE_REVIEW_SERVER: codereview.yourserver.org | 51 # CODE_REVIEW_SERVER: codereview.yourserver.org |
51 } | 52 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 130 |
130 Note: The cache will be inconsistent if the same file is retrieved with both | 131 Note: The cache will be inconsistent if the same file is retrieved with both |
131 use_root=True and use_root=False. Don't be stupid. | 132 use_root=True and use_root=False. Don't be stupid. |
132 """ | 133 """ |
133 if filename not in FILES_CACHE: | 134 if filename not in FILES_CACHE: |
134 # Don't try to look up twice. | 135 # Don't try to look up twice. |
135 FILES_CACHE[filename] = None | 136 FILES_CACHE[filename] = None |
136 # First we check if we have a cached version. | 137 # First we check if we have a cached version. |
137 try: | 138 try: |
138 cached_file = os.path.join(GetCacheDir(), filename) | 139 cached_file = os.path.join(GetCacheDir(), filename) |
139 except gclient_utils.Error: | 140 except (gclient_utils.Error, subprocess2.CalledProcessError): |
140 return None | 141 return None |
141 if (not os.path.exists(cached_file) or | 142 if (not os.path.exists(cached_file) or |
142 (time.time() - os.stat(cached_file).st_mtime) > max_age): | 143 (time.time() - os.stat(cached_file).st_mtime) > max_age): |
143 dir_info = SVN.CaptureInfo('.') | 144 dir_info = SVN.CaptureInfo('.') |
144 repo_root = dir_info['Repository Root'] | 145 repo_root = dir_info['Repository Root'] |
145 if use_root: | 146 if use_root: |
146 url_path = repo_root | 147 url_path = repo_root |
147 else: | 148 else: |
148 url_path = dir_info['URL'] | 149 url_path = dir_info['URL'] |
149 while True: | 150 while True: |
(...skipping 11 matching lines...) Expand all Loading... |
161 # MacOSX 10.5.2 has a bug with svn 1.4.4 that will trigger the | 162 # MacOSX 10.5.2 has a bug with svn 1.4.4 that will trigger the |
162 # 'Can\'t get username or password' and can be fixed easily. | 163 # 'Can\'t get username or password' and can be fixed easily. |
163 # The fix doesn't work if the user upgraded to svn 1.6.x. Bleh. | 164 # The fix doesn't work if the user upgraded to svn 1.6.x. Bleh. |
164 # I don't have time to fix their broken stuff. | 165 # I don't have time to fix their broken stuff. |
165 args.append('--non-interactive') | 166 args.append('--non-interactive') |
166 gclient_utils.CheckCallAndFilter( | 167 gclient_utils.CheckCallAndFilter( |
167 args, cwd='.', filter_fn=content_array.append) | 168 args, cwd='.', filter_fn=content_array.append) |
168 # Exit the loop if the file was found. Override content. | 169 # Exit the loop if the file was found. Override content. |
169 content = '\n'.join(content_array) | 170 content = '\n'.join(content_array) |
170 break | 171 break |
171 except gclient_utils.Error: | 172 except (gclient_utils.Error, subprocess2.CalledProcessError): |
172 if content_array[0].startswith( | 173 if content_array[0].startswith( |
173 'svn: Can\'t get username or password'): | 174 'svn: Can\'t get username or password'): |
174 ErrorExit('Your svn credentials expired. Please run svn update ' | 175 ErrorExit('Your svn credentials expired. Please run svn update ' |
175 'to fix the cached credentials') | 176 'to fix the cached credentials') |
176 if content_array[0].startswith('svn: Can\'t get password'): | 177 if content_array[0].startswith('svn: Can\'t get password'): |
177 ErrorExit('If are using a Mac and svn --version shows 1.4.x, ' | 178 ErrorExit('If are using a Mac and svn --version shows 1.4.x, ' |
178 'please hack gcl.py to remove --non-interactive usage, it\'s' | 179 'please hack gcl.py to remove --non-interactive usage, it\'s' |
179 'a bug on your installed copy') | 180 'a bug on your installed copy') |
180 if (content_array[0].startswith('svn: File not found:') or | 181 if (content_array[0].startswith('svn: File not found:') or |
181 content_array[0].endswith('path not found')): | 182 content_array[0].endswith('path not found')): |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 '\nYour python version is unsupported, please upgrade.\n') | 1413 '\nYour python version is unsupported, please upgrade.\n') |
1413 if not argv: | 1414 if not argv: |
1414 argv = ['help'] | 1415 argv = ['help'] |
1415 command = Command(argv[0]) | 1416 command = Command(argv[0]) |
1416 # Help can be run from anywhere. | 1417 # Help can be run from anywhere. |
1417 if command == CMDhelp: | 1418 if command == CMDhelp: |
1418 return command(argv[1:]) | 1419 return command(argv[1:]) |
1419 | 1420 |
1420 try: | 1421 try: |
1421 GetRepositoryRoot() | 1422 GetRepositoryRoot() |
1422 except gclient_utils.Error: | 1423 except (gclient_utils.Error, subprocess2.CalledProcessError): |
1423 print >> sys.stderr, 'To use gcl, you need to be in a subversion checkout.' | 1424 print >> sys.stderr, 'To use gcl, you need to be in a subversion checkout.' |
1424 return 1 | 1425 return 1 |
1425 | 1426 |
1426 # Create the directories where we store information about changelists if it | 1427 # Create the directories where we store information about changelists if it |
1427 # doesn't exist. | 1428 # doesn't exist. |
1428 try: | 1429 try: |
1429 if not os.path.exists(GetInfoDir()): | 1430 if not os.path.exists(GetInfoDir()): |
1430 os.mkdir(GetInfoDir()) | 1431 os.mkdir(GetInfoDir()) |
1431 if not os.path.exists(GetChangesDir()): | 1432 if not os.path.exists(GetChangesDir()): |
1432 os.mkdir(GetChangesDir()) | 1433 os.mkdir(GetChangesDir()) |
1433 if not os.path.exists(GetCacheDir()): | 1434 if not os.path.exists(GetCacheDir()): |
1434 os.mkdir(GetCacheDir()) | 1435 os.mkdir(GetCacheDir()) |
1435 | 1436 |
1436 if command: | 1437 if command: |
1437 return command(argv[1:]) | 1438 return command(argv[1:]) |
1438 # Unknown command, try to pass that to svn | 1439 # Unknown command, try to pass that to svn |
1439 return CMDpassthru(argv) | 1440 return CMDpassthru(argv) |
1440 except gclient_utils.Error, e: | 1441 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1441 print >> sys.stderr, 'Got an exception' | 1442 print >> sys.stderr, 'Got an exception' |
1442 print >> sys.stderr, str(e) | 1443 print >> sys.stderr, str(e) |
1443 return 1 | 1444 return 1 |
1444 except upload.ClientLoginError, e: | 1445 except upload.ClientLoginError, e: |
1445 print >> sys.stderr, 'Got an exception logging in to Rietveld' | 1446 print >> sys.stderr, 'Got an exception logging in to Rietveld' |
1446 print >> sys.stderr, str(e) | 1447 print >> sys.stderr, str(e) |
1447 except urllib2.HTTPError, e: | 1448 except urllib2.HTTPError, e: |
1448 if e.code != 500: | 1449 if e.code != 500: |
1449 raise | 1450 raise |
1450 print >> sys.stderr, ( | 1451 print >> sys.stderr, ( |
1451 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1452 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1452 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1453 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1453 return 1 | 1454 return 1 |
1454 | 1455 |
1455 | 1456 |
1456 if __name__ == "__main__": | 1457 if __name__ == "__main__": |
1457 fix_encoding.fix_encoding() | 1458 fix_encoding.fix_encoding() |
1458 sys.exit(main(sys.argv[1:])) | 1459 sys.exit(main(sys.argv[1:])) |
OLD | NEW |