Fix drover.py style.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/222010

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@26980 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 7f7915cb12
commit 817ba610a1

@ -1,6 +1,9 @@
@echo off @echo off
:: Copyright (c) 2009 The Chromium Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style license that can be
:: found in the LICENSE file.
setlocal setlocal
set PATH=%~dp0svn;%PATH% set PATH=%~dp0svn;%PATH%
call python "%~dp0drover.py" %* call python "%~dp0drover.py" %*

@ -1,76 +1,77 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
import subprocess import subprocess
import sys import sys
import re
import os
import webbrowser import webbrowser
def deltree(root): def deltree(root):
""" """Removes a given directory."""
Removes a given directory
"""
if (not os.path.exists(root)): if (not os.path.exists(root)):
return return
if sys.platform == 'win32': if sys.platform == 'win32':
os.system('rmdir /S /Q ' + root.replace('/','\\')) os.system('rmdir /S /Q ' + root.replace('/','\\'))
else: else:
for name in os.listdir(root): for name in os.listdir(root):
path = os.path.join(root, name) path = os.path.join(root, name)
if os.path.isdir(path): if os.path.isdir(path):
deltree(path) deltree(path)
else: else:
os.unlink(path) os.unlink(path)
os.rmdir(root) os.rmdir(root)
def clobberDir(dir): def clobberDir(dir):
""" """Removes a given directory."""
Removes a given directory
"""
if (os.path.exists(dir)): if (os.path.exists(dir)):
print dir + " directory found, deleting" print dir + " directory found, deleting"
#The following line was removed due to access controls in Windows # The following line was removed due to access controls in Windows
#which make os.unlink(path) calls impossible. # which make os.unlink(path) calls impossible.
#deltree(dir) # deltree(dir)
os.system('rmdir /S /Q ' + dir.replace('/','\\')) os.system('rmdir /S /Q ' + dir.replace('/','\\'))
def gclUpload(revision, author): def gclUpload(revision, author):
command = "gcl upload " + str(revision) + " --send_mail --no_try --no_presubmit --reviewers=" + author command = ("gcl upload " + str(revision) +
" --send_mail --no_try --no_presubmit --reviewers=" + author)
os.system(command) os.system(command)
# subprocess.Popen(command, # subprocess.Popen(command,
# shell=True, # shell=True,
# stdout=None, # stdout=None,
# stderr=subprocess.PIPE) # stderr=subprocess.PIPE)
# stderr=subprocess.PIPE).stdout.readlines() # stderr=subprocess.PIPE).stdout.readlines()
# for line in svn_info: # for line in svn_info:
# match = re.search(r"Issue created. URL: (http://.+)", line) # match = re.search(r"Issue created. URL: (http://.+)", line)
# if match: # if match:
# return match.group(1) # return match.group(1)
return None
return None
def getAuthor(url, revision): def getAuthor(url, revision):
command = 'svn info ' + url + "@"+str(revision) command = 'svn info ' + url + "@"+str(revision)
svn_info = subprocess.Popen(command, svn_info = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines() stderr=subprocess.PIPE).stdout.readlines()
for line in svn_info: for line in svn_info:
match = re.search(r"Last Changed Author: (.+)", line) match = re.search(r"Last Changed Author: (.+)", line)
if match: if match:
return match.group(1) return match.group(1)
return None return None
def getRevisionLog(url, revision): def getRevisionLog(url, revision):
""" """Takes an svn url and gets the associated revision. """
Takes an svn url and gets the associated revision.
"""
command = 'svn log ' + url + " -r"+str(revision) command = 'svn log ' + url + " -r"+str(revision)
svn_info = subprocess.Popen(command, svn_info = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines() stderr=subprocess.PIPE).stdout.readlines()
rtn= "" rtn= ""
pos = 0 pos = 0
@ -82,117 +83,101 @@ def getRevisionLog(url, revision):
return rtn return rtn
def checkoutRevision(url, revision, branch_url): def checkoutRevision(url, revision, branch_url):
paths = getBestMergePaths(url, revision) paths = getBestMergePaths(url, revision)
deltree('./src') deltree('./src')
if not os.path.exists('./src'): if not os.path.exists('./src'):
command = 'svn checkout -N ' + branch_url command = 'svn checkout -N ' + branch_url
print command print command
os.system(command) os.system(command)
#This line is extremely important due to the way svn behaves in the set-depths # This line is extremely important due to the way svn behaves in the
#action. If parents aren't handled before children, the child directories get # set-depths action. If parents aren't handled before children, the child
#clobbered and the merge step fails. # directories get clobbered and the merge step fails.
paths.sort() paths.sort()
for path in paths: for path in paths:
subpaths = path.split('/') subpaths = path.split('/')
subpaths.pop(0) subpaths.pop(0)
base = './src' base = './src'
for subpath in subpaths: for subpath in subpaths:
base += '/' + subpath base += '/' + subpath
if not os.path.exists(base): if not os.path.exists(base):
command = ('svn update --depth empty ' + base) command = ('svn update --depth empty ' + base)
print command print command
os.system(command) os.system(command)
else: else:
print "Found " + base print "Found " + base
files = getFilesInRevision(url, revision) for file in getFilesInRevision(url, revision):
# Prevent the tool from clobbering the src directory.
for file in files:
#Prevent the tool from clobbering the src directory
if (file == ""): if (file == ""):
continue continue
command = ('svn up ./src' + file) command = ('svn up ./src' + file)
print command print command
os.system(command) os.system(command)
#def mergeRevision(url, revision):
# command = 'svn merge -r ' + str(revision-1) + ":" + str(revision) + " " + url
# print command
# os.system(command)
def mergeRevision(url, revision, ignoreAncestry=False): def mergeRevision(url, revision, ignoreAncestry=False):
paths = getBestMergePaths(url, revision) paths = getBestMergePaths(url, revision)
for path in paths: for path in paths:
command = ('svn merge -N -r ' + str(revision-1) + ":" + str(revision) + " ") command = ('svn merge -N -r ' + str(revision-1) + ":" + str(revision) + " ")
if (ignoreAncestry): if (ignoreAncestry):
command = command + " --ignore-ancestry " command = command + " --ignore-ancestry "
command = command + url + path + " ./src" + path command = command + url + path + " ./src" + path
print command print command
os.system(command) os.system(command)
def revertRevision(url, revision): def revertRevision(url, revision):
paths = getBestMergePaths(url, revision) paths = getBestMergePaths(url, revision)
for path in paths: for path in paths:
command = ('svn merge -N -r ' + str(revision) + ":" + str(revision-1) + " " + command = ('svn merge -N -r ' + str(revision) + ":" + str(revision-1) +
url + path + " ./src" + path) " " + url + path + " ./src" + path)
print command print command
os.system(command) os.system(command)
def getBestMergePaths(url, revision): def getBestMergePaths(url, revision):
""" """Takes an svn url and gets the associated revision."""
Takes an svn url and gets the associated revision.
"""
command = 'svn log ' + url + " -r "+str(revision) + " -v" command = 'svn log ' + url + " -r "+str(revision) + " -v"
svn_info = subprocess.Popen(command, svn_info = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines() stderr=subprocess.PIPE).stdout.readlines()
map = dict() map = {}
for line in svn_info: for line in svn_info:
#match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/.*/src(.*)/.+", line)
#match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/(?:trunk|branches/\d+)/src(.*)/.+", line)
match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/(?:trunk|branches/\d+)/src([^ ]*)/[^ ]+", line) match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/(?:trunk|branches/\d+)/src([^ ]*)/[^ ]+", line)
if match: if match:
map[match.group(1)] = match.group(1) map[match.group(1)] = match.group(1)
return map.keys() return map.keys()
def getFilesInRevision(url, revision): def getFilesInRevision(url, revision):
""" """Takes an svn url and gets the associated revision."""
Takes an svn url and gets the associated revision.
"""
command = 'svn log ' + url + " -r "+str(revision) + " -v" command = 'svn log ' + url + " -r "+str(revision) + " -v"
svn_info = subprocess.Popen(command, svn_info = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines() stderr=subprocess.PIPE).stdout.readlines()
map = dict() map = {}
for line in svn_info: for line in svn_info:
match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/(?:trunk|branches/\d+)/src([^ ]*)/([^ ]+)", line) match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/(?:trunk|branches/\d+)/src([^ ]*)/([^ ]+)", line)
if match: if match:
map[match.group(1) + "/" + match.group(2)] = match.group(1) + "/" + match.group(2) map[match.group(1) + "/" + match.group(2)] = match.group(1) + "/" + match.group(2)
return map.keys() return map.keys()
def getBestMergePath(url, revision): def getBestMergePath(url, revision):
""" """Takes an svn url and gets the associated revision."""
Takes an svn url and gets the associated revision.
"""
command = 'svn log ' + url + " -r "+str(revision) + " -v" command = 'svn log ' + url + " -r "+str(revision) + " -v"
svn_info = subprocess.Popen(command, svn_info = subprocess.Popen(command,
shell=True, shell=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines() stderr=subprocess.PIPE).stdout.readlines()
best_path = None best_path = None
for line in svn_info: for line in svn_info:
match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/.*/src(.*)/.+", line) match = re.search(r"[\n\r ]+[MADUC][\n\r ]+/.*/src(.*)/.+", line)
if match: if match:
@ -200,21 +185,20 @@ def getBestMergePath(url, revision):
best_path = match.group(1) best_path = match.group(1)
else: else:
best_path = leastPath(match.group(1),best_path) best_path = leastPath(match.group(1),best_path)
# print best_path
return best_path return best_path
def leastPath(a, b): def leastPath(a, b):
if (not a) or (a == ""): if (not a) or (a == ""):
return "" return ""
if (b == ""): if (b == ""):
return "" return ""
if (not b): if (not b):
return a return a
a_list = a.lstrip("/").split("/") a_list = a.lstrip("/").split("/")
b_list = b.lstrip("/").split("/") b_list = b.lstrip("/").split("/")
last_match = "" last_match = ""
while((len(a_list) != 0) and (len(b_list) != 0)): while((len(a_list) != 0) and (len(b_list) != 0)):
a_value = a_list.pop(0) a_value = a_list.pop(0)
@ -223,12 +207,12 @@ def leastPath(a, b):
last_match = last_match + "/" + a_value last_match = last_match + "/" + a_value
else: else:
break break
return last_match return last_match
def prompt(question): def prompt(question):
p = None p = None
while not p: while not p:
print question + " [y|n]:" print question + " [y|n]:"
p = sys.stdin.readline() p = sys.stdin.readline()
@ -237,7 +221,8 @@ def prompt(question):
elif p.lower().startswith('y'): elif p.lower().startswith('y'):
return True return True
else: else:
p = None p = None
def main(argv=None): def main(argv=None):
BASE_URL = "svn://chrome-svn/chrome" BASE_URL = "svn://chrome-svn/chrome"
@ -267,23 +252,21 @@ def main(argv=None):
revision = int(sys.argv[1]) revision = int(sys.argv[1])
if ((len(sys.argv) >= 4) and (sys.argv[2] in ['--revert','-r'])): if ((len(sys.argv) >= 4) and (sys.argv[2] in ['--revert','-r'])):
BRANCH_URL = BASE_URL + "/branches/" + sys.argv[3] + "/src" BRANCH_URL = BASE_URL + "/branches/" + sys.argv[3] + "/src"
url = BRANCH_URL url = BRANCH_URL
else: else:
url = TRUNK_URL url = TRUNK_URL
action = "Merge" action = "Merge"
command = 'svn log ' + url + " -r "+str(revision) + " -v" command = 'svn log ' + url + " -r "+str(revision) + " -v"
os.system(command) os.system(command)
if not prompt("Is this the correct revision?"): if not prompt("Is this the correct revision?"):
sys.exit(0) sys.exit(0)
if (len(sys.argv) > 1): if (len(sys.argv) > 1):
if sys.argv[2] in ['--merge','-m']: if sys.argv[2] in ['--merge','-m']:
if (len(sys.argv) != 4): if (len(sys.argv) != 4):
print "Please specify the branch # you want (i.e. 182) after --merge" print "Please specify the branch # you want (i.e. 182) after --merge"
sys.exit(0) sys.exit(0)
branch_url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src" branch_url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src"
checkoutRevision(url, revision, branch_url) checkoutRevision(url, revision, branch_url)
mergeRevision(url, revision) mergeRevision(url, revision)
@ -293,7 +276,7 @@ def main(argv=None):
sys.exit(0) sys.exit(0)
branch_url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src" branch_url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src"
checkoutRevision(url, revision, branch_url) checkoutRevision(url, revision, branch_url)
mergeRevision(url, revision, True) mergeRevision(url, revision, True)
elif sys.argv[2] in ['--revert','-r']: elif sys.argv[2] in ['--revert','-r']:
if (len(sys.argv) == 4): if (len(sys.argv) == 4):
url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src" url = "svn://chrome-svn/chrome/branches/" + sys.argv[3] + "/src"
@ -305,10 +288,8 @@ def main(argv=None):
sys.exit(0) sys.exit(0)
os.chdir('./src') os.chdir('./src')
# Check the base url so we actually find the author who made the change.
#Check the base url so we actually find the author who made the change
author = getAuthor(BASE_URL, revision) author = getAuthor(BASE_URL, revision)
filename = str(revision)+".txt" filename = str(revision)+".txt"
out = open(filename,"w") out = open(filename,"w")
out.write(action +" " + str(revision) + " - ") out.write(action +" " + str(revision) + " - ")
@ -316,7 +297,6 @@ def main(argv=None):
if (author): if (author):
out.write("TBR=" + author) out.write("TBR=" + author)
out.close() out.close()
os.system('gcl change ' + str(revision) + " " + filename) os.system('gcl change ' + str(revision) + " " + filename)
os.unlink(filename) os.unlink(filename)
print author print author
@ -336,6 +316,7 @@ def main(argv=None):
os.system("gcl commit " + str(revision) + " --no_presubmit --force") os.system("gcl commit " + str(revision) + " --no_presubmit --force")
else: else:
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())

Loading…
Cancel
Save