- Timestamp:
- Feb 22, 2010 5:19:00 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mergebot/trunk/mergebot/svn.py
r34 r35 10 10 import subprocess 11 11 12 def shell_quote(s elf, string):12 def shell_quote(string): 13 13 """Given a string, escape the characters interpretted by the shell.""" 14 14 for char in ["\\", "\"", "$"]: … … 18 18 19 19 class SvnLib(object): 20 """A library to provide a higher-level set of subversion operations.""" 20 21 def __init__(self): 21 22 pass 22 23 23 24 def logcmd(self, cmd, logfile): 24 """Log the cmd string, then execute it, appending its stdout and stderr to25 logfile."""25 """Log the cmd string, then execute it, appending its stdout and stderr 26 to logfile.""" 26 27 open(logfile, "a").write("%s: %s\n" % (time.asctime(), cmd)) 27 28 return os.system("(%s) >>%s 2>&1" % (cmd, logfile)) … … 33 34 def does_url_exist_14(self, url): 34 35 """Given a subversion url return true if it exists, false otherwise.""" 35 return not subprocess.call(['svn', 'log', '--limit=1', '--non-interactive',36 url],36 return not subprocess.call(['svn', 'log', '--limit=1', 37 '--non-interactive', url], 37 38 stdout=open('/dev/null', 'w'), 38 39 stderr=open('/dev/null', 'w')) … … 45 46 stderr=open('/dev/null', 'w')) 46 47 47 does_url_exist =does_url_exist_14 # default to most compatible form for now48 does_url_exist = does_url_exist_14 # default to most compatible form for now 48 49 49 50 def get_branch_info(self, url, logfile): 50 51 """Given a subversion url and a logfile, return (start_revision, 51 52 end_revision) or None if it does not exist.""" 52 svncmd = os.popen("svn log --stop-on-copy --non-interactive %s 2>>%s" %\53 (url, logfile), "r")53 svncmd = os.popen("svn log --stop-on-copy --non-interactive %s 2>>%s" \ 54 % (url, logfile), "r") 54 55 branchlog = svncmd.read() 55 56 returnval = svncmd.close() … … 58 59 return None 59 60 logs = branchlog.split("-"*72 + "\n") 60 # If there have been no commits on the branch since it was created, there 61 # will only be one revision listed.... but the log will split into 3 parts. 61 # If there have been no commits on the branch since it was created, 62 # there will only be one revision listed.... but the log will split 63 # into 3 parts. 62 64 endrev = self.get_rev_from_log(logs[1]) 63 65 startrev = self.get_rev_from_log(logs[-2]) … … 65 67 66 68 def create_branch(self, from_url, to_url, commit_message, logfile): 67 """Create a branch copying from_url to to_url. Commit as mergebot, and use68 the provided commit message."""69 """Create a branch copying from_url to to_url. Commit as mergebot, and 70 use the provided commit message.""" 69 71 svncmd = \ 70 72 "svn copy --username=mergebot --password=mergebot -m %s %s %s" \ … … 73 75 74 76 def delete_branch(self, url, commit_message, logfile): 75 """This will generate a new revision. Return the revision number, or -1 on76 failure.77 """This will generate a new revision. Return the revision number, or 78 -1 on failure. 77 79 Assumes that the url exists. You should call get_branch_info() to 78 80 determine that first""" 79 svncmd = "svn rm --no-auth-cache --username=mergebot --password=mergebot " \ 81 svncmd = "svn rm --no-auth-cache " \ 82 "--username=mergebot --password=mergebot " \ 80 83 "-m %s %s 2>>%s" % (shell_quote(commit_message), url, logfile) 81 84 return self._svn_new_rev_command(svncmd) … … 111 114 112 115 def conflicts_from_merge_results(self, results): 113 "Given the output from merge, return a list of files that had conflicts." 116 """Given the output from merge, return a list of files that had 117 conflicts.""" 114 118 conflicts = [filename for status, filename in results if 'C' in status] 115 119 return conflicts 116 120 117 121 def commit(self, workingdir, commit_message, logfile): 118 """Returns newly committed revision number, or None if there was nothing to119 commit. -1 on error."""122 """Returns newly committed revision number, or None if there was 123 nothing to commit. -1 on error.""" 120 124 svncmd = "cd %s && svn commit --no-auth-cache --username=mergebot " \ 121 125 "--password=mergebot -m %s 2>>%s" % (workingdir, … … 124 128 125 129 def _svn_new_rev_command(self, svncmd): 126 """Given an svn command that results in a new revision, return the revision127 number, or -1 on error."""130 """Given an svn command that results in a new revision, return the 131 revision number, or -1 on error.""" 128 132 pipe = os.popen(svncmd) 129 133 output = pipe.read()
Note: See TracChangeset
for help on using the changeset viewer.