Add Debian.debianize. Add a try:except for webutils usage. Use Raise=True

in a few more places.
This commit is contained in:
James Vega 2004-12-08 03:19:07 +00:00
parent 59b561b0af
commit bda9e9144c
2 changed files with 37 additions and 18 deletions

View File

@ -126,7 +126,7 @@ class Debian(callbacks.Privmsg,
raise callbacks.ArgumentError raise callbacks.ArgumentError
if optlist and glob: if optlist and glob:
irc.error('You must specify either a glob or a regexp/exact ' irc.error('You must specify either a glob or a regexp/exact '
'search, but not both.') 'search, but not both.', Raise=True)
for (option, arg) in optlist: for (option, arg) in optlist:
if option == 'exact': if option == 'exact':
regexp = arg.lstrip('/') regexp = arg.lstrip('/')
@ -139,8 +139,7 @@ class Debian(callbacks.Privmsg,
try: try:
re_obj = re.compile(regexp, re.I) re_obj = re.compile(regexp, re.I)
except re.error, e: except re.error, e:
irc.error("Error in regexp: %s" % e) irc.error("Error in regexp: %s" % e, Raise=True)
return
if self.registryValue('pythonZgrep'): if self.registryValue('pythonZgrep'):
fd = gzip.open(self.contents) fd = gzip.open(self.contents)
r = imap(lambda tup: tup[0], r = imap(lambda tup: tup[0],
@ -153,17 +152,15 @@ class Debian(callbacks.Privmsg,
except TypeError: except TypeError:
# We're on Windows. # We're on Windows.
irc.error('This command won\'t work on this platform. ' irc.error('This command won\'t work on this platform. '
'If you think it should (i.e., you know that ' 'If you think it should (i.e., you know that you '
'you have a zgrep binary somewhere) then file ' 'have a zgrep binary somewhere) then file a bug '
'a bug about it at http://supybot.sf.net/ .') 'about it at http://supybot.sf.net/ .', Raise=True)
return
packages = sets.Set() # Make packages unique packages = sets.Set() # Make packages unique
try: try:
for line in r: for line in r:
if len(packages) > 100: if len(packages) > 100:
irc.error('More than 100 packages matched, ' irc.error('More than 100 packages matched, '
'please narrow your search.') 'please narrow your search.', Raise=True)
return
try: try:
if hasattr(line, 'group'): # we're actually using if hasattr(line, 'group'): # we're actually using
line = line.group(0) # pythonZgrep :( line = line.group(0) # pythonZgrep :(
@ -207,9 +204,7 @@ class Debian(callbacks.Privmsg,
try: try:
html = webutils.getUrl(url) html = webutils.getUrl(url)
except webutils.WebError, e: except webutils.WebError, e:
irc.error('I couldn\'t reach the search page (%s).' % e) irc.error('I couldn\'t reach the search page (%s).' % e,Raise=True)
return
if 'is down at the moment' in html: if 'is down at the moment' in html:
irc.error('Packages.debian.org is down at the moment. ' irc.error('Packages.debian.org is down at the moment. '
'Please try again later.', Raise=True) 'Please try again later.', Raise=True)
@ -270,8 +265,7 @@ class Debian(callbacks.Privmsg,
try: try:
fd = webutils.getUrlFd('http://incoming.debian.org/') fd = webutils.getUrlFd('http://incoming.debian.org/')
except webutils.WebError, e: except webutils.WebError, e:
irc.error(str(e)) irc.error(str(e), Raise=True)
return
for line in fd: for line in fd:
m = self._incomingRe.search(line) m = self._incomingRe.search(line)
if m: if m:
@ -300,7 +294,7 @@ class Debian(callbacks.Privmsg,
fd = webutils.getUrlFd( fd = webutils.getUrlFd(
'http://packages.debian.org/unstable/newpkg_%s' % section) 'http://packages.debian.org/unstable/newpkg_%s' % section)
except webutils.WebError, e: except webutils.WebError, e:
irc.error(str(e)) irc.error(str(e), Raise=True)
packages = [] packages = []
for line in fd: for line in fd:
m = self._newpkgre.search(line) m = self._newpkgre.search(line)
@ -330,10 +324,13 @@ class Debian(callbacks.Privmsg,
Returns a description of the bug with bug id <num>. Returns a description of the bug with bug id <num>.
""" """
url = 'http://bugs.debian.org/%s' % bug url = 'http://bugs.debian.org/%s' % bug
text = webutils.getUrl(url) try:
text = webutils.getUrl(url)
except webutils.WebError, e:
irc.error(str(e), Raise=True)
if "There is no record of Bug" in text: if "There is no record of Bug" in text:
irc.error('I could not find a bug report matching that number.') irc.error('I could not find a bug report matching that number.',
return Raise=True)
searches = map(lambda p: p.search(text), self._searches) searches = map(lambda p: p.search(text), self._searches)
sev = self._severity.search(text) sev = self._severity.search(text)
# This section should be cleaned up to ease future modifications # This section should be cleaned up to ease future modifications
@ -351,6 +348,25 @@ class Debian(callbacks.Privmsg,
irc.reply('I was unable to properly parse the BTS page.') irc.reply('I was unable to properly parse the BTS page.')
bug = wrap(bug, [('id', 'bug')]) bug = wrap(bug, [('id', 'bug')])
_dpnRe = re.compile(r'"\+2">([^<]+)</font', re.I)
def debianize(self, irc, msg, args, words):
"""<text>
Turns <text> into a 'debian package name' using
http://www.pigdog.com/features/dpn.html.
"""
url = r'http://www.pigdog.org/cgi_bin/dpn.phtml?name=%s'
try:
text = webutils.getUrl(url % '+'.join(words))
except webutils.WebError, e:
irc.error(str(e), Raise=True)
m = self._dpnRe.search(text)
if m is not None:
irc.reply(m.group(1))
else:
irc.errorPossibleBug('Unable to parse webpage.')
debianize = wrap(debianize, [many('something')])
Class = Debian Class = Debian
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -81,5 +81,8 @@ class DebianTestCase(PluginTestCase):
def testDebincoming(self): def testDebincoming(self):
self.assertNotError('incoming') self.assertNotError('incoming')
def testDebianize(self):
self.assertNotError('debianize supybot')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: