Download:
child 10:198302d7eeaf
parent 8:28e93659ea08
9:84423e165ad2
Brendan Cully <brendan@kublai.com>, Wed, 19 Oct 2011 17:10:10 -0500
Add glossary command

2 файлов изменено, 48 вставок(+), 9 удалений(-) [+]
plugin.py file | annotate | diff | comparison | revisions
test.py file | annotate | diff | comparison | revisions
--- a/plugin.py Tue Sep 14 12:27:53 2010 -0500
+++ b/plugin.py Wed Oct 19 17:10:10 2011 -0500
@@ -107,6 +107,17 @@
state.args.append(args.pop(0))
addConverter('revision', revparse)
+class Hg(object):
+ def __init__(self, path):
+ self.path = path
+
+ def run(self, args):
+ fd = os.popen('%s %s' % (self.path, args))
+ out = fd.read()
+ fd.close()
+
+ return out
+
class Mercurial(callbacks.Plugin):
"""Add the help for "@plugin help Mercurial" here
This should describe *how* to use this plugin."""
@@ -115,6 +126,7 @@
def __init__(self, irc):
super(Mercurial, self).__init__(irc)
self.path = self.registryValue('path')
+ self.hg = Hg(self.path)
def hghelp(self, irc, msg, args, cmd):
"""runs hg help with the given args"""
@@ -138,20 +150,16 @@
out = ['"%s": unknown command' % cmd]
return out
- fd = os.popen('%s help %s' % (self.path, cmd))
- out = fd.read()
- fd.close()
+ out = self.hg.run('help ' + cmd)
irc.replies(fmt(out))
hghelp = wrap(hghelp, ['text'])
def changeLog(self, repo, rev):
tmpl = '{rev}:{node|short}\n{date|age}\n{author|person}\n{files}\n{desc}'
- cmd = "%s -R %s log -v --limit 1 --template '%s' -r %s" \
- % (self.path, repo, tmpl, rev)
- fd = os.popen(cmd)
- out = fd.read()
- fd.close()
+ cmd = "-R %s log -v --limit 1 --template '%s' -r %s" \
+ % (repo, tmpl, rev)
+ out = self.hg.run(cmd)
if not out:
return ['No result found.']
@@ -198,4 +206,25 @@
irc.reply(link)
bts = wrap(bts, ['text'])
+ def glossary(self, irc, msg, args, term):
+ """usage: glossary <term>"""
+ raw = self.hg.run('help glossary').splitlines()
+ found = False
+ done = False
+ answer = []
+ for line in raw:
+ if not found and line.lower().startswith(' ' + term.lower()):
+ found = True
+ elif found and not (line.startswith(' ') or not line):
+ done = True
+
+ line = line.strip()
+ if found and not done and line:
+ answer.append(line)
+
+ if not answer:
+ answer = ['', 'no match found']
+ irc.reply(' '.join(answer[1:]))
+ glossary = wrap(glossary, ['text'])
+
Class = Mercurial
--- a/test.py Tue Sep 14 12:27:53 2010 -0500
+++ b/test.py Wed Oct 19 17:10:10 2011 -0500
@@ -33,7 +33,17 @@
class MercurialTestCase(PluginTestCase):
plugins = ('Mercurial',)
+ def setUp(self):
+ ChannelPluginTestCase.setUp(self)
+ print 'foo'
+
def testHghelp(self):
- self.assertNotError('hghelp')
+ self.assertNotError('hghelp foo')
+
+ def testGlossary(self):
+ self.assertNotError('glossary foo')
+ m = self.getMsg('glossary foo')
+ print m
+ self.assertError('glossary foo')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: