Factoid editing now recognises ~= as <sed>

Displaying info on a factoid (!-factoid) now shows who was the last to edit also
Adding an <alias> factoid should now work when the factoid is new
Package lookup even more rebust, readded source information
This commit is contained in:
Terence Simpson 2008-05-07 03:04:23 +01:00
parent 9fa81121c8
commit 02bcaf5336
2 changed files with 22 additions and 8 deletions

View File

@ -22,6 +22,7 @@ class Apt:
def __init__(self, plugin):
self.aptdir = plugin.registryValue('aptdir')
self.distros = []
self.plugin = plugin
if self.aptdir:
self.distros = [x[:-5] for x in os.listdir(self.aptdir) if x.endswith('.list')]
self.aptcommand = """apt-cache\\
@ -47,10 +48,10 @@ class Apt:
data = commands.getoutput(self.aptfilecommand % (distro, distro, pkg)).split()
if data:
if data[0] == 'sh:': # apt-file isn't installed
plugin.log.error("apt-file is not installed")
self.plugin.log.error("apt-file is not installed")
return "Please use http://packages.ubuntu.com/ to search for files"
if data[0] == 'E:': # No files in the cache dir
plugin.log.error("Please run the 'update_apt_file' script")
self.plugin.log.error("Please run the 'update_apt_file' script")
return "Cache out of date, please contact the administrator"
if len(data) > 5:
return "File %s found in %s (and %d others)" % (pkg, ', '.join(data[:5]), len(data)-5)
@ -89,7 +90,7 @@ class Apt:
parser.feed(p)
p = parser.close()
if type(p) == type(""):
plugin.log.error("apt returned an error, do you have the deb-src URLs in %s.list" % distro)
self.plugin.log.error("apt returned an error, do you have the deb-src URLs in %s.list" % distro)
return "Package lookup faild"
if apt.VersionCompare(maxp['Version'], p['Version']) < 0:
maxp = p
@ -102,12 +103,16 @@ class Apt:
parser = FeedParser.FeedParser()
parser.feed(p)
p = parser.close()
if type(p) == type(""):
self.plugin.log.error("apt returned an error, do you have the deb-src URLs in %s.list" % distro)
return "Package lookup faild"
if apt.VersionCompare(maxp2['Version'], p['Version']) < 0:
maxp2 = p
del parser
archs = ''
if maxp2['Architecture'] not in ('all','any'):
archs = ' (Only available for %s)' % maxp2['Architecture']
if maxp2.has_key('Architecture'):
if maxp2['Architecture'] not in ('all','any'):
archs = ' (Only available for %s)' % maxp2['Architecture']
return("%s (source: %s): %s. In component %s, is %s. Version %s (%s), package size %s kB, installed size %s kB%s" %
(maxp['Package'], maxp['Source'] or maxp['Package'], maxp['Description'].split('\n')[0], component(maxp['Section']),
maxp['Priority'], maxp['Version'], distro, int(maxp['Size'])/1024, maxp['Installed-Size'], archs))

View File

@ -253,7 +253,15 @@ class Encyclopedia(callbacks.Plugin):
else:
factoid.value = "<reply> %s has no aliases" % (factoid.name)
# Author info
cur = db.cursor()
cur.execute("SELECT author, added FROM log WHERE name = %s", factoid.name)
data = cur.fetchall()
factoid.value += " - added by %s on %s" % (factoid.author[:factoid.author.find('!')], factoid.added[:factoid.added.find('.')])
if data:
last_edit = data[len(data)-1]
who = last_edit[0][:last_edit[0].find('!')]
when = last_edit[1][:last_edit[1].find('.')]
factoid.value += " - last edited by %s on %s" % (who, when)
return factoid
def check_aliases(self, channel, factoid):
@ -290,7 +298,6 @@ class Encyclopedia(callbacks.Plugin):
text = self.addressed(recipient, text, irc)
if not text:
return
self.log.info("%s said in %s: %s" % (msg.prefix, msg.args[0], msg.args[1]))
display_info = False
target = msg.args[0]
if target[0] != '#':
@ -315,7 +322,7 @@ class Encyclopedia(callbacks.Plugin):
if lower_text.startswith('search '):
ret = self.search_factoid(lower_text[7:].strip(), channel)
elif (' is ' in lower_text and text[:3] in ('no ', 'no,')) or '<sed>' in lower_text or '=~' in lower_text \
or lower_text.startswith('forget') or lower_text.startswith('unforget'):
or '~=' in lower_text or '<alias>' in lower_text or lower_text.startswith('forget') or lower_text.startswith('unforget'):
if not capab(msg.prefix, 'editfactoids'):
irc.reply("Your edit request has been forwarded to %s. Thank you for your attention to detail" %
self.registryValue('relaychannel'),private=True)
@ -424,6 +431,8 @@ class Encyclopedia(callbacks.Plugin):
text = text.replace('is<sed>','=~',1)
if ' is <sed>' in text:
text = text.replace('is <sed>','=~',1)
if '~=' in text:
text = text.replace('~=','=~',1)
# Split into name and regex
name = text[:text.find('=~')].strip()
regex = text[text.find('=~')+2:].strip()
@ -543,7 +552,7 @@ class Encyclopedia(callbacks.Plugin):
fd = urllib2.urlopen(location)
newDb = fd.read()
fd.close()
fd2 = open(dpath,'w')
fd2 = open(dpath,'w')
fd2.write(newDb)
fd2.close()