| 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 import optparse | 6 import optparse |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import subprocess | |
| 10 import sys | 9 import sys |
| 11 | 10 |
| 12 import breakpad # pylint: disable=W0611 | 11 import breakpad # pylint: disable=W0611 |
| 13 | 12 |
| 14 import gclient_utils | 13 import gclient_utils |
| 14 import subprocess2 |
| 15 | 15 |
| 16 USAGE = """ | 16 USAGE = """ |
| 17 WARNING: Please use this tool in an empty directory | 17 WARNING: Please use this tool in an empty directory |
| 18 (or at least one that you don't mind clobbering.) | 18 (or at least one that you don't mind clobbering.) |
| 19 | 19 |
| 20 REQUIRES: SVN 1.5+ | 20 REQUIRES: SVN 1.5+ |
| 21 NOTE: NO NEED TO CHECKOUT ANYTHING IN ADVANCE OF USING THIS TOOL." | 21 NOTE: NO NEED TO CHECKOUT ANYTHING IN ADVANCE OF USING THIS TOOL. |
| 22 Valid parameters: | 22 Valid parameters: |
| 23 | 23 |
| 24 [Merge from trunk to branch] | 24 [Merge from trunk to branch] |
| 25 --merge <revision> --branch <branch_num> | 25 --merge <revision> --branch <branch_num> |
| 26 Example: %(app)s --merge 12345 --branch 187 | 26 Example: %(app)s --merge 12345 --branch 187 |
| 27 | 27 |
| 28 [Merge from trunk to local copy] | 28 [Merge from trunk to local copy] |
| 29 --merge <revision> --local | 29 --merge <revision> --local |
| 30 Example: %(app)s --merge 12345 --local | 30 Example: %(app)s --merge 12345 --local |
| 31 | 31 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 command = "%s %s" % (gcl_path, subcommand) | 58 command = "%s %s" % (gcl_path, subcommand) |
| 59 return os.system(command) | 59 return os.system(command) |
| 60 | 60 |
| 61 def gclUpload(revision, author): | 61 def gclUpload(revision, author): |
| 62 command = ("upload " + str(revision) + | 62 command = ("upload " + str(revision) + |
| 63 " --send_mail --no_presubmit --reviewers=" + author) | 63 " --send_mail --no_presubmit --reviewers=" + author) |
| 64 return runGcl(command) | 64 return runGcl(command) |
| 65 | 65 |
| 66 def getSVNInfo(url, revision): | 66 def getSVNInfo(url, revision): |
| 67 svn_info = gclient_utils.Popen(['svn', 'info', '%s@%s' % (url, revision)], | 67 svn_info = subprocess2.check_output( |
| 68 stdout=subprocess.PIPE, | 68 ['svn', 'info', '%s@%s' % (url, revision)]).splitlines() |
| 69 stderr=subprocess.PIPE).stdout.readlines() | |
| 70 info = {} | 69 info = {} |
| 71 for line in svn_info: | 70 for line in svn_info: |
| 72 match = re.search(r"(.*?):(.*)", line) | 71 match = re.search(r"(.*?):(.*)", line) |
| 73 if match: | 72 if match: |
| 74 info[match.group(1).strip()]=match.group(2).strip() | 73 info[match.group(1).strip()]=match.group(2).strip() |
| 75 | 74 |
| 76 return info | 75 return info |
| 77 | 76 |
| 78 def isSVNDirty(): | 77 def isSVNDirty(): |
| 79 svn_status = gclient_utils.Popen(['svn', 'status'], | 78 svn_status = subprocess2.check_output(['svn', 'status']).splitlines() |
| 80 stdout=subprocess.PIPE, | |
| 81 stderr=subprocess.PIPE).stdout.readlines() | |
| 82 for line in svn_status: | 79 for line in svn_status: |
| 83 match = re.search(r"^[^X?]", line) | 80 match = re.search(r"^[^X?]", line) |
| 84 if match: | 81 if match: |
| 85 return True | 82 return True |
| 86 | 83 |
| 87 return False | 84 return False |
| 88 | 85 |
| 89 def getAuthor(url, revision): | 86 def getAuthor(url, revision): |
| 90 info = getSVNInfo(url, revision) | 87 info = getSVNInfo(url, revision) |
| 91 if (info.has_key("Last Changed Author")): | 88 if (info.has_key("Last Changed Author")): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 111 if (not info.has_key("Repository Root")): | 108 if (not info.has_key("Repository Root")): |
| 112 return False | 109 return False |
| 113 repo_root = info["Repository Root"] | 110 repo_root = info["Repository Root"] |
| 114 info = getSVNInfo(os.path.dirname(os.path.abspath(path)), "HEAD") | 111 info = getSVNInfo(os.path.dirname(os.path.abspath(path)), "HEAD") |
| 115 if (info.get("Repository Root", None) != repo_root): | 112 if (info.get("Repository Root", None) != repo_root): |
| 116 return True | 113 return True |
| 117 return False | 114 return False |
| 118 | 115 |
| 119 def getRevisionLog(url, revision): | 116 def getRevisionLog(url, revision): |
| 120 """Takes an svn url and gets the associated revision.""" | 117 """Takes an svn url and gets the associated revision.""" |
| 121 svn_log = gclient_utils.Popen(['svn', 'log', url, '-r', str(revision)], | 118 svn_log = subprocess2.check_output( |
| 122 stdout=subprocess.PIPE, | 119 ['svn', 'log', url, '-r', str(revision)]).splitlines() |
| 123 stderr=subprocess.PIPE).stdout.readlines() | |
| 124 # Don't include the header lines and the trailing "---..." line and eliminate | 120 # Don't include the header lines and the trailing "---..." line and eliminate |
| 125 # any '\r's. | 121 # any '\r's. |
| 126 return ''.join([l.replace('\r','') for l in svn_log[3:-1]]) | 122 return ''.join([l.replace('\r','') for l in svn_log[3:-1]]) |
| 127 | 123 |
| 128 def getSVNVersionInfo(): | 124 def getSVNVersionInfo(): |
| 129 """Extract version information from SVN""" | 125 """Extract version information from SVN""" |
| 130 svn_info = gclient_utils.Popen(['svn', '--version'], | 126 svn_info = subprocess2.check_output(['svn', '--version']).splitlines() |
| 131 stdout=subprocess.PIPE, | |
| 132 stderr=subprocess.PIPE).stdout.readlines() | |
| 133 info = {} | 127 info = {} |
| 134 for line in svn_info: | 128 for line in svn_info: |
| 135 match = re.search(r"svn, version ((\d+)\.(\d+)\.(\d+))", line) | 129 match = re.search(r"svn, version ((\d+)\.(\d+)\.(\d+))", line) |
| 136 if match: | 130 if match: |
| 137 info['version'] = match.group(1) | 131 info['version'] = match.group(1) |
| 138 info['major'] = int(match.group(2)) | 132 info['major'] = int(match.group(2)) |
| 139 info['minor'] = int(match.group(3)) | 133 info['minor'] = int(match.group(3)) |
| 140 info['patch'] = int(match.group(4)) | 134 info['patch'] = int(match.group(4)) |
| 141 return info | 135 return info |
| 142 | 136 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 " " + url + path + " ." + path) | 264 " " + url + path + " ." + path) |
| 271 print command | 265 print command |
| 272 os.system(command) | 266 os.system(command) |
| 273 | 267 |
| 274 def getFileInfo(url, revision): | 268 def getFileInfo(url, revision): |
| 275 global files_info_ | 269 global files_info_ |
| 276 | 270 |
| 277 if (files_info_ != None): | 271 if (files_info_ != None): |
| 278 return files_info_ | 272 return files_info_ |
| 279 | 273 |
| 280 svn_log = gclient_utils.Popen(['svn', 'log', url, '-r', str(revision), '-v'], | 274 svn_log = subprocess2.check_output( |
| 281 stdout=subprocess.PIPE, | 275 ['svn', 'log', url, '-r', str(revision), '-v']).splitlines() |
| 282 stderr=subprocess.PIPE).stdout.readlines() | |
| 283 | 276 |
| 284 info = [] | 277 info = [] |
| 285 for line in svn_log: | 278 for line in svn_log: |
| 286 # A workaround to dump the (from .*) stuff, regex not so friendly in the 2nd | 279 # A workaround to dump the (from .*) stuff, regex not so friendly in the 2nd |
| 287 # pass... | 280 # pass... |
| 288 match = re.search(r"(.*) \(from.*\)", line) | 281 match = re.search(r"(.*) \(from.*\)", line) |
| 289 if match: | 282 if match: |
| 290 line = match.group(1) | 283 line = match.group(1) |
| 291 match = re.search(file_pattern_, line) | 284 match = re.search(file_pattern_, line) |
| 292 if match: | 285 if match: |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 command = 'svn log ' + url + " -r "+str(revision) + " -v" | 423 command = 'svn log ' + url + " -r "+str(revision) + " -v" |
| 431 os.system(command) | 424 os.system(command) |
| 432 | 425 |
| 433 if not (options.revertbot or prompt("Is this the correct revision?")): | 426 if not (options.revertbot or prompt("Is this the correct revision?")): |
| 434 return 0 | 427 return 0 |
| 435 | 428 |
| 436 if (os.path.exists(working)) and not options.local: | 429 if (os.path.exists(working)) and not options.local: |
| 437 if not (options.revertbot or SKIP_CHECK_WORKING or | 430 if not (options.revertbot or SKIP_CHECK_WORKING or |
| 438 prompt("Working directory: '%s' already exists, clobber?" % working)): | 431 prompt("Working directory: '%s' already exists, clobber?" % working)): |
| 439 return 0 | 432 return 0 |
| 440 gclient_utils.RemoveDirectory(working) | 433 gclient_utils.rmtree(working) |
| 441 | 434 |
| 442 if not options.local: | 435 if not options.local: |
| 443 os.makedirs(working) | 436 os.makedirs(working) |
| 444 os.chdir(working) | 437 os.chdir(working) |
| 445 | 438 |
| 446 if options.merge: | 439 if options.merge: |
| 447 action = "Merge" | 440 action = "Merge" |
| 448 if not options.local: | 441 if not options.local: |
| 449 branch_url = BRANCH_URL.replace("$branch", options.branch) | 442 branch_url = BRANCH_URL.replace("$branch", options.branch) |
| 450 # Checkout everything but stuff that got added into a new dir | 443 # Checkout everything but stuff that got added into a new dir |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 544 |
| 552 if options.local and (options.revert or options.branch): | 545 if options.local and (options.revert or options.branch): |
| 553 option_parser.error("--local cannot be used with --revert or --branch") | 546 option_parser.error("--local cannot be used with --revert or --branch") |
| 554 return 1 | 547 return 1 |
| 555 | 548 |
| 556 return drover(options, args) | 549 return drover(options, args) |
| 557 | 550 |
| 558 | 551 |
| 559 if __name__ == "__main__": | 552 if __name__ == "__main__": |
| 560 sys.exit(main()) | 553 sys.exit(main()) |
| OLD | NEW |