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 try: | |
24 import simplejson as json | |
25 except ImportError: | |
26 try: | |
27 import json | |
28 # Some versions of python2.5 have an incomplete json module. Check to make | |
29 # sure loads exists. | |
30 # pylint: disable=W0104 | |
31 json.loads | |
32 except (ImportError, AttributeError): | |
33 # Import the one included in depot_tools. | |
34 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) | |
jochen (gone - plz use gerrit)
2010/10/29 18:29:33
since this is part of depot_tools anyway, why not
M-A Ruel
2010/11/01 13:33:01
I wanted to use the included copy at last resort b
| |
35 import simplejson as json | |
36 | |
23 import breakpad | 37 import breakpad |
24 | 38 |
25 # gcl now depends on gclient. | 39 # gcl now depends on gclient. |
26 from scm import SVN | 40 from scm import SVN |
27 import gclient_utils | 41 import gclient_utils |
28 | 42 |
29 __version__ = '1.2' | 43 __version__ = '1.2' |
30 | 44 |
31 | 45 |
32 CODEREVIEW_SETTINGS = { | 46 CODEREVIEW_SETTINGS = { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 """Returns a list of files in this change, not including deleted files.""" | 324 """Returns a list of files in this change, not including deleted files.""" |
311 return [f[1] for f in self.GetFiles() | 325 return [f[1] for f in self.GetFiles() |
312 if not f[0].startswith("D")] | 326 if not f[0].startswith("D")] |
313 | 327 |
314 def _AddedFileList(self): | 328 def _AddedFileList(self): |
315 """Returns a list of files added in this change.""" | 329 """Returns a list of files added in this change.""" |
316 return [f[1] for f in self.GetFiles() if f[0].startswith("A")] | 330 return [f[1] for f in self.GetFiles() if f[0].startswith("A")] |
317 | 331 |
318 def Save(self): | 332 def Save(self): |
319 """Writes the changelist information to disk.""" | 333 """Writes the changelist information to disk.""" |
320 if self.NeedsUpload(): | 334 data = json.dumps({ |
321 needs_upload = "dirty" | 335 'issue': self.issue, |
322 else: | 336 'patchset': self.patchset, |
323 needs_upload = "clean" | 337 'needs_upload': self.NeedsUpload(), |
324 data = ChangeInfo._SEPARATOR.join([ | 338 'files': self.GetFiles(), |
325 "%d, %d, %s" % (self.issue, self.patchset, needs_upload), | 339 'description': self.description, |
326 "\n".join([f[0] + f[1] for f in self.GetFiles()]), | 340 }, sort_keys=True, indent=2) |
327 self.description]) | |
328 gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data) | 341 gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data) |
329 | 342 |
330 def Delete(self): | 343 def Delete(self): |
331 """Removes the changelist information from disk.""" | 344 """Removes the changelist information from disk.""" |
332 os.remove(GetChangelistInfoFile(self.name)) | 345 os.remove(GetChangelistInfoFile(self.name)) |
333 | 346 |
334 def CloseIssue(self): | 347 def CloseIssue(self): |
335 """Closes the Rietveld issue for this changelist.""" | 348 """Closes the Rietveld issue for this changelist.""" |
336 data = [("description", self.description),] | 349 data = [("description", self.description),] |
337 ctype, body = upload.EncodeMultipartFormData(data, []) | 350 ctype, body = upload.EncodeMultipartFormData(data, []) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 """ | 451 """ |
439 info_file = GetChangelistInfoFile(changename) | 452 info_file = GetChangelistInfoFile(changename) |
440 if not os.path.exists(info_file): | 453 if not os.path.exists(info_file): |
441 if fail_on_not_found: | 454 if fail_on_not_found: |
442 ErrorExit("Changelist " + changename + " not found.") | 455 ErrorExit("Changelist " + changename + " not found.") |
443 return ChangeInfo(changename, 0, 0, '', None, local_root, | 456 return ChangeInfo(changename, 0, 0, '', None, local_root, |
444 needs_upload=False) | 457 needs_upload=False) |
445 content = gclient_utils.FileRead(info_file, 'r') | 458 content = gclient_utils.FileRead(info_file, 'r') |
446 save = False | 459 save = False |
447 try: | 460 try: |
448 values = ChangeInfo._LoadOldFormat(content) | 461 values = ChangeInfo._LoadNewFormat(content) |
449 except ValueError: | 462 except ValueError: |
450 ErrorExit( | 463 try: |
451 ('Changelist file %s is corrupt.\n' | 464 values = ChangeInfo._LoadOldFormat(content) |
452 'Either run "gcl delete %s" or manually edit the file') % ( | 465 save = True |
453 info_file, changename)) | 466 except ValueError: |
467 ErrorExit( | |
468 ('Changelist file %s is corrupt.\n' | |
469 'Either run "gcl delete %s" or manually edit the file') % ( | |
470 info_file, changename)) | |
454 files = values['files'] | 471 files = values['files'] |
455 if update_status: | 472 if update_status: |
456 for item in files[:]: | 473 for item in files[:]: |
457 filename = os.path.join(local_root, item[1]) | 474 filename = os.path.join(local_root, item[1]) |
458 status_result = SVN.CaptureStatus(filename) | 475 status_result = SVN.CaptureStatus(filename) |
459 if not status_result or not status_result[0][0]: | 476 if not status_result or not status_result[0][0]: |
460 # File has been reverted. | 477 # File has been reverted. |
461 save = True | 478 save = True |
462 files.remove(item) | 479 files.remove(item) |
463 continue | 480 continue |
(...skipping 26 matching lines...) Expand all Loading... | |
490 values['patchset'] = int(items[1]) | 507 values['patchset'] = int(items[1]) |
491 if len(items) > 2: | 508 if len(items) > 2: |
492 values['needs_upload'] = (items[2] == "dirty") | 509 values['needs_upload'] = (items[2] == "dirty") |
493 for line in split_data[1].splitlines(): | 510 for line in split_data[1].splitlines(): |
494 status = line[:7] | 511 status = line[:7] |
495 filename = line[7:] | 512 filename = line[7:] |
496 values['files'].append((status, filename)) | 513 values['files'].append((status, filename)) |
497 values['description'] = split_data[2] | 514 values['description'] = split_data[2] |
498 return values | 515 return values |
499 | 516 |
517 @staticmethod | |
518 def _LoadNewFormat(content): | |
519 return json.loads(content) | |
520 | |
500 | 521 |
501 def GetChangelistInfoFile(changename): | 522 def GetChangelistInfoFile(changename): |
502 """Returns the file that stores information about a changelist.""" | 523 """Returns the file that stores information about a changelist.""" |
503 if not changename or re.search(r'[^\w-]', changename): | 524 if not changename or re.search(r'[^\w-]', changename): |
504 ErrorExit("Invalid changelist name: " + changename) | 525 ErrorExit("Invalid changelist name: " + changename) |
505 return os.path.join(GetChangesDir(), changename) | 526 return os.path.join(GetChangesDir(), changename) |
506 | 527 |
507 | 528 |
508 def LoadChangelistInfoForMultiple(changenames, local_root, fail_on_not_found, | 529 def LoadChangelistInfoForMultiple(changenames, local_root, fail_on_not_found, |
509 update_status): | 530 update_status): |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 if e.code != 500: | 1374 if e.code != 500: |
1354 raise | 1375 raise |
1355 print >> sys.stderr, ( | 1376 print >> sys.stderr, ( |
1356 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1377 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1357 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1378 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1358 return 1 | 1379 return 1 |
1359 | 1380 |
1360 | 1381 |
1361 if __name__ == "__main__": | 1382 if __name__ == "__main__": |
1362 sys.exit(main(sys.argv[1:])) | 1383 sys.exit(main(sys.argv[1:])) |
OLD | NEW |