diff --git a/plugins/Sourceforge.py b/plugins/Sourceforge.py
index 9645d0c0b..1ec25895a 100644
--- a/plugins/Sourceforge.py
+++ b/plugins/Sourceforge.py
@@ -118,7 +118,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
_statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4}
_projectURL = 'http://sourceforge.net/projects/'
- _trackerURL = 'https://sourceforge.net/support/tracker.php?aid='
+ _trackerURL = 'http://sourceforge.net/support/tracker.php?aid='
def __init__(self):
callbacks.PrivmsgCommandAndRegexp.__init__(self)
self.__class__.sf = self.__class__.sourceforge
@@ -242,9 +242,27 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
return
irc.reply(self._getTrackerList(url))
+ _totbugs = re.compile(r'Bugs\s+?\( ([^<]+)', re.S | re.I)
+ def _getNumBugs(self, project):
+ text = webutils.getUrl('%s%s' % (self._projectURL, project))
+ m = self._totbugs.search(text)
+ if m:
+ return m.group(1)
+ else:
+ return ''
+
+ _totrfes = re.compile(r'Feature Requests\s+?\( ([^<]+)',
+ re.S | re.I)
+ def _getNumRfes(self, project):
+ text = webutils.getUrl('%s%s' % (self._projectURL, project))
+ m = self._totrfes.search(text)
+ if m:
+ return m.group(1)
+ else:
+ return ''
+
# TODO: consolidate total* into one command which takes options for all
# the viable statistics that can be snarfed from the project page
- _totbugs = re.compile(r'Bugs\s+?\( ([^<]+)', re.S | re.I)
def totalbugs(self, irc, msg, args):
"""[]
@@ -255,13 +273,28 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
project = project or self.registryValue('defaultProject', msg.args[0])
if not project:
raise callbacks.ArgumentError
- text = webutils.getUrl(''.join([self._projectURL, project]))
- m = self._totbugs.search(text)
- if m:
- irc.reply(m.group(1))
+ total = self._getNumBugs(project)
+ if total:
+ irc.reply(total)
else:
irc.error('Could not find bug statistics.')
+ def totalrfes(self, irc, msg, args):
+ """[]
+
+ Returns a count of the open/total RFEs. is not needed if a
+ default project is set.
+ """
+ project = privmsgs.getArgs(args, required=0, optional=1)
+ project = project or self.registryValue('defaultProject', msg.args[0])
+ if not project:
+ raise callbacks.ArgumentError
+ total = self._getNumRfes(project)
+ if total:
+ irc.reply(total)
+ else:
+ irc.error('Could not find RFE statistics.')
+
_rfeLink = re.compile(r'"([^"]+)">RFE')
def rfes(self, irc, msg, args):
"""[--{any,open,closed,deleted,pending}] []
@@ -296,24 +329,34 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
return
irc.reply(self._getTrackerList(url))
- _totrfes = re.compile(r'Feature Requests\s+?\( ([^<]+)',
- re.S | re.I)
- def totalrfes(self, irc, msg, args):
- """[]
+ def fight(self, irc, msg, args):
+ """[--{bugs,rfes}] [--{open,closed}]
- Returns a count of the open/total RFEs. is not needed if a
- default project is set.
+ Returns the projects, in order, from greatest number of bugs to least.
+ Defaults to bugs and open.
"""
- project = privmsgs.getArgs(args, required=0, optional=1)
- project = project or self.registryValue('defaultProject', msg.args[0])
- if not project:
- raise callbacks.ArgumentError
- text = webutils.getUrl(''.join([self._projectURL, project]))
- m = self._totrfes.search(text)
- if m:
- irc.reply(m.group(1))
- else:
- irc.error('Could not find RFE statistics.')
+ search = self._getNumBugs
+ type = 0
+ (optlist, rest) = getopt.getopt(args, '',
+ ['bugs', 'rfes', 'open', 'closed'])
+ for (option, _) in optlist:
+ if option == '--bugs':
+ search = self._getNumBugs
+ if option == '--rfes':
+ search = self._getNumRfes
+ if option == '--open':
+ type = 0
+ if option == '--closed':
+ type = 1
+ results = []
+ for proj in args:
+ num = search(proj)
+ if num:
+ results.append((int(num.split('/')[type].split()[0]), proj))
+ results.sort()
+ results.reverse()
+ s = ', '.join(['\'%s\': %s' % (s, i) for (i, s) in results])
+ irc.reply(s)
def sfSnarfer(self, irc, msg, match):
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \
diff --git a/test/test_Sourceforge.py b/test/test_Sourceforge.py
index d86266586..0f53b0309 100644
--- a/test/test_Sourceforge.py
+++ b/test/test_Sourceforge.py
@@ -176,4 +176,17 @@ if network:
self.assertError('totalbugs lkjfad')
self.assertError('totalrfes lkjfad')
+ def testFight(self):
+ self.assertRegexp('fight gaim opengaim',
+ r'\'(open|)gaim\': \d+, \'(open|)gaim\': \d+')
+ self.assertRegexp('fight --rfes gaim opengaim',
+ r'\'(open|)gaim\': \d+, \'(open|)gaim\': \d+')
+ self.assertRegexp('fight --closed gaim opengaim',
+ r'\'(open|)gaim\': \d+, \'(open|)gaim\': \d+')
+ m = self.getMsg('fight --bugs gaim opengaim')
+ n = self.getMsg('fight --open gaim opengaim')
+ o = self.getMsg('fight gaim opengaim')
+ self.assertEqual(m, o)
+ self.assertEqual(n, o)
+
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: