| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 gclient_utils.FileWrite(cached_file, content) | 142 gclient_utils.FileWrite(cached_file, content) |
| 143 else: | 143 else: |
| 144 content = ReadFile(cached_file) | 144 content = gclient_utils.FileRead(cached_file, 'r') |
| 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 |
| 153 # already initialized. | 153 # already initialized. |
| 154 global CODEREVIEW_SETTINGS | 154 global CODEREVIEW_SETTINGS |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 p.wait() | 198 p.wait() |
| 199 p.stdout.close() | 199 p.stdout.close() |
| 200 return output, p.returncode | 200 return output, p.returncode |
| 201 | 201 |
| 202 | 202 |
| 203 def RunShell(command, print_output=False): | 203 def RunShell(command, print_output=False): |
| 204 """Executes a command and returns the output.""" | 204 """Executes a command and returns the output.""" |
| 205 return RunShellWithReturnCode(command, print_output)[0] | 205 return RunShellWithReturnCode(command, print_output)[0] |
| 206 | 206 |
| 207 | 207 |
| 208 def ReadFile(filename, flags='r'): | |
| 209 """Returns the contents of a file.""" | |
| 210 f = open(filename, flags) | |
| 211 result = f.read() | |
| 212 f.close() | |
| 213 return result | |
| 214 | |
| 215 | |
| 216 def FilterFlag(args, flag): | 208 def FilterFlag(args, flag): |
| 217 """Returns True if the flag is present in args list. | 209 """Returns True if the flag is present in args list. |
| 218 | 210 |
| 219 The flag is removed from args if present. | 211 The flag is removed from args if present. |
| 220 """ | 212 """ |
| 221 if flag in args: | 213 if flag in args: |
| 222 args.remove(flag) | 214 args.remove(flag) |
| 223 return True | 215 return True |
| 224 return False | 216 return False |
| 225 | 217 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 and unchanged files will be removed. | 401 and unchanged files will be removed. |
| 410 | 402 |
| 411 Returns: a ChangeInfo object. | 403 Returns: a ChangeInfo object. |
| 412 """ | 404 """ |
| 413 info_file = GetChangelistInfoFile(changename) | 405 info_file = GetChangelistInfoFile(changename) |
| 414 if not os.path.exists(info_file): | 406 if not os.path.exists(info_file): |
| 415 if fail_on_not_found: | 407 if fail_on_not_found: |
| 416 ErrorExit("Changelist " + changename + " not found.") | 408 ErrorExit("Changelist " + changename + " not found.") |
| 417 return ChangeInfo(changename, 0, 0, '', None, local_root, | 409 return ChangeInfo(changename, 0, 0, '', None, local_root, |
| 418 needs_upload=False) | 410 needs_upload=False) |
| 419 split_data = ReadFile(info_file).split(ChangeInfo._SEPARATOR, 2) | 411 split_data = gclient_utils.FileRead(info_file, 'r').split( |
| 412 ChangeInfo._SEPARATOR, 2) |
| 420 if len(split_data) != 3: | 413 if len(split_data) != 3: |
| 421 ErrorExit("Changelist file %s is corrupt" % info_file) | 414 ErrorExit("Changelist file %s is corrupt" % info_file) |
| 422 items = split_data[0].split(', ') | 415 items = split_data[0].split(', ') |
| 423 issue = 0 | 416 issue = 0 |
| 424 patchset = 0 | 417 patchset = 0 |
| 425 needs_upload = False | 418 needs_upload = False |
| 426 if items[0]: | 419 if items[0]: |
| 427 issue = int(items[0]) | 420 issue = int(items[0]) |
| 428 if len(items) > 1: | 421 if len(items) > 1: |
| 429 patchset = int(items[1]) | 422 patchset = int(items[1]) |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 separator2) | 998 separator2) |
| 1006 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' | 999 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' |
| 1007 | 1000 |
| 1008 handle, filename = tempfile.mkstemp(text=True) | 1001 handle, filename = tempfile.mkstemp(text=True) |
| 1009 os.write(handle, text) | 1002 os.write(handle, text) |
| 1010 os.close(handle) | 1003 os.close(handle) |
| 1011 | 1004 |
| 1012 if not silent: | 1005 if not silent: |
| 1013 os.system(GetEditor() + " " + filename) | 1006 os.system(GetEditor() + " " + filename) |
| 1014 | 1007 |
| 1015 result = ReadFile(filename) | 1008 result = gclient_utils.FileRead(filename, 'r') |
| 1016 os.remove(filename) | 1009 os.remove(filename) |
| 1017 | 1010 |
| 1018 if not result: | 1011 if not result: |
| 1019 return | 1012 return |
| 1020 | 1013 |
| 1021 split_result = result.split(separator1, 1) | 1014 split_result = result.split(separator1, 1) |
| 1022 if len(split_result) != 2: | 1015 if len(split_result) != 2: |
| 1023 ErrorExit("Don't modify the text starting with ---!\n\n" + result) | 1016 ErrorExit("Don't modify the text starting with ---!\n\n" + result) |
| 1024 | 1017 |
| 1025 # Update the CL description if it has changed. | 1018 # Update the CL description if it has changed. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 return 0 | 1249 return 0 |
| 1257 args =["svn", command] | 1250 args =["svn", command] |
| 1258 root = GetRepositoryRoot() | 1251 root = GetRepositoryRoot() |
| 1259 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1252 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
| 1260 RunShell(args, True) | 1253 RunShell(args, True) |
| 1261 return 0 | 1254 return 0 |
| 1262 | 1255 |
| 1263 | 1256 |
| 1264 if __name__ == "__main__": | 1257 if __name__ == "__main__": |
| 1265 sys.exit(main()) | 1258 sys.exit(main()) |
| OLD | NEW |