| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 import simplejson as json # pylint: disable=F0401 | 31 import simplejson as json # pylint: disable=F0401 |
| 32 | 32 |
| 33 import fix_encoding | 33 import fix_encoding |
| 34 import gclient_utils | 34 import gclient_utils |
| 35 import presubmit_support | 35 import presubmit_support |
| 36 import rietveld | 36 import rietveld |
| 37 from scm import SVN | 37 from scm import SVN |
| 38 import subprocess2 | 38 import subprocess2 |
| 39 from third_party import upload | 39 from third_party import upload |
| 40 | 40 |
| 41 __version__ = '1.2.2' | 41 __version__ = '1.2.1' |
| 42 | 42 |
| 43 | 43 |
| 44 CODEREVIEW_SETTINGS = { | 44 CODEREVIEW_SETTINGS = { |
| 45 # To make gcl send reviews to a server, check in a file named | 45 # To make gcl send reviews to a server, check in a file named |
| 46 # "codereview.settings" (see |CODEREVIEW_SETTINGS_FILE| below) to your | 46 # "codereview.settings" (see |CODEREVIEW_SETTINGS_FILE| below) to your |
| 47 # project's base directory and add the following line to codereview.settings: | 47 # project's base directory and add the following line to codereview.settings: |
| 48 # CODE_REVIEW_SERVER: codereview.yourserver.org | 48 # CODE_REVIEW_SERVER: codereview.yourserver.org |
| 49 } | 49 } |
| 50 | 50 |
| 51 # globals that store the root of the current repository and the directory where | 51 # globals that store the root of the current repository and the directory where |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 # Global cache of files cached in GetCacheDir(). | 63 # Global cache of files cached in GetCacheDir(). |
| 64 FILES_CACHE = {} | 64 FILES_CACHE = {} |
| 65 | 65 |
| 66 # Valid extensions for files we want to lint. | 66 # Valid extensions for files we want to lint. |
| 67 DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" | 67 DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" |
| 68 DEFAULT_LINT_IGNORE_REGEX = r"$^" | 68 DEFAULT_LINT_IGNORE_REGEX = r"$^" |
| 69 | 69 |
| 70 REVIEWERS_REGEX = r'\s*R=(.+)' | 70 REVIEWERS_REGEX = r'\s*R=(.+)' |
| 71 | 71 |
| 72 | |
| 73 def CheckHomeForFile(filename): | 72 def CheckHomeForFile(filename): |
| 74 """Checks the users home dir for the existence of the given file. Returns | 73 """Checks the users home dir for the existence of the given file. Returns |
| 75 the path to the file if it's there, or None if it is not. | 74 the path to the file if it's there, or None if it is not. |
| 76 """ | 75 """ |
| 77 home_vars = ['HOME'] | 76 home_vars = ['HOME'] |
| 78 if sys.platform in ('cygwin', 'win32'): | 77 if sys.platform in ('cygwin', 'win32'): |
| 79 home_vars.append('USERPROFILE') | 78 home_vars.append('USERPROFILE') |
| 80 for home_var in home_vars: | 79 for home_var in home_vars: |
| 81 home = os.getenv(home_var) | 80 home = os.getenv(home_var) |
| 82 if home != None: | 81 if home != None: |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 220 |
| 222 def Warn(msg): | 221 def Warn(msg): |
| 223 print >> sys.stderr, msg | 222 print >> sys.stderr, msg |
| 224 | 223 |
| 225 | 224 |
| 226 def ErrorExit(msg): | 225 def ErrorExit(msg): |
| 227 print >> sys.stderr, msg | 226 print >> sys.stderr, msg |
| 228 sys.exit(1) | 227 sys.exit(1) |
| 229 | 228 |
| 230 | 229 |
| 230 def RunShellWithReturnCode(command, print_output=False): |
| 231 """Executes a command and returns the output and the return code.""" |
| 232 p = subprocess2.Popen( |
| 233 command, stdout=subprocess2.PIPE, |
| 234 stderr=subprocess2.STDOUT, universal_newlines=True) |
| 235 if print_output: |
| 236 output_array = [] |
| 237 while True: |
| 238 line = p.stdout.readline() |
| 239 if not line: |
| 240 break |
| 241 if print_output: |
| 242 print line.strip('\n') |
| 243 output_array.append(line) |
| 244 output = "".join(output_array) |
| 245 else: |
| 246 output = p.stdout.read() |
| 247 p.wait() |
| 248 p.stdout.close() |
| 249 return output, p.returncode |
| 250 |
| 251 |
| 252 def RunShell(command, print_output=False): |
| 253 """Executes a command and returns the output.""" |
| 254 return RunShellWithReturnCode(command, print_output)[0] |
| 255 |
| 256 |
| 231 def FilterFlag(args, flag): | 257 def FilterFlag(args, flag): |
| 232 """Returns True if the flag is present in args list. | 258 """Returns True if the flag is present in args list. |
| 233 | 259 |
| 234 The flag is removed from args if present. | 260 The flag is removed from args if present. |
| 235 """ | 261 """ |
| 236 if flag in args: | 262 if flag in args: |
| 237 args.remove(flag) | 263 args.remove(flag) |
| 238 return True | 264 return True |
| 239 return False | 265 return False |
| 240 | 266 |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 commit_message = change_info.description.replace('\r\n', '\n') | 1007 commit_message = change_info.description.replace('\r\n', '\n') |
| 982 if change_info.issue: | 1008 if change_info.issue: |
| 983 server = change_info.rietveld | 1009 server = change_info.rietveld |
| 984 if not server.startswith("http://") and not server.startswith("https://"): | 1010 if not server.startswith("http://") and not server.startswith("https://"): |
| 985 server = "http://" + server | 1011 server = "http://" + server |
| 986 commit_message += ('\nReview URL: %s/%d' % (server, change_info.issue)) | 1012 commit_message += ('\nReview URL: %s/%d' % (server, change_info.issue)) |
| 987 | 1013 |
| 988 handle, commit_filename = tempfile.mkstemp(text=True) | 1014 handle, commit_filename = tempfile.mkstemp(text=True) |
| 989 os.write(handle, commit_message) | 1015 os.write(handle, commit_message) |
| 990 os.close(handle) | 1016 os.close(handle) |
| 991 try: | 1017 |
| 992 handle, targets_filename = tempfile.mkstemp(text=True) | 1018 handle, targets_filename = tempfile.mkstemp(text=True) |
| 993 os.write(handle, "\n".join(change_info.GetFileNames())) | 1019 os.write(handle, "\n".join(change_info.GetFileNames())) |
| 994 os.close(handle) | 1020 os.close(handle) |
| 995 try: | 1021 |
| 996 commit_cmd += ['--file=' + commit_filename] | 1022 commit_cmd += ['--file=' + commit_filename] |
| 997 commit_cmd += ['--targets=' + targets_filename] | 1023 commit_cmd += ['--targets=' + targets_filename] |
| 998 # Change the current working directory before calling commit. | 1024 # Change the current working directory before calling commit. |
| 999 previous_cwd = os.getcwd() | 1025 previous_cwd = os.getcwd() |
| 1000 os.chdir(change_info.GetLocalRoot()) | 1026 os.chdir(change_info.GetLocalRoot()) |
| 1001 output = '' | 1027 output = RunShell(commit_cmd, True) |
| 1002 try: | 1028 os.remove(commit_filename) |
| 1003 output = subprocess2.check_output(commit_cmd) | 1029 os.remove(targets_filename) |
| 1004 except subprocess2.CalledProcessError, e: | |
| 1005 ErrorExit('Commit failed.\n%s' % e) | |
| 1006 finally: | |
| 1007 os.remove(commit_filename) | |
| 1008 finally: | |
| 1009 os.remove(targets_filename) | |
| 1010 if output.find("Committed revision") != -1: | 1030 if output.find("Committed revision") != -1: |
| 1011 change_info.Delete() | 1031 change_info.Delete() |
| 1012 | 1032 |
| 1013 if change_info.issue: | 1033 if change_info.issue: |
| 1014 revision = re.compile(".*?\nCommitted revision (\d+)", | 1034 revision = re.compile(".*?\nCommitted revision (\d+)", |
| 1015 re.DOTALL).match(output).group(1) | 1035 re.DOTALL).match(output).group(1) |
| 1016 viewvc_url = GetCodeReviewSetting("VIEW_VC") | 1036 viewvc_url = GetCodeReviewSetting("VIEW_VC") |
| 1017 change_info.description += '\n' | 1037 change_info.description += '\n' |
| 1018 if viewvc_url: | 1038 if viewvc_url: |
| 1019 change_info.description += "\nCommitted: " + viewvc_url + revision | 1039 change_info.description += "\nCommitted: " + viewvc_url + revision |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 if args: | 1297 if args: |
| 1278 change_info = ChangeInfo.Load(args.pop(0), GetRepositoryRoot(), True, True) | 1298 change_info = ChangeInfo.Load(args.pop(0), GetRepositoryRoot(), True, True) |
| 1279 files = change_info.GetFileNames() | 1299 files = change_info.GetFileNames() |
| 1280 else: | 1300 else: |
| 1281 files = [f[1] for f in GetFilesNotInCL()] | 1301 files = [f[1] for f in GetFilesNotInCL()] |
| 1282 | 1302 |
| 1283 root = GetRepositoryRoot() | 1303 root = GetRepositoryRoot() |
| 1284 cmd = ['svn', 'diff'] | 1304 cmd = ['svn', 'diff'] |
| 1285 cmd.extend([os.path.join(root, x) for x in files]) | 1305 cmd.extend([os.path.join(root, x) for x in files]) |
| 1286 cmd.extend(args) | 1306 cmd.extend(args) |
| 1287 return subprocess2.call(cmd) | 1307 return RunShellWithReturnCode(cmd, print_output=True)[1] |
| 1288 | 1308 |
| 1289 | 1309 |
| 1290 @no_args | 1310 @no_args |
| 1291 def CMDsettings(): | 1311 def CMDsettings(): |
| 1292 """Prints code review settings for this checkout.""" | 1312 """Prints code review settings for this checkout.""" |
| 1293 # Force load settings | 1313 # Force load settings |
| 1294 GetCodeReviewSetting("UNKNOWN") | 1314 GetCodeReviewSetting("UNKNOWN") |
| 1295 del CODEREVIEW_SETTINGS['__just_initialized'] | 1315 del CODEREVIEW_SETTINGS['__just_initialized'] |
| 1296 print '\n'.join(("%s: %s" % (str(k), str(v)) | 1316 print '\n'.join(("%s: %s" % (str(k), str(v)) |
| 1297 for (k,v) in CODEREVIEW_SETTINGS.iteritems())) | 1317 for (k,v) in CODEREVIEW_SETTINGS.iteritems())) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 def CMDpassthru(args): | 1380 def CMDpassthru(args): |
| 1361 """Everything else that is passed into gcl we redirect to svn. | 1381 """Everything else that is passed into gcl we redirect to svn. |
| 1362 | 1382 |
| 1363 It assumes a change list name is passed and is converted with the files names. | 1383 It assumes a change list name is passed and is converted with the files names. |
| 1364 """ | 1384 """ |
| 1365 args = ["svn", args[0]] | 1385 args = ["svn", args[0]] |
| 1366 if len(args) > 1: | 1386 if len(args) > 1: |
| 1367 root = GetRepositoryRoot() | 1387 root = GetRepositoryRoot() |
| 1368 change_info = ChangeInfo.Load(args[1], root, True, True) | 1388 change_info = ChangeInfo.Load(args[1], root, True, True) |
| 1369 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1389 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
| 1370 return subprocess2.call(args) | 1390 return RunShellWithReturnCode(args, print_output=True)[1] |
| 1371 | 1391 |
| 1372 | 1392 |
| 1373 def Command(name): | 1393 def Command(name): |
| 1374 return getattr(sys.modules[__name__], 'CMD' + name, None) | 1394 return getattr(sys.modules[__name__], 'CMD' + name, None) |
| 1375 | 1395 |
| 1376 | 1396 |
| 1377 def GenUsage(command): | 1397 def GenUsage(command): |
| 1378 """Modify an OptParse object with the function's documentation.""" | 1398 """Modify an OptParse object with the function's documentation.""" |
| 1379 obj = Command(command) | 1399 obj = Command(command) |
| 1380 display = command | 1400 display = command |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 raise | 1477 raise |
| 1458 print >> sys.stderr, ( | 1478 print >> sys.stderr, ( |
| 1459 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1479 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 1460 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1480 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
| 1461 return 1 | 1481 return 1 |
| 1462 | 1482 |
| 1463 | 1483 |
| 1464 if __name__ == "__main__": | 1484 if __name__ == "__main__": |
| 1465 fix_encoding.fix_encoding() | 1485 fix_encoding.fix_encoding() |
| 1466 sys.exit(main(sys.argv[1:])) | 1486 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |