some general vc refactors

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-05-10 22:45:16 -04:00
parent e495d8a65f
commit b504d677eb
3 changed files with 29 additions and 13 deletions

View File

@ -1,9 +1,15 @@
from subprocess import Popen, PIPE, STDOUT
from method import Method, Argument
from method.vc import VcBlame
import re
try:
from mercurial import hg, ui
from mercurial import commands as hgc
has_hg = True
except ImportError:
has_hg = False
class HgBlame(VcBlame):
"""Show buffer annotated with hg metadata"""
line_re = re.compile(r'^ *(?P<user>[^ ]+) (?P<rev>\d+) (?P<date>\d{4}-\d{2}-\d{2}): (?P<content>.*)\n$')
@ -21,14 +27,10 @@ class HgLog(Method):
class HgDiff(Method):
"""Diff the current file with the version in Mercurial"""
def _execute(self, w, **vargs):
try:
from mercurial import hg, ui
from mercurial import commands as hgc
except ImportError:
w.set_error("Mecurial is not installed")
if not has_hg:
w.set_error("Mercurial is not installed")
return
if not hasattr(w.buffer, 'path'):
elif not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file")
return
ui_imp = ui.ui(verbose=True)

View File

@ -8,6 +8,11 @@ from method.vc import VcBlame
from method import Method, Argument
if os.system('which svn >/dev/null 2>/dev/null') == 0:
has_svn = True
else:
has_svn = False
class SvnException(Exception):
pass
@ -262,6 +267,9 @@ class SvnBlame(VcBlame):
line_re = re.compile('^ *(?P<rev>\d+) *(?P<user>[a-zA-Z0-9_]+) *(?P<date>[-0-9]+) *(?P<time>[:0-9]+) *(?P<tz>-\d{4}) *\((?P<vdate>[^\)]+)\) (?P<content>.*)\n$')
prefix_fmt = '[b:d:*]%(rev)-4s [c:d:*]%(user)-10s [b:d:*]%(date)10s[d:d:*]'
_is_method = True
pretest_err_msg = 'Subversion is not installed'
def _pretest(self):
return has_svn
def _open_pipe(self, w, **vargs):
cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path)
cmd = ("svn", 'blame', '-v', w.buffer.path)
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)

View File

@ -6,9 +6,12 @@ import lex
class VcException(Exception): pass
class VcBlame(Method):
_is_method = False
line_re = None
prefix_fmt = None
_is_method = False
line_re = None
prefix_fmt = None
pretest_err_msg = None
def _pretest(self):
return True
def _filter(self, line):
m = self.line_re.match(line)
if not m:
@ -17,7 +20,10 @@ class VcBlame(Method):
def _open_pipe(self, w, **vargs):
raise Exception('unimplemented')
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
if not self._pretest():
w.set_error(self.pretest_err_msg)
return
elif not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file")
return