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,4 +1,7 @@
@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%

@ -1,13 +1,16 @@
# 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
@ -22,10 +25,9 @@ def deltree(root):
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"
@ -34,8 +36,10 @@ def clobberDir(dir):
# 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,
@ -46,9 +50,9 @@ def gclUpload(revision, author):
# 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,
@ -59,14 +63,11 @@ def getAuthor(url, revision):
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,
@ -82,21 +83,19 @@ 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)
@ -110,20 +109,14 @@ def checkoutRevision(url, revision, branch_url):
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)
@ -132,67 +125,59 @@ def mergeRevision(url, revision, ignoreAncestry=False):
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,10 +185,10 @@ 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 ""
@ -214,7 +199,6 @@ def leastPath(a, b):
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)
@ -226,9 +210,9 @@ def leastPath(a, b):
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()
@ -239,6 +223,7 @@ def prompt(question):
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"
TRUNK_URL = BASE_URL + "/trunk/src" TRUNK_URL = BASE_URL + "/trunk/src"
@ -271,10 +256,8 @@ def main(argv=None):
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)
@ -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
@ -337,5 +317,6 @@ def main(argv=None):
else: else:
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())
Loading…
Cancel
Save