commands.wrap update

This commit is contained in:
James Vega 2004-10-17 18:01:58 +00:00
parent 284cf06a67
commit 4b86bf5eaf
2 changed files with 41 additions and 38 deletions

View File

@ -47,7 +47,7 @@ import rssparser
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.plugins as plugins import supybot.plugins as plugins
from supybot.commands import wrap from supybot.commands import *
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
@ -125,6 +125,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
_regexps =(_resolution, _submitDate, _submitted, _assigned, _priority, _regexps =(_resolution, _submitDate, _submitted, _assigned, _priority,
_status) _status)
_statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4} _statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4}
_optDict = {'any':'', 'open':'', 'closed':'', 'deleted':'', 'pending':''}
_projectURL = 'http://sourceforge.net/projects/' _projectURL = 'http://sourceforge.net/projects/'
_trackerURL = 'http://sourceforge.net/support/tracker.php?aid=' _trackerURL = 'http://sourceforge.net/support/tracker.php?aid='
@ -230,42 +231,44 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
except webutils.WebError, e: except webutils.WebError, e:
raise TrackerError, str(e) raise TrackerError, str(e)
def bug(self, irc, msg, args): def bug(self, irc, msg, args, id):
"""<id> """<id>
Returns a description of the bug with id <id>. Really, this is Returns a description of the bug with id <id>. Really, this is
just a wrapper for the tracker command; it won't even complain if the just a wrapper for the tracker command; it won't even complain if the
<id> you give isn't a bug. <id> you give isn't a bug.
""" """
self.tracker(irc, msg, args) self.tracker(irc, msg, args, id)
bug = wrap(bug, [('id', 'bug')])
def patch(self, irc, msg, args): def patch(self, irc, msg, args, id):
"""<id> """<id>
Returns a description of the patch with id <id>. Really, this is Returns a description of the patch with id <id>. Really, this is
just a wrapper for the tracker command; it won't even complain if the just a wrapper for the tracker command; it won't even complain if the
<id> you give isn't a patch. <id> you give isn't a patch.
""" """
self.tracker(irc, msg, args) self.tracker(irc, msg, args, id)
patch = wrap(patch, [('id', 'patch')])
def rfe(self, irc, msg, args): def rfe(self, irc, msg, args, id):
"""<id> """<id>
Returns a description of the rfe with id <id>. Really, this is Returns a description of the rfe with id <id>. Really, this is
just a wrapper for the tracker command; it won't even complain if the just a wrapper for the tracker command; it won't even complain if the
<id> you give isn't an rfe. <id> you give isn't an rfe.
""" """
self.tracker(irc, msg, args) self.tracker(irc, msg, args, id)
rfe = wrap(rfe, [('id', 'rfe')])
def tracker(self, irc, msg, args): def tracker(self, irc, msg, args, id):
"""<id> """<id>
Returns a description of the tracker with id <id> and the corresponding Returns a description of the tracker with id <id> and the corresponding
url. url.
""" """
num = privmsgs.getArgs(args)
try: try:
url = '%s%s' % (self._trackerURL, num) url = '%s%s' % (self._trackerURL, id)
resp = self._getTrackerInfo(url) resp = self._getTrackerInfo(url)
if resp is None: if resp is None:
irc.error('Invalid Tracker page snarfed: %s' % url) irc.error('Invalid Tracker page snarfed: %s' % url)
@ -273,17 +276,15 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
irc.reply('%s <%s>' % (resp, url)) irc.reply('%s <%s>' % (resp, url))
except TrackerError, e: except TrackerError, e:
irc.error(str(e)) irc.error(str(e))
tracker = wrap(tracker, [('id', 'tracker')])
_trackerLink = {'bugs': re.compile(r'"([^"]+)">Bugs'), _trackerLink = {'bugs': re.compile(r'"([^"]+)">Bugs'),
'rfes': re.compile(r'"([^"]+)">RFE'), 'rfes': re.compile(r'"([^"]+)">RFE'),
'patches': re.compile(r'"([^"]+)">Patches'), 'patches': re.compile(r'"([^"]+)">Patches'),
} }
def _trackers(self, irc, args, msg, tracker): def _trackers(self, irc, args, msg, optlist, project, tracker):
(optlist, rest) = getopt.getopt(args, '', self._statusOpt.keys())
project = privmsgs.getArgs(rest, required=0, optional=1)
status = 'open' status = 'open'
for (option, _) in optlist: for (option, _) in optlist:
option = option.lstrip('-').lower()
if option in self._statusOpt: if option in self._statusOpt:
status = option status = option
try: try:
@ -307,43 +308,44 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
return return
irc.reply(self._getTrackerList(url)) irc.reply(self._getTrackerList(url))
def bugs(self, irc, msg, args): def bugs(self, irc, msg, args, optlist, project):
"""[--{any,open,closed,deleted,pending}] [<project>] """[--{any,open,closed,deleted,pending}] [<project>]
Returns a list of the most recent bugs filed against <project>. Returns a list of the most recent bugs filed against <project>.
<project> is not needed if there is a default project set. Search <project> is not needed if there is a default project set. Search
defaults to open bugs. defaults to open bugs.
""" """
self._trackers(irc, args, msg, 'bugs') self._trackers(irc, args, msg, optlist, project, 'bugs')
bugs = wrap(bugs, [getopts(_optDict), additional('text', '')])
def rfes(self, irc, msg, args): def rfes(self, irc, msg, args, optlist, project):
"""[--{any,open,closed,deleted,pending}] [<project>] """[--{any,open,closed,deleted,pending}] [<project>]
Returns a list of the most recent rfes filed against <project>. Returns a list of the most recent rfes filed against <project>.
<project> is not needed if there is a default project set. Search <project> is not needed if there is a default project set. Search
defaults to open rfes. defaults to open rfes.
""" """
self._trackers(irc, args, msg, 'rfes') self._trackers(irc, args, msg, optlist, project, 'rfes')
rfes = wrap(rfes, [getopts(_optDict), additional('text', '')])
def patches(self, irc, msg, args): def patches(self, irc, msg, args, optlist, project):
"""[--{any,open,closed,deleted,pending}] [<project>] """[--{any,open,closed,deleted,pending}] [<project>]
Returns a list of the most recent patches filed against <project>. Returns a list of the most recent patches filed against <project>.
<project> is not needed if there is a default project set. Search <project> is not needed if there is a default project set. Search
defaults to open patches. defaults to open patches.
""" """
self._trackers(irc, args, msg, 'patches') self._trackers(irc, args, msg, optlist, project, 'patches')
patches = wrap(patches, [getopts(_optDict), additional('text', '')])
_intRe = re.compile(r'(\d+)') _intRe = re.compile(r'(\d+)')
_percentRe = re.compile(r'([\d.]+%)') _percentRe = re.compile(r'([\d.]+%)')
def stats(self, irc, msg, args): def stats(self, irc, msg, args, project):
"""[<project>] """[<project>]
Returns the current statistics for <project>. <project> is not needed Returns the current statistics for <project>. <project> is not needed
if there is a default project set. if there is a default project set.
""" """
project = privmsgs.getArgs(args, optional=1, required=0)
project = project.lower() # To make sure it's the UNIX name.
url = 'http://sourceforge.net/' \ url = 'http://sourceforge.net/' \
'export/rss2_projsummary.php?project=' + project 'export/rss2_projsummary.php?project=' + project
results = rssparser.parse(url) results = rssparser.parse(url)
@ -383,7 +385,6 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
(x.patchesOpen, x.patchesTotal) = gets(self._intRe, title) (x.patchesOpen, x.patchesTotal) = gets(self._intRe, title)
elif 'Tracker: Feature' in title: elif 'Tracker: Feature' in title:
(x.rfesOpen, x.rfesTotal) = gets(self._intRe, title) (x.rfesOpen, x.rfesTotal) = gets(self._intRe, title)
irc.reply('%s has %s, ' irc.reply('%s has %s, '
'is %s active (ranked %s), ' 'is %s active (ranked %s), '
'has had %s (%s today), ' 'has had %s (%s today), '
@ -396,6 +397,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
utils.nItems('bug', x.bugsOpen, 'open'), x.bugsTotal, utils.nItems('bug', x.bugsOpen, 'open'), x.bugsTotal,
utils.nItems('rfe', x.rfesOpen, 'open'), x.rfesTotal, utils.nItems('rfe', x.rfesOpen, 'open'), x.rfesTotal,
utils.nItems('patch',x.patchesOpen, 'open'), x.patchesTotal)) utils.nItems('patch',x.patchesOpen, 'open'), x.patchesTotal))
stats = wrap(stats, ['lowered'])
_totbugs = re.compile(r'Bugs</a>\s+?\( <b>([^<]+)</b>', re.S | re.I) _totbugs = re.compile(r'Bugs</a>\s+?\( <b>([^<]+)</b>', re.S | re.I)
def _getNumBugs(self, project): def _getNumBugs(self, project):
@ -464,27 +466,26 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
else: else:
irc.error('Could not find RFE statistics.') irc.error('Could not find RFE statistics.')
def fight(self, irc, msg, args): def fight(self, irc, msg, args, optlist, projects):
"""[--{bugs,rfes}] [--{open,closed}] <project name> <project name> """[--{bugs,rfes}] [--{open,closed}] <project name> <project name> \
[<project name> ...]
Returns the projects, in order, from greatest number of bugs to least. Returns the projects, in order, from greatest number of bugs to least.
Defaults to bugs and open. Defaults to bugs and open.
""" """
search = self._getNumBugs search = self._getNumBugs
type = 0 type = 0
(optlist, rest) = getopt.getopt(args, '',
['bugs', 'rfes', 'open', 'closed'])
for (option, _) in optlist: for (option, _) in optlist:
if option == '--bugs': if option == 'bugs':
search = self._getNumBugs search = self._getNumBugs
if option == '--rfes': if option == 'rfes':
search = self._getNumRfes search = self._getNumRfes
if option == '--open': if option == 'open':
type = 0 type = 0
if option == '--closed': if option == 'closed':
type = 1 type = 1
results = [] results = []
for proj in args: for proj in projects:
num = search(proj) num = search(proj)
if num: if num:
results.append((int(num.split('/')[type].split()[0]), proj)) results.append((int(num.split('/')[type].split()[0]), proj))
@ -492,6 +493,8 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
results.reverse() results.reverse()
s = ', '.join(['\'%s\': %s' % (s, i) for (i, s) in results]) s = ', '.join(['\'%s\': %s' % (s, i) for (i, s) in results])
irc.reply(s) irc.reply(s)
fight = wrap(fight, [getopts({'bugs':'','rfes':'','open':'','closed':''}),
many('text')])
def sfSnarfer(self, irc, msg, match): def sfSnarfer(self, irc, msg, match):
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \ r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \

View File

@ -46,7 +46,7 @@ from itertools import islice, ifilter, imap
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.world as world import supybot.world as world
from supybot.commands import wrap from supybot.commands import *
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks