OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 |
11 import getpass | 11 import getpass |
12 import os | 12 import os |
13 import random | 13 import random |
14 import re | 14 import re |
15 import string | 15 import string |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 import tempfile | 18 import tempfile |
19 import time | 19 import time |
20 from third_party import upload | 20 from third_party import upload |
21 import urllib2 | 21 import urllib2 |
22 | 22 |
23 __pychecker__ = 'unusednames=breakpad' | |
24 import breakpad | 23 import breakpad |
25 __pychecker__ = '' | |
26 | 24 |
27 # gcl now depends on gclient. | 25 # gcl now depends on gclient. |
28 from scm import SVN | 26 from scm import SVN |
29 import gclient_utils | 27 import gclient_utils |
30 | 28 |
31 __version__ = '1.2' | 29 __version__ = '1.2' |
32 | 30 |
33 | 31 |
34 CODEREVIEW_SETTINGS = { | 32 CODEREVIEW_SETTINGS = { |
35 # To make gcl send reviews to a server, check in a file named | 33 # To make gcl send reviews to a server, check in a file named |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 660 |
663 def defer_attributes(a, b): | 661 def defer_attributes(a, b): |
664 """Copy attributes from an object (like a function) to another.""" | 662 """Copy attributes from an object (like a function) to another.""" |
665 for x in dir(a): | 663 for x in dir(a): |
666 if not getattr(b, x, None): | 664 if not getattr(b, x, None): |
667 setattr(b, x, getattr(a, x)) | 665 setattr(b, x, getattr(a, x)) |
668 | 666 |
669 | 667 |
670 def need_change(function): | 668 def need_change(function): |
671 """Converts args -> change_info.""" | 669 """Converts args -> change_info.""" |
| 670 # pylint: disable=W0612,W0621 |
672 def hook(args): | 671 def hook(args): |
673 if not len(args) == 1: | 672 if not len(args) == 1: |
674 ErrorExit("You need to pass a change list name") | 673 ErrorExit("You need to pass a change list name") |
675 change_info = ChangeInfo.Load(args[0], GetRepositoryRoot(), True, True) | 674 change_info = ChangeInfo.Load(args[0], GetRepositoryRoot(), True, True) |
676 return function(change_info) | 675 return function(change_info) |
677 defer_attributes(function, hook) | 676 defer_attributes(function, hook) |
678 hook.need_change = True | 677 hook.need_change = True |
679 hook.no_args = True | 678 hook.no_args = True |
680 return hook | 679 return hook |
681 | 680 |
682 | 681 |
683 def need_change_and_args(function): | 682 def need_change_and_args(function): |
684 """Converts args -> change_info.""" | 683 """Converts args -> change_info.""" |
| 684 # pylint: disable=W0612,W0621 |
685 def hook(args): | 685 def hook(args): |
686 if not args: | 686 if not args: |
687 ErrorExit("You need to pass a change list name") | 687 ErrorExit("You need to pass a change list name") |
688 change_info = ChangeInfo.Load(args.pop(0), GetRepositoryRoot(), True, True) | 688 change_info = ChangeInfo.Load(args.pop(0), GetRepositoryRoot(), True, True) |
689 return function(change_info, args) | 689 return function(change_info, args) |
690 defer_attributes(function, hook) | 690 defer_attributes(function, hook) |
691 hook.need_change = True | 691 hook.need_change = True |
692 return hook | 692 return hook |
693 | 693 |
694 | 694 |
695 def no_args(function): | 695 def no_args(function): |
696 """Make sure no args are passed.""" | 696 """Make sure no args are passed.""" |
| 697 # pylint: disable=W0612,W0621 |
697 def hook(args): | 698 def hook(args): |
698 if args: | 699 if args: |
699 ErrorExit("Doesn't support arguments") | 700 ErrorExit("Doesn't support arguments") |
700 return function() | 701 return function() |
701 defer_attributes(function, hook) | 702 defer_attributes(function, hook) |
702 hook.no_args = True | 703 hook.no_args = True |
703 return hook | 704 return hook |
704 | 705 |
705 | 706 |
706 def attrs(**kwargs): | 707 def attrs(**kwargs): |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 new_cl_files = [] | 1035 new_cl_files = [] |
1035 for line in cl_files_text.splitlines(): | 1036 for line in cl_files_text.splitlines(): |
1036 if not len(line): | 1037 if not len(line): |
1037 continue | 1038 continue |
1038 if line.startswith("---"): | 1039 if line.startswith("---"): |
1039 break | 1040 break |
1040 status = line[:7] | 1041 status = line[:7] |
1041 filename = line[7:] | 1042 filename = line[7:] |
1042 new_cl_files.append((status, filename)) | 1043 new_cl_files.append((status, filename)) |
1043 | 1044 |
1044 if (not len(change_info._files)) and (not change_info.issue) and \ | 1045 if (not len(change_info.GetFiles()) and not change_info.issue and |
1045 (not len(new_description) and (not new_cl_files)): | 1046 not len(new_description) and not new_cl_files): |
1046 ErrorExit("Empty changelist not saved") | 1047 ErrorExit("Empty changelist not saved") |
1047 | 1048 |
1048 change_info._files = new_cl_files | 1049 change_info._files = new_cl_files |
1049 change_info.Save() | 1050 change_info.Save() |
1050 if svn_info.get('URL', '').startswith('http:'): | 1051 if svn_info.get('URL', '').startswith('http:'): |
1051 Warn("WARNING: Creating CL in a read-only checkout. You will not be " | 1052 Warn("WARNING: Creating CL in a read-only checkout. You will not be " |
1052 "able to commit it!") | 1053 "able to commit it!") |
1053 | 1054 |
1054 print change_info.name + " changelist saved." | 1055 print change_info.name + " changelist saved." |
1055 if change_info.MissingTests(): | 1056 if change_info.MissingTests(): |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 print "".join(filename) | 1137 print "".join(filename) |
1137 return 0 | 1138 return 0 |
1138 | 1139 |
1139 | 1140 |
1140 @no_args | 1141 @no_args |
1141 def CMDdeleteempties(): | 1142 def CMDdeleteempties(): |
1142 """Delete all changelists that have no files.""" | 1143 """Delete all changelists that have no files.""" |
1143 print "\n--- Deleting:" | 1144 print "\n--- Deleting:" |
1144 for cl in GetCLs(): | 1145 for cl in GetCLs(): |
1145 change_info = ChangeInfo.Load(cl, GetRepositoryRoot(), True, True) | 1146 change_info = ChangeInfo.Load(cl, GetRepositoryRoot(), True, True) |
1146 if not len(change_info._files): | 1147 if not len(change_info.GetFiles()): |
1147 print change_info.name | 1148 print change_info.name |
1148 change_info.Delete() | 1149 change_info.Delete() |
1149 return 0 | 1150 return 0 |
1150 | 1151 |
1151 | 1152 |
1152 @no_args | 1153 @no_args |
1153 def CMDnothave(): | 1154 def CMDnothave(): |
1154 """Lists files unknown to Subversion.""" | 1155 """Lists files unknown to Subversion.""" |
1155 for filename in UnknownFiles(): | 1156 for filename in UnknownFiles(): |
1156 print "? " + "".join(filename) | 1157 print "? " + "".join(filename) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 return getattr(sys.modules[__name__], 'CMD' + name, None) | 1258 return getattr(sys.modules[__name__], 'CMD' + name, None) |
1258 | 1259 |
1259 | 1260 |
1260 def GenUsage(command): | 1261 def GenUsage(command): |
1261 """Modify an OptParse object with the function's documentation.""" | 1262 """Modify an OptParse object with the function's documentation.""" |
1262 obj = Command(command) | 1263 obj = Command(command) |
1263 display = command | 1264 display = command |
1264 more = getattr(obj, 'usage', '') | 1265 more = getattr(obj, 'usage', '') |
1265 if command == 'help': | 1266 if command == 'help': |
1266 display = '<command>' | 1267 display = '<command>' |
1267 need_change = '' | 1268 need_change_val = '' |
1268 if getattr(obj, 'need_change', None): | 1269 if getattr(obj, 'need_change', None): |
1269 need_change = ' <change_list>' | 1270 need_change_val = ' <change_list>' |
1270 options = ' [options]' | 1271 options = ' [options]' |
1271 if getattr(obj, 'no_args', None): | 1272 if getattr(obj, 'no_args', None): |
1272 options = '' | 1273 options = '' |
1273 res = 'Usage: gcl %s%s%s %s\n\n' % (display, need_change, options, more) | 1274 res = 'Usage: gcl %s%s%s %s\n\n' % (display, need_change_val, options, more) |
1274 res += re.sub('\n ', '\n', obj.__doc__) | 1275 res += re.sub('\n ', '\n', obj.__doc__) |
1275 return res | 1276 return res |
1276 | 1277 |
1277 | 1278 |
1278 def CMDhelp(args): | 1279 def CMDhelp(args): |
1279 """Prints this help or help for the given command.""" | 1280 """Prints this help or help for the given command.""" |
1280 if args and 'CMD' + args[0] in dir(sys.modules[__name__]): | 1281 if args and 'CMD' + args[0] in dir(sys.modules[__name__]): |
1281 print GenUsage(args[0]) | 1282 print GenUsage(args[0]) |
1282 | 1283 |
1283 # These commands defer to external tools so give this info too. | 1284 # These commands defer to external tools so give this info too. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 if e.code != 500: | 1337 if e.code != 500: |
1337 raise | 1338 raise |
1338 print >> sys.stderr, ( | 1339 print >> sys.stderr, ( |
1339 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1340 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1340 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1341 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1341 return 1 | 1342 return 1 |
1342 | 1343 |
1343 | 1344 |
1344 if __name__ == "__main__": | 1345 if __name__ == "__main__": |
1345 sys.exit(main(sys.argv[1:])) | 1346 sys.exit(main(sys.argv[1:])) |
OLD | NEW |