Chromium Code Reviews| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 return [file[1] for file in self._files] | 299 return [file[1] for file in self._files] |
| 300 | 300 |
| 301 def GetFiles(self): | 301 def GetFiles(self): |
| 302 """Returns the list of files included in this change with their status.""" | 302 """Returns the list of files included in this change with their status.""" |
| 303 return self._files | 303 return self._files |
| 304 | 304 |
| 305 def GetLocalRoot(self): | 305 def GetLocalRoot(self): |
| 306 """Returns the local repository checkout root directory.""" | 306 """Returns the local repository checkout root directory.""" |
| 307 return self._local_root | 307 return self._local_root |
| 308 | 308 |
| 309 def Exists(self): | |
| 310 """Returns True if this change already exists (i.e., is not new).""" | |
| 311 return (self.issue or self.description or self._files) | |
| 312 | |
| 309 def _NonDeletedFileList(self): | 313 def _NonDeletedFileList(self): |
| 310 """Returns a list of files in this change, not including deleted files.""" | 314 """Returns a list of files in this change, not including deleted files.""" |
| 311 return [file[1] for file in self.GetFiles() | 315 return [file[1] for file in self.GetFiles() |
| 312 if not file[0].startswith("D")] | 316 if not file[0].startswith("D")] |
| 313 | 317 |
| 314 def _AddedFileList(self): | 318 def _AddedFileList(self): |
| 315 """Returns a list of files added in this change.""" | 319 """Returns a list of files added in this change.""" |
| 316 return [file[1] for file in self.GetFiles() if file[0].startswith("A")] | 320 return [file[1] for file in self.GetFiles() if file[0].startswith("A")] |
| 317 | 321 |
| 318 def Save(self): | 322 def Save(self): |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 else: | 975 else: |
| 972 ErrorExit("Error getting the description from Rietveld: " + err) | 976 ErrorExit("Error getting the description from Rietveld: " + err) |
| 973 else: | 977 else: |
| 974 if override_description: | 978 if override_description: |
| 975 description = override_description | 979 description = override_description |
| 976 else: | 980 else: |
| 977 description = change_info.description | 981 description = change_info.description |
| 978 | 982 |
| 979 other_files = GetFilesNotInCL() | 983 other_files = GetFilesNotInCL() |
| 980 | 984 |
| 981 #Edited files will have a letter for the first character in a string. | 985 # Edited files (as opposed to files with only changed properties) will have |
| 982 #This regex looks for the presence of that character. | 986 # a letter for the first character in the status string. |
| 983 file_re = re.compile(r"^[a-z].+\Z", re.IGNORECASE) | 987 file_re = re.compile(r"^[a-z].+\Z", re.IGNORECASE) |
| 984 affected_files = filter(lambda x: file_re.match(x[0]), other_files) | 988 affected_files = [x for x in other_files if file_re.match(x[0])] |
|
M-A Ruel
2009/08/07 01:01:30
Hey, you are fixing my abuse of filter()!
| |
| 985 unaffected_files = filter(lambda x: not file_re.match(x[0]), other_files) | 989 unaffected_files = [x for x in other_files if not file_re.match(x[0])] |
| 986 | 990 |
| 987 separator1 = ("\n---All lines above this line become the description.\n" | 991 separator1 = ("\n---All lines above this line become the description.\n" |
| 988 "---Repository Root: " + change_info.GetLocalRoot() + "\n" | 992 "---Repository Root: " + change_info.GetLocalRoot() + "\n" |
| 989 "---Paths in this changelist (" + change_info.name + "):\n") | 993 "---Paths in this changelist (" + change_info.name + "):\n") |
| 990 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" | 994 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" |
| 991 text = (description + separator1 + '\n' + | 995 text = (description + separator1 + '\n' + |
| 992 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()]) + | 996 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()])) |
| 993 separator2 + | 997 |
| 994 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + | 998 if change_info.Exists(): |
| 995 '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n') | 999 text += (separator2 + |
| 1000 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n') | |
| 1001 else: | |
| 1002 text += ('\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + | |
| 1003 separator2) | |
| 1004 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' | |
| 996 | 1005 |
| 997 handle, filename = tempfile.mkstemp(text=True) | 1006 handle, filename = tempfile.mkstemp(text=True) |
| 998 os.write(handle, text) | 1007 os.write(handle, text) |
| 999 os.close(handle) | 1008 os.close(handle) |
| 1000 | 1009 |
| 1001 os.system(GetEditor() + " " + filename) | 1010 os.system(GetEditor() + " " + filename) |
| 1002 | 1011 |
| 1003 result = ReadFile(filename) | 1012 result = ReadFile(filename) |
| 1004 os.remove(filename) | 1013 os.remove(filename) |
| 1005 | 1014 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1227 # the files. This allows commands such as 'gcl diff xxx' to work. | 1236 # the files. This allows commands such as 'gcl diff xxx' to work. |
| 1228 args =["svn", command] | 1237 args =["svn", command] |
| 1229 root = GetRepositoryRoot() | 1238 root = GetRepositoryRoot() |
| 1230 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1239 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
| 1231 RunShell(args, True) | 1240 RunShell(args, True) |
| 1232 return 0 | 1241 return 0 |
| 1233 | 1242 |
| 1234 | 1243 |
| 1235 if __name__ == "__main__": | 1244 if __name__ == "__main__": |
| 1236 sys.exit(main()) | 1245 sys.exit(main()) |
| OLD | NEW |