Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: gcl.py

Issue 4106011: Refactor ChangeInfo.Load() to make it possible to switch to a new format more easily. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
jochen (gone - plz use gerrit) 2010/10/29 18:25:08 nit non-std license header
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
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 and unchanged files will be removed. 435 and unchanged files will be removed.
436 436
437 Returns: a ChangeInfo object. 437 Returns: a ChangeInfo object.
438 """ 438 """
439 info_file = GetChangelistInfoFile(changename) 439 info_file = GetChangelistInfoFile(changename)
440 if not os.path.exists(info_file): 440 if not os.path.exists(info_file):
441 if fail_on_not_found: 441 if fail_on_not_found:
442 ErrorExit("Changelist " + changename + " not found.") 442 ErrorExit("Changelist " + changename + " not found.")
443 return ChangeInfo(changename, 0, 0, '', None, local_root, 443 return ChangeInfo(changename, 0, 0, '', None, local_root,
444 needs_upload=False) 444 needs_upload=False)
445 split_data = gclient_utils.FileRead(info_file, 'r').split( 445 content = gclient_utils.FileRead(info_file, 'r')
446 ChangeInfo._SEPARATOR, 2) 446 save = False
447 if len(split_data) != 3: 447 try:
448 values = ChangeInfo._LoadOldFormat(content)
449 except ValueError:
448 ErrorExit( 450 ErrorExit(
449 ('Changelist file %s is corrupt.\n' 451 ('Changelist file %s is corrupt.\n'
450 'Either run "gcl delete %s" or manually edit the file') % ( 452 'Either run "gcl delete %s" or manually edit the file') % (
451 info_file, changename)) 453 info_file, changename))
452 items = split_data[0].split(', ') 454 files = values['files']
453 issue = 0
454 patchset = 0
455 needs_upload = False
456 if items[0]:
457 issue = int(items[0])
458 if len(items) > 1:
459 patchset = int(items[1])
460 if len(items) > 2:
461 needs_upload = (items[2] == "dirty")
462 files = []
463 for line in split_data[1].splitlines():
464 status = line[:7]
465 filename = line[7:]
466 files.append((status, filename))
467 description = split_data[2]
468 save = False
469 if update_status: 455 if update_status:
470 for item in files[:]: 456 for item in files[:]:
471 filename = os.path.join(local_root, item[1]) 457 filename = os.path.join(local_root, item[1])
472 status_result = SVN.CaptureStatus(filename) 458 status_result = SVN.CaptureStatus(filename)
473 if not status_result or not status_result[0][0]: 459 if not status_result or not status_result[0][0]:
474 # File has been reverted. 460 # File has been reverted.
475 save = True 461 save = True
476 files.remove(item) 462 files.remove(item)
477 continue 463 continue
478 status = status_result[0][0] 464 status = status_result[0][0]
479 if status != item[0]: 465 if status != item[0]:
480 save = True 466 save = True
481 files[files.index(item)] = (status, item[1]) 467 files[files.index(item)] = (status, item[1])
482 change_info = ChangeInfo(changename, issue, patchset, description, files, 468 change_info = ChangeInfo(changename, values['issue'], values['patchset'],
483 local_root, needs_upload) 469 values['description'], files,
470 local_root, values['needs_upload'])
484 if save: 471 if save:
485 change_info.Save() 472 change_info.Save()
486 return change_info 473 return change_info
487 474
475 @staticmethod
476 def _LoadOldFormat(content):
477 split_data = content.split(ChangeInfo._SEPARATOR, 2)
478 if len(split_data) != 3:
479 raise ValueError('Bad change format')
480 values = {
481 'issue': 0,
482 'patchset': 0,
483 'needs_upload': False,
484 'files': [],
485 }
486 items = split_data[0].split(', ')
487 if items[0]:
488 values['issue'] = int(items[0])
489 if len(items) > 1:
490 values['patchset'] = int(items[1])
491 if len(items) > 2:
492 values['needs_upload'] = (items[2] == "dirty")
493 for line in split_data[1].splitlines():
494 status = line[:7]
495 filename = line[7:]
496 values['files'].append((status, filename))
497 values['description'] = split_data[2]
498 return values
499
488 500
489 def GetChangelistInfoFile(changename): 501 def GetChangelistInfoFile(changename):
490 """Returns the file that stores information about a changelist.""" 502 """Returns the file that stores information about a changelist."""
491 if not changename or re.search(r'[^\w-]', changename): 503 if not changename or re.search(r'[^\w-]', changename):
492 ErrorExit("Invalid changelist name: " + changename) 504 ErrorExit("Invalid changelist name: " + changename)
493 return os.path.join(GetChangesDir(), changename) 505 return os.path.join(GetChangesDir(), changename)
494 506
495 507
496 def LoadChangelistInfoForMultiple(changenames, local_root, fail_on_not_found, 508 def LoadChangelistInfoForMultiple(changenames, local_root, fail_on_not_found,
497 update_status): 509 update_status):
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 if e.code != 500: 1353 if e.code != 500:
1342 raise 1354 raise
1343 print >> sys.stderr, ( 1355 print >> sys.stderr, (
1344 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 1356 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
1345 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) 1357 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))
1346 return 1 1358 return 1
1347 1359
1348 1360
1349 if __name__ == "__main__": 1361 if __name__ == "__main__":
1350 sys.exit(main(sys.argv[1:])) 1362 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698