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

Unified Diff: gcl.py

Issue 4127013: Refactor ChangeInfo.Load() to make it easier to support mulitple format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 10 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gcl.py
diff --git a/gcl.py b/gcl.py
index 4c1e28448eccc6063830ae0661fd516a49e1215b..d4dac604b4e47c76a18897ba4b03ba1590e4d395 100755
--- a/gcl.py
+++ b/gcl.py
@@ -20,6 +20,20 @@ import time
from third_party import upload
import urllib2
+try:
+ import simplejson as json
+except ImportError:
+ try:
+ import json
+ # Some versions of python2.5 have an incomplete json module. Check to make
+ # sure loads exists.
+ # pylint: disable=W0104
+ json.loads
+ except (ImportError, AttributeError):
+ # Import the one included in depot_tools.
+ 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
+ import simplejson as json
+
import breakpad
# gcl now depends on gclient.
@@ -317,14 +331,13 @@ class ChangeInfo(object):
def Save(self):
"""Writes the changelist information to disk."""
- if self.NeedsUpload():
- needs_upload = "dirty"
- else:
- needs_upload = "clean"
- data = ChangeInfo._SEPARATOR.join([
- "%d, %d, %s" % (self.issue, self.patchset, needs_upload),
- "\n".join([f[0] + f[1] for f in self.GetFiles()]),
- self.description])
+ data = json.dumps({
+ 'issue': self.issue,
+ 'patchset': self.patchset,
+ 'needs_upload': self.NeedsUpload(),
+ 'files': self.GetFiles(),
+ 'description': self.description,
+ }, sort_keys=True, indent=2)
gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data)
def Delete(self):
@@ -445,12 +458,16 @@ class ChangeInfo(object):
content = gclient_utils.FileRead(info_file, 'r')
save = False
try:
- values = ChangeInfo._LoadOldFormat(content)
+ values = ChangeInfo._LoadNewFormat(content)
except ValueError:
- ErrorExit(
- ('Changelist file %s is corrupt.\n'
- 'Either run "gcl delete %s" or manually edit the file') % (
- info_file, changename))
+ try:
+ values = ChangeInfo._LoadOldFormat(content)
+ save = True
+ except ValueError:
+ ErrorExit(
+ ('Changelist file %s is corrupt.\n'
+ 'Either run "gcl delete %s" or manually edit the file') % (
+ info_file, changename))
files = values['files']
if update_status:
for item in files[:]:
@@ -497,6 +514,10 @@ class ChangeInfo(object):
values['description'] = split_data[2]
return values
+ @staticmethod
+ def _LoadNewFormat(content):
+ return json.loads(content)
+
def GetChangelistInfoFile(changename):
"""Returns the file that stores information about a changelist."""
« no previous file with comments | « no previous file | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698