Changeset 35


Ignore:
Timestamp:
Feb 22, 2010 5:19:00 PM (15 years ago)
Author:
retracile
Message:

Mergebot: begin refactoring svn layer, fix some more errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mergebot/trunk/mergebot/svn.py

    r34 r35  
    1010import subprocess
    1111
    12 def shell_quote(self, string):
     12def shell_quote(string):
    1313    """Given a string, escape the characters interpretted by the shell."""
    1414    for char in ["\\", "\"", "$"]:
     
    1818
    1919class SvnLib(object):
     20    """A library to provide a higher-level set of subversion operations."""
    2021    def __init__(self):
    2122        pass
    2223
    2324    def logcmd(self, cmd, logfile):
    24         """Log the cmd string, then execute it, appending its stdout and stderr to
    25         logfile."""
     25        """Log the cmd string, then execute it, appending its stdout and stderr
     26        to logfile."""
    2627        open(logfile, "a").write("%s: %s\n" % (time.asctime(), cmd))
    2728        return os.system("(%s) >>%s 2>&1" % (cmd, logfile))
     
    3334    def does_url_exist_14(self, url):
    3435        """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],
    3738                        stdout=open('/dev/null', 'w'),
    3839                        stderr=open('/dev/null', 'w'))
     
    4546                        stderr=open('/dev/null', 'w'))
    4647
    47     does_url_exist=does_url_exist_14 # default to most compatible form for now
     48    does_url_exist = does_url_exist_14 # default to most compatible form for now
    4849
    4950    def get_branch_info(self, url, logfile):
    5051        """Given a subversion url and a logfile, return (start_revision,
    5152        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")
    5455        branchlog = svncmd.read()
    5556        returnval = svncmd.close()
     
    5859            return None
    5960        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.
    6264        endrev = self.get_rev_from_log(logs[1])
    6365        startrev = self.get_rev_from_log(logs[-2])
     
    6567
    6668    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 use
    68         the provided commit message."""
     69        """Create a branch copying from_url to to_url.  Commit as mergebot, and
     70        use the provided commit message."""
    6971        svncmd = \
    7072            "svn copy --username=mergebot --password=mergebot -m %s %s %s" \
     
    7375
    7476    def delete_branch(self, url, commit_message, logfile):
    75         """This will generate a new revision.  Return the revision number, or -1 on
    76         failure.
     77        """This will generate a new revision.  Return the revision number, or
     78        -1 on failure.
    7779        Assumes that the url exists.  You should call get_branch_info() to
    7880        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 " \
    8083            "-m %s %s 2>>%s" % (shell_quote(commit_message), url, logfile)
    8184        return self._svn_new_rev_command(svncmd)
     
    111114
    112115    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."""
    114118        conflicts = [filename for status, filename in results if 'C' in status]
    115119        return conflicts
    116120
    117121    def commit(self, workingdir, commit_message, logfile):
    118         """Returns newly committed revision number, or None if there was nothing to
    119         commit.  -1 on error."""
     122        """Returns newly committed revision number, or None if there was
     123        nothing to commit.  -1 on error."""
    120124        svncmd = "cd %s && svn commit --no-auth-cache --username=mergebot " \
    121125            "--password=mergebot -m %s 2>>%s" % (workingdir,
     
    124128
    125129    def _svn_new_rev_command(self, svncmd):
    126         """Given an svn command that results in a new revision, return the revision
    127         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."""
    128132        pipe = os.popen(svncmd)
    129133        output = pipe.read()
Note: See TracChangeset for help on using the changeset viewer.