SupyMisc: make 'supyplugins' command smarter

- It can now call on folder and filenames (e.g. 'supyplugins SupyMisc/plugin.py'),
  checking if such file exists and returning its URL if it does.
- Add tests accordingly.
This commit is contained in:
GLolol 2014-11-29 12:50:55 -08:00
parent 96a4615c81
commit c541445c1e
2 changed files with 35 additions and 3 deletions

View File

@ -28,6 +28,8 @@
### ###
import random import random
import re
import json
try: try:
from itertools import izip from itertools import izip
except ImportError: except ImportError:
@ -176,11 +178,32 @@ class SupyMisc(callbacks.Plugin):
irc.reply(len(world.ircs)) irc.reply(len(world.ircs))
netcount = wrap(netcount) netcount = wrap(netcount)
def supyplugins(self, irc, msg, args): def supyplugins(self, irc, msg, args, text):
"""takes no arguments. """takes no arguments.
Returns a URL for the source of this plugin. """ Returns a URL for the source of this plugin. """
irc.reply("SupyPlugins source is available at: https://github.com/GLolol/SupyPlugins") base = 'https://github.com/GLolol/SupyPlugins'
supyplugins = wrap(supyplugins) if not text:
irc.reply(format("SupyPlugins source is available at: %u", base))
return
apiurl = 'https://api.github.com/repos/GLolol/SupyPlugins/contents/'
text = re.sub("\/+", "/", text)
try:
text, line = text.split("#")
except ValueError:
line = ''
try:
fd = utils.web.getUrl(apiurl + text)
data = json.loads(fd.decode("utf-8"))
if type(data) == list:
s = "%s/tree/master/%s" % (base, text)
else:
s = data['html_url']
except (AttributeError, utils.web.Error):
irc.error('Not found.', Raise=True)
if line:
s += "#%s" % line
irc.reply(format('%u', s))
supyplugins = wrap(supyplugins, [additional('text')])
def chancount(self, irc, msg, args): def chancount(self, irc, msg, args):
"""takes no arguments. """takes no arguments.

View File

@ -64,4 +64,13 @@ class SupyMiscTestCase(PluginTestCase):
self.assertResponse('mreplace hi,there hello,ok hmm, hi there everyone', self.assertResponse('mreplace hi,there hello,ok hmm, hi there everyone',
'hmm, hello ok everyone') 'hmm, hello ok everyone')
def testSPsourceFetch(self):
self.assertNotError('supyplugins')
self.assertRegexp('supyplugins SupyMisc//plugin.py', \
'.*?blob\/master\/SupyMisc\/plugin\.py.*?')
self.assertRegexp('supyplugins SupyMisc/', \
'.*?tree\/master\/SupyMisc.*?')
self.assertError('supyplugins asfswfuiahfawfawefawe')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: