From abdfd2d502a0911268c1da6f8ee10b1576ae97ad Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 16 Mar 2008 23:27:16 +0000 Subject: [PATCH] blarg --HG-- branch : pmacs2 --- method/__init__.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/method/__init__.py b/method/__init__.py index 8238e5b..55a3874 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -1104,6 +1104,80 @@ class FileDiff(Method): else: w.application.data_buffer("*Diff*", errdata, switch_to=True) w.set_error("There was an error: %d exited with status %s" % (pid, status)) + +class SvnCommit(Method): + '''diff the current file with the version in SVN''' + args = [Argument("msg", type=type(""), prompt="Commit Message: ")] + regex = re.compile('^new revision: ([0-9.]+); previous revision: ([0-9.]+)$') + def _execute(self, w, **vargs): + if not hasattr(w.buffer, 'path'): + w.set_error("Buffer has no corresponding file") + return + + cwd = os.getcwd() + os.path.sep + path = w.buffer.path + if path.startswith(cwd): + path = path[len(cwd):] + + cmd = "svn ci -m %r %r" % (vargs['msg'], path) + (status, data) = commands.getstatusoutput(cmd) + status = status >> 8 + lines = data.split('\n') + + try: + if status == 0: + raise Exception + for line in lines: + m = self.regex.match(lines[-1]) + if m: + w.set_error("Committed [%s -> %s]" % (m.group(2), m.group(1))) + return + w.set_error("Up-to-date") + except: + w.set_error("Problems with SVN commit: %d" % status) + w.application.data_buffer("*Commit*", data, switch_to=True) + +class SvnStatus(Method): + column = { + ' ': 'Unmodified', + 'A': 'Added', + 'C': 'Conflicted', + 'D': 'Deleted', + 'I': 'Ignored', + 'M': 'Modified', + 'R': 'Replaced', + 'X': 'External', + '?': 'Unknown', + '!': 'Missing', + '~': 'Obstructed', + } + def _execute(self, w, **vargs): + if not hasattr(w.buffer, 'path'): + w.set_error("Buffer has no corresponding file") + return + + cwd = os.getcwd() + os.path.sep + path = w.buffer.path + if path.startswith(cwd): + path = path[len(cwd):] + cmd = "svn status -v %r" % path + (status, data) = commands.getstatusoutput(cmd) + status = status >> 8 + + if status != 0: + w.set_error("Problems with 'svn status': %d" % status) + return + + c = data[0] + status = self.column.get(c, 'Error (%s)' % c) + fields = data[6:].split() + try: + (rrev, lrev, lauthor, filename) = fields + except: + raise Exception, '%r %r' % (fields, data[6:]) + + w.set_error('%s %s %s/%s [%s]' % (filename, status, rrev, lrev, lauthor)) + class SvnDiff(Method): '''diff the current file with the version in SVN''' def _execute(self, w, **vargs):