| 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 """Wrapper script around Rietveld's upload.py that groups files into | 6 """Wrapper script around Rietveld's upload.py that groups files into |
| 7 changelists.""" | 7 changelists.""" |
| 8 | 8 |
| 9 import getpass | 9 import getpass |
| 10 import os | 10 import os |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 break | 132 break |
| 133 # Make sure to mark settings as empty if not found. | 133 # Make sure to mark settings as empty if not found. |
| 134 content = "" | 134 content = "" |
| 135 if url_path == repo_root: | 135 if url_path == repo_root: |
| 136 # Reached the root. Abandoning search. | 136 # Reached the root. Abandoning search. |
| 137 break | 137 break |
| 138 # Go up one level to try again. | 138 # Go up one level to try again. |
| 139 url_path = os.path.dirname(url_path) | 139 url_path = os.path.dirname(url_path) |
| 140 # Write a cached version even if there isn't a file, so we don't try to | 140 # Write a cached version even if there isn't a file, so we don't try to |
| 141 # fetch it each time. | 141 # fetch it each time. |
| 142 WriteFile(cached_file, content) | 142 gclient_utils.FileWrite(cached_file, content) |
| 143 else: | 143 else: |
| 144 content = ReadFile(cached_file) | 144 content = ReadFile(cached_file) |
| 145 # Keep the content cached in memory. | 145 # Keep the content cached in memory. |
| 146 FILES_CACHE[filename] = content | 146 FILES_CACHE[filename] = content |
| 147 return FILES_CACHE[filename] | 147 return FILES_CACHE[filename] |
| 148 | 148 |
| 149 | 149 |
| 150 def GetCodeReviewSetting(key): | 150 def GetCodeReviewSetting(key): |
| 151 """Returns a value for the given key for this repository.""" | 151 """Returns a value for the given key for this repository.""" |
| 152 # Use '__just_initialized' as a flag to determine if the settings were | 152 # Use '__just_initialized' as a flag to determine if the settings were |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 | 207 |
| 208 def ReadFile(filename, flags='r'): | 208 def ReadFile(filename, flags='r'): |
| 209 """Returns the contents of a file.""" | 209 """Returns the contents of a file.""" |
| 210 f = open(filename, flags) | 210 f = open(filename, flags) |
| 211 result = f.read() | 211 result = f.read() |
| 212 f.close() | 212 f.close() |
| 213 return result | 213 return result |
| 214 | 214 |
| 215 | 215 |
| 216 def WriteFile(filename, contents): | |
| 217 """Overwrites the file with the given contents.""" | |
| 218 f = open(filename, 'w') | |
| 219 f.write(contents) | |
| 220 f.close() | |
| 221 | |
| 222 | |
| 223 def FilterFlag(args, flag): | 216 def FilterFlag(args, flag): |
| 224 """Returns True if the flag is present in args list. | 217 """Returns True if the flag is present in args list. |
| 225 | 218 |
| 226 The flag is removed from args if present. | 219 The flag is removed from args if present. |
| 227 """ | 220 """ |
| 228 if flag in args: | 221 if flag in args: |
| 229 args.remove(flag) | 222 args.remove(flag) |
| 230 return True | 223 return True |
| 231 return False | 224 return False |
| 232 | 225 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 def Save(self): | 292 def Save(self): |
| 300 """Writes the changelist information to disk.""" | 293 """Writes the changelist information to disk.""" |
| 301 if self.NeedsUpload(): | 294 if self.NeedsUpload(): |
| 302 needs_upload = "dirty" | 295 needs_upload = "dirty" |
| 303 else: | 296 else: |
| 304 needs_upload = "clean" | 297 needs_upload = "clean" |
| 305 data = ChangeInfo._SEPARATOR.join([ | 298 data = ChangeInfo._SEPARATOR.join([ |
| 306 "%d, %d, %s" % (self.issue, self.patchset, needs_upload), | 299 "%d, %d, %s" % (self.issue, self.patchset, needs_upload), |
| 307 "\n".join([f[0] + f[1] for f in self.GetFiles()]), | 300 "\n".join([f[0] + f[1] for f in self.GetFiles()]), |
| 308 self.description]) | 301 self.description]) |
| 309 WriteFile(GetChangelistInfoFile(self.name), data) | 302 gclient_utils.FileWrite(GetChangelistInfoFile(self.name), data) |
| 310 | 303 |
| 311 def Delete(self): | 304 def Delete(self): |
| 312 """Removes the changelist information from disk.""" | 305 """Removes the changelist information from disk.""" |
| 313 os.remove(GetChangelistInfoFile(self.name)) | 306 os.remove(GetChangelistInfoFile(self.name)) |
| 314 | 307 |
| 315 def CloseIssue(self): | 308 def CloseIssue(self): |
| 316 """Closes the Rietveld issue for this changelist.""" | 309 """Closes the Rietveld issue for this changelist.""" |
| 317 data = [("description", self.description),] | 310 data = [("description", self.description),] |
| 318 ctype, body = upload.EncodeMultipartFormData(data, []) | 311 ctype, body = upload.EncodeMultipartFormData(data, []) |
| 319 SendToRietveld("/%d/close" % self.issue, body, ctype) | 312 SendToRietveld("/%d/close" % self.issue, body, ctype) |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 return 0 | 1256 return 0 |
| 1264 args =["svn", command] | 1257 args =["svn", command] |
| 1265 root = GetRepositoryRoot() | 1258 root = GetRepositoryRoot() |
| 1266 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1259 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
| 1267 RunShell(args, True) | 1260 RunShell(args, True) |
| 1268 return 0 | 1261 return 0 |
| 1269 | 1262 |
| 1270 | 1263 |
| 1271 if __name__ == "__main__": | 1264 if __name__ == "__main__": |
| 1272 sys.exit(main()) | 1265 sys.exit(main()) |
| OLD | NEW |