improve cvs methods text decoding

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-08-26 10:07:58 -04:00
parent 9093d0d691
commit f69ec62f08
1 changed files with 21 additions and 30 deletions

View File

@ -22,9 +22,7 @@ class CvsCommit(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs ci -m %r %r" % (vargs['msg'], path) cmd = "cvs ci -m %r %r" % (vargs['msg'], path)
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8
lines = data.split('\n')
if status == 0: if status == 0:
for line in lines: for line in lines:
@ -55,14 +53,13 @@ class CvsStatus(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs status %r" % path cmd = "cvs status %r" % path
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8
if status != 0: if status != 0:
w.set_error("Problems with CVS status: %d" % status) w.set_error("Problems with CVS status: %d" % status)
return return
lines = data.split('\n') lines = out.split('\n')
if lines[0].startswith('cvs status: nothing known about '): if lines[0].startswith('cvs status: nothing known about '):
w.set_error('File is not under CVS control') w.set_error('File is not under CVS control')
@ -118,9 +115,8 @@ class CvsLog(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs log %r" % path cmd = "cvs log %r" % path
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8 w.application.data_buffer("*Log*", out, switch_to=True)
w.application.data_buffer("*Log*", data, switch_to=True)
w.set_error("cvs log exited with %d" % status) w.set_error("cvs log exited with %d" % status)
class CvsDiff(Method): class CvsDiff(Method):
@ -136,13 +132,12 @@ class CvsDiff(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs diff -u %r" % path cmd = "cvs diff -u %r" % path
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8
if status == 0: if status == 0:
w.set_error("No difference found") w.set_error("No difference found")
else: else:
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff') w.application.data_buffer("*Diff*", out, switch_to=True, modename='diff')
w.set_error("Differences were found") w.set_error("Differences were found")
class CvsDiff2(Method): class CvsDiff2(Method):
'''diff the current file's contents with a version in CVS''' '''diff the current file's contents with a version in CVS'''
@ -165,13 +160,12 @@ class CvsDiff2(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs diff -r %s -u %r" % (rev, path) cmd = "cvs diff -r %s -u %r" % (rev, path)
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8
if status == 0: if status == 0:
w.set_error("No difference found") w.set_error("No difference found")
else: else:
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff') w.application.data_buffer("*Diff*", out, switch_to=True, modename='diff')
w.set_error("Differences were found") w.set_error("Differences were found")
class CvsDiff3(Method): class CvsDiff3(Method):
'''diff the current file with the version in CVS''' '''diff the current file with the version in CVS'''
@ -199,13 +193,12 @@ class CvsDiff3(Method):
path = path[len(cwd):] path = path[len(cwd):]
cmd = "cvs diff -r %s -r %s -u %r" % (rev1, rev2, path) cmd = "cvs diff -r %s -r %s -u %r" % (rev1, rev2, path)
(status, data) = commands.getstatusoutput(cmd) status, out, err = util.communicate(cmd)
status = status >> 8
if status == 0: if status == 0:
w.set_error("No difference found") w.set_error("No difference found")
else: else:
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff') w.application.data_buffer("*Diff*", out, switch_to=True, modename='diff')
w.set_error("Differences were found") w.set_error("Differences were found")
class CvsBlame(Method): class CvsBlame(Method):
@ -228,20 +221,21 @@ class CvsBlame(Method):
return return
cmd = self._get_cmd(w, **vargs) cmd = self._get_cmd(w, **vargs)
pipe = Popen(cmd, stdout=PIPE, stderr=PIPE) status, out, err = util.communicate(cmd, stderr=True, shell=False)
linetokens = [] linetokens = []
max_rev = 0 max_rev = 0
max_user = 0 max_user = 0
for line in pipe.stdout: for line in out.split('\n'):
if not line:
continue
m = self.line_re.match(line) m = self.line_re.match(line)
if not m: if not m:
raise Exception, line raise Exception(repr(line))
(rev, user, date, content) = m.groups() (rev, user, date, content) = m.groups()
max_rev = max(max_rev, len(rev)) max_rev = max(max_rev, len(rev))
max_user = max(max_user, len(user)) max_user = max(max_user, len(user))
linetokens.append([rev, user, date, content, []]) linetokens.append([rev, user, date, content, []])
status = pipe.wait() >> 8
lines = [x[3] for x in linetokens] lines = [x[3] for x in linetokens]
if w.mode.grammar: if w.mode.grammar:
@ -266,7 +260,6 @@ class CvsBlame(Method):
lines.append('%s %s' % (prefix, suffix)) lines.append('%s %s' % (prefix, suffix))
data = ''.join(lines) data = ''.join(lines)
status = pipe.wait() >> 8
if status == 0: if status == 0:
w.application.color_data_buffer("*Blame*", data, switch_to=True) w.application.color_data_buffer("*Blame*", data, switch_to=True)
else: else:
@ -303,13 +296,11 @@ class CvsRevView(Method):
return return
cmd = self._get_cmd(w, **vargs) cmd = self._get_cmd(w, **vargs)
pipe = Popen(cmd, stdout=PIPE, stderr=PIPE)
name = self._get_name(w, **vargs) name = self._get_name(w, **vargs)
data = pipe.stdout.read()
status = pipe.wait() >> 8
mname = w.mode.name.lower() mname = w.mode.name.lower()
status, out, err = util.communicate(cmd, stderr=True, shell=False)
w.application.data_buffer(name, data, switch_to=True, modename=mname) w.application.data_buffer(name, out, switch_to=True, modename=mname)
class CvsDateView(CvsRevView): class CvsDateView(CvsRevView):
'''show blame output for the current version in CVS''' '''show blame output for the current version in CVS'''