summaryrefslogtreecommitdiffstats
path: root/subcmds/upload.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/upload.py')
-rw-r--r--subcmds/upload.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 84a5e440..e314032a 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -13,6 +13,7 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16from __future__ import print_function
16import copy 17import copy
17import re 18import re
18import sys 19import sys
@@ -26,16 +27,18 @@ UNUSUAL_COMMIT_THRESHOLD = 5
26 27
27def _ConfirmManyUploads(multiple_branches=False): 28def _ConfirmManyUploads(multiple_branches=False):
28 if multiple_branches: 29 if multiple_branches:
29 print "ATTENTION: One or more branches has an unusually high number of commits." 30 print('ATTENTION: One or more branches has an unusually high number'
31 'of commits.')
30 else: 32 else:
31 print "ATTENTION: You are uploading an unusually high number of commits." 33 print('ATTENTION: You are uploading an unusually high number of commits.')
32 print "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across branches?)" 34 print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across'
35 'branches?)')
33 answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip() 36 answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip()
34 return answer == "yes" 37 return answer == "yes"
35 38
36def _die(fmt, *args): 39def _die(fmt, *args):
37 msg = fmt % args 40 msg = fmt % args
38 print >>sys.stderr, 'error: %s' % msg 41 print('error: %s' % msg, file=sys.stderr)
39 sys.exit(1) 42 sys.exit(1)
40 43
41def _SplitEmails(values): 44def _SplitEmails(values):
@@ -47,7 +50,7 @@ def _SplitEmails(values):
47class Upload(InteractiveCommand): 50class Upload(InteractiveCommand):
48 common = True 51 common = True
49 helpSummary = "Upload changes for code review" 52 helpSummary = "Upload changes for code review"
50 helpUsage=""" 53 helpUsage = """
51%prog [--re --cc] [<project>]... 54%prog [--re --cc] [<project>]...
52""" 55"""
53 helpDescription = """ 56 helpDescription = """
@@ -176,18 +179,18 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
176 date = branch.date 179 date = branch.date
177 commit_list = branch.commits 180 commit_list = branch.commits
178 181
179 print 'Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr) 182 print('Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr))
180 print ' branch %s (%2d commit%s, %s):' % ( 183 print(' branch %s (%2d commit%s, %s):' % (
181 name, 184 name,
182 len(commit_list), 185 len(commit_list),
183 len(commit_list) != 1 and 's' or '', 186 len(commit_list) != 1 and 's' or '',
184 date) 187 date))
185 for commit in commit_list: 188 for commit in commit_list:
186 print ' %s' % commit 189 print(' %s' % commit)
187 190
188 sys.stdout.write('to %s (y/N)? ' % remote.review) 191 sys.stdout.write('to %s (y/N)? ' % remote.review)
189 answer = sys.stdin.readline().strip() 192 answer = sys.stdin.readline().strip().lower()
190 answer = answer in ('y', 'Y', 'yes', '1', 'true', 't') 193 answer = answer in ('y', 'yes', '1', 'true', 't')
191 194
192 if answer: 195 if answer:
193 if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD: 196 if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
@@ -297,7 +300,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
297 try: 300 try:
298 # refs/changes/XYZ/N --> XYZ 301 # refs/changes/XYZ/N --> XYZ
299 return refs.get(last_pub).split('/')[-2] 302 return refs.get(last_pub).split('/')[-2]
300 except: 303 except (AttributeError, IndexError):
301 return "" 304 return ""
302 305
303 def _UploadAndReport(self, opt, todo, original_people): 306 def _UploadAndReport(self, opt, todo, original_people):
@@ -309,23 +312,23 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
309 312
310 # Check if there are local changes that may have been forgotten 313 # Check if there are local changes that may have been forgotten
311 if branch.project.HasChanges(): 314 if branch.project.HasChanges():
312 key = 'review.%s.autoupload' % branch.project.remote.review 315 key = 'review.%s.autoupload' % branch.project.remote.review
313 answer = branch.project.config.GetBoolean(key) 316 answer = branch.project.config.GetBoolean(key)
314 317
315 # if they want to auto upload, let's not ask because it could be automated 318 # if they want to auto upload, let's not ask because it could be automated
316 if answer is None: 319 if answer is None:
317 sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') 320 sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ')
318 a = sys.stdin.readline().strip().lower() 321 a = sys.stdin.readline().strip().lower()
319 if a not in ('y', 'yes', 't', 'true', 'on'): 322 if a not in ('y', 'yes', 't', 'true', 'on'):
320 print >>sys.stderr, "skipping upload" 323 print("skipping upload", file=sys.stderr)
321 branch.uploaded = False 324 branch.uploaded = False
322 branch.error = 'User aborted' 325 branch.error = 'User aborted'
323 continue 326 continue
324 327
325 # Check if topic branches should be sent to the server during upload 328 # Check if topic branches should be sent to the server during upload
326 if opt.auto_topic is not True: 329 if opt.auto_topic is not True:
327 key = 'review.%s.uploadtopic' % branch.project.remote.review 330 key = 'review.%s.uploadtopic' % branch.project.remote.review
328 opt.auto_topic = branch.project.config.GetBoolean(key) 331 opt.auto_topic = branch.project.config.GetBoolean(key)
329 332
330 branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) 333 branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft)
331 branch.uploaded = True 334 branch.uploaded = True
@@ -334,8 +337,8 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
334 branch.uploaded = False 337 branch.uploaded = False
335 have_errors = True 338 have_errors = True
336 339
337 print >>sys.stderr, '' 340 print(file=sys.stderr)
338 print >>sys.stderr, '----------------------------------------------------------------------' 341 print('----------------------------------------------------------------------', file=sys.stderr)
339 342
340 if have_errors: 343 if have_errors:
341 for branch in todo: 344 for branch in todo:
@@ -344,17 +347,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
344 fmt = ' (%s)' 347 fmt = ' (%s)'
345 else: 348 else:
346 fmt = '\n (%s)' 349 fmt = '\n (%s)'
347 print >>sys.stderr, ('[FAILED] %-15s %-15s' + fmt) % ( 350 print(('[FAILED] %-15s %-15s' + fmt) % (
348 branch.project.relpath + '/', \ 351 branch.project.relpath + '/', \
349 branch.name, \ 352 branch.name, \
350 str(branch.error)) 353 str(branch.error)),
351 print >>sys.stderr, '' 354 file=sys.stderr)
355 print()
352 356
353 for branch in todo: 357 for branch in todo:
354 if branch.uploaded: 358 if branch.uploaded:
355 print >>sys.stderr, '[OK ] %-15s %s' % ( 359 print('[OK ] %-15s %s' % (
356 branch.project.relpath + '/', 360 branch.project.relpath + '/',
357 branch.name) 361 branch.name),
362 file=sys.stderr)
358 363
359 if have_errors: 364 if have_errors:
360 sys.exit(1) 365 sys.exit(1)
@@ -385,17 +390,17 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
385 try: 390 try:
386 hook.Run(opt.allow_all_hooks, project_list=pending_proj_names) 391 hook.Run(opt.allow_all_hooks, project_list=pending_proj_names)
387 except HookError as e: 392 except HookError as e:
388 print >>sys.stderr, "ERROR: %s" % str(e) 393 print("ERROR: %s" % str(e), file=sys.stderr)
389 return 394 return
390 395
391 if opt.reviewers: 396 if opt.reviewers:
392 reviewers = _SplitEmails(opt.reviewers) 397 reviewers = _SplitEmails(opt.reviewers)
393 if opt.cc: 398 if opt.cc:
394 cc = _SplitEmails(opt.cc) 399 cc = _SplitEmails(opt.cc)
395 people = (reviewers,cc) 400 people = (reviewers, cc)
396 401
397 if not pending: 402 if not pending:
398 print >>sys.stdout, "no branches ready for upload" 403 print("no branches ready for upload", file=sys.stderr)
399 elif len(pending) == 1 and len(pending[0][1]) == 1: 404 elif len(pending) == 1 and len(pending[0][1]) == 1:
400 self._SingleBranch(opt, pending[0][1][0], people) 405 self._SingleBranch(opt, pending[0][1][0], people)
401 else: 406 else: