--- a/plugin.py Wed Nov 21 00:22:32 2018 +0800
+++ b/plugin.py Wed Nov 21 01:27:49 2018 +0800
from supybot.commands import *
- fd = os.popen('HGPLAIN=1 %s %s' % (self.path, args))
+ with open(os.devnull) as null:
+ p = subprocess.Popen([self.path] + args, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, stdin=null,
+ env={'HGPLAIN': '1', 'HGENCODING': 'UTF-8'})
+ out, err = p.communicate()
+ return (out.decode('utf-8'), err.decode('utf-8'))
class Mercurial(callbacks.Plugin):
"""Add the help for "@plugin help Mercurial" here
out[1] = ircutils.bold(out[1])
- if out and out[0].startswith('Mercurial Distributed SCM'):
- out = ['"%s": unknown command' % cmd]
- out = self.hg.run('help ' + cmd)
+ out, err = self.hg.run(['help', cmd])
+ irc.reply(err.splitlines()[0])
hghelp = wrap(hghelp, ['text'])
- def changelog(self, repo, rev):
+ def changelog(self, irc, repo, rev):
tmpl = '{rev}:{node|short}\n{date|age}\n{author|person}\n{files}\n{desc}'
- cmd = "-R %s log -v --limit 1 --template '%s' -r %s" \
+ out, err = self.hg.run([
+ '-R', repo, 'log', '-r', rev, '-l', '1', '--template', tmpl, '-v'
+ return irc.reply(err.splitlines()[0])
- return ['No result found.']
+ return irc.reply('no changesets found')
lines = [x for x in out.strip().splitlines() if x]
node, date, user, files = lines[:4]
lines = ['%s %s %s' % (node, user, date)] + lines
- baseurl = self.hg.run("-R %s paths default" % repo)
+ baseurl, err = self.hg.run(['-R', repo, 'paths', 'default'])
url = "%s/rev/%s" % (baseurl.strip("\n/"), rev)
- return lines[:2] + [url]
+ irc.replies(lines[:2] + [url])
def crew(self, irc, msg, args, rev):
"gets the changelog message for the given revision of the crew repository"
- cl = self.changelog('/home/brendan/hg/mirror/mercurial/crew', rev)
+ self.changelog(irc, '/home/brendan/hg/mirror/mercurial/crew', rev)
crew = wrap(crew, ['revision'])
def main(self, irc, msg, args, rev):
"gets the changelog message for the given revision of the crew repository"
- cl = self.changelog('/home/hg/repos/hg', rev)
+ self.changelog(irc, '/home/hg/repos/hg', rev)
main = wrap(main, ['revision'])
def bts(self, irc, msg, args, issue):
def glossary(self, irc, msg, args, term):
"""usage: glossary <term>"""
- raw = self.hg.run('help glossary').splitlines()
+ raw, err = self.hg.run(['help', 'glossary'])
+ for line in raw.splitlines():
if not found and line.lower().startswith(' ' + term.lower()):
elif found and not (line.startswith(' ') or not line):
if found and not done and line:
- answer = ['', 'no match found']
- irc.reply(' '.join(answer[1:]))
+ irc.replies(answer[1:], joiner=' ')
+ irc.reply('no match found')
glossary = wrap(glossary, ['text'])