Fixy fixy!

This commit is contained in:
Dennis Kaarsemaker
2007-02-10 22:47:18 +01:00
parent e375094603
commit a3481af25c
6 changed files with 121 additions and 114 deletions

View File

@ -351,7 +351,6 @@ class Bugtracker(callbacks.PluginRegexp):
def turlSnarfer(self, irc, msg, match): def turlSnarfer(self, irc, msg, match):
r"(?P<tracker>https?://\S*?)/(Bugs/0*|str.php\?L|show_bug.cgi\?id=|bugreport.cgi\?bug=|(bugs|\+bug)/|ticket/|tracker/|\S*aid=)(?P<bug>\d+)(?P<sfurl>&group_id=\d+&at_id=\d+)?" r"(?P<tracker>https?://\S*?)/(Bugs/0*|str.php\?L|show_bug.cgi\?id=|bugreport.cgi\?bug=|(bugs|\+bug)/|ticket/|tracker/|\S*aid=)(?P<bug>\d+)(?P<sfurl>&group_id=\d+&at_id=\d+)?"
print match
if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]): if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]):
return return
nbugs = msg.tagged('nbugs') nbugs = msg.tagged('nbugs')
@ -380,6 +379,7 @@ class Bugtracker(callbacks.PluginRegexp):
irc.reply("https://devpad.canonical.com/~jamesh/oops.cgi/%s" % oopsid, prefixNick=False) irc.reply("https://devpad.canonical.com/~jamesh/oops.cgi/%s" % oopsid, prefixNick=False)
def get_tracker(self,snarfurl,sfdata): def get_tracker(self,snarfurl,sfdata):
snarfurl = snarfurl.replace('sf.net','sourceforge.net')
snarfhost = snarfurl.replace('http://','').replace('https://','') snarfhost = snarfurl.replace('http://','').replace('https://','')
if '/' in snarfurl: if '/' in snarfurl:
snarfhost = snarfhost[:snarfhost.index('/')] snarfhost = snarfhost[:snarfhost.index('/')]
@ -527,10 +527,10 @@ class Malone(IBugtracker):
try: try:
statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed', 'Needs Info', 'In Progress', 'Confirmed'] statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed', 'Needs Info', 'In Progress', 'Confirmed']
severities = ['Undecided', 'Wishlist', 'Minor', 'Low', 'Normal', 'Medium', 'Major', 'High', 'Critical'] severities = ['Undecided', 'Wishlist', 'Minor', 'Low', 'Normal', 'Medium', 'Major', 'High', 'Critical']
if task1['status'] not in statuses and task2['status'] in statuses: return 1 if task1['status'] not in statuses and task2['status'] in statuses: return -1
if task1['status'] in statuses and task2['status'] not in statuses: return -1 if task1['status'] in statuses and task2['status'] not in statuses: return 1
if task1['importance'] not in severities and task2['importance'] in severities: return 1 if task1['importance'] not in severities and task2['importance'] in severities: return -1
if task1['importance'] in severities and task2['importance'] not in severities: return -1 if task1['importance'] in severities and task2['importance'] not in severities: return 1
if not (task1['status'] == task2['status']): if not (task1['status'] == task2['status']):
if statuses.index(task1['status']) < statuses.index(task2['status']): if statuses.index(task1['status']) < statuses.index(task2['status']):
return -1 return -1
@ -677,7 +677,6 @@ class Trac(IBugtracker):
severity = l[l.find('>')+1:l.find('</')] severity = l[l.find('>')+1:l.find('</')]
if 'headers="h_owner"' in l: if 'headers="h_owner"' in l:
assignee = l[l.find('>')+1:l.find('</')] assignee = l[l.find('>')+1:l.find('</')]
#print [(id, package, title, severity, status, assignee, "%s/%s" % (self.url, id))]
return [(id, package, title, severity, status, assignee, "%s/%s" % (self.url, id))] return [(id, package, title, severity, status, assignee, "%s/%s" % (self.url, id))]
class WikiForms(IBugtracker): class WikiForms(IBugtracker):
@ -753,13 +752,11 @@ class Sourceforge(IBugtracker):
_sf_url = 'http://sf.net/support/tracker.php?aid=%d' _sf_url = 'http://sf.net/support/tracker.php?aid=%d'
def get_bug(self, id): def get_bug(self, id):
url = self._sf_url % id url = self._sf_url % id
print url
try: try:
bugdata = utils.web.getUrl(url) bugdata = utils.web.getUrl(url)
except Exception, e: except Exception, e:
s = 'Could not parse data returned by %s: %s' % (self.description, e) s = 'Could not parse data returned by %s: %s' % (self.description, e)
raise BugtrackerError, s raise BugtrackerError, s
print bugdata
try: try:
reo = sfre.search(bugdata) reo = sfre.search(bugdata)
status = reo.group('status') status = reo.group('status')

View File

@ -55,7 +55,7 @@ you want to show by default.
To get package lookup working, you need to set the variable To get package lookup working, you need to set the variable
supybot.plugins.encyclopedia.aptdir to the name of a new, empty directory. In supybot.plugins.encyclopedia.aptdir to the name of a new, empty directory. In
this directory, you creae sources.list files for every distrorelease you want to this directory, you create sources.list files for every distrorelease you want to
search. The name of the file is important, since the filename (without the .list search. The name of the file is important, since the filename (without the .list
suffix) is the name that is used to refer to the distrorelease. suffix) is the name that is used to refer to the distrorelease.

View File

@ -1,9 +0,0 @@
#!/usr/bin/python
import sys
sys.path.append('/home/dennis/public_html')
from commoncgi import *
for file in sorted(os.listdir('/home/dennis/public_html/botlogs'),reverse=True)[1:101]:
print '<a href="/botlogs/%s">%s</a><br/>' % (file, file)
send_page('plain.tmpl')

View File

@ -1,19 +1,100 @@
#!/usr/bin/python #!/usr/bin/python
###
# Copyright (c) 2006,2007 Dennis Kaarsemaker
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###
import sqlite import sys
import datetime sys.path.append('/var/www/bots.ubuntulinux.nl')
import cgi, cgitb from commoncgi import *
from math import ceil
import re
cgitb.enable
### Variables
NUM_PER_PAGE=50.0 NUM_PER_PAGE=50.0
datadir = '/home/dennis/ubugtu/data/facts'
default_database = 'ubuntu'
buf = '' databases = [x for x in os.listdir(datadir)]
def out(txt):
global buf
buf += str(txt)
# Initialize
database = default_database
order_by = 'popularity DESC'
page = 0
search = ''
factoids = []
total = 0
# Read POST
if 'db' in form:
database = form['db'].value
if database not in database:
database = default_database
con = sqlite.connect(os.path.join(datadir, database + '.db'))
cur = con.cursor()
try: page = int(form['page'].value)
except: pass
if 'order' in form:
if form['order'].value in ('added DESC', 'added ASC', 'name DESC', 'name ASC', 'popularity DESC','popularity ASC'):
order_by = form['order'].value
if 'search' in form:
search = form['search'].value
# Select factoids
if search:
keys = [x.strip() for x in search.split() if len(x.strip()) >2][:5]
query1 = "SELECT name, value, author, added, popularity FROM facts WHERE name NOT LIKE '%-also' AND ("
query2 = "SELECT COUNT(name) FROM facts WHERE "
bogus = False
for k in keys:
k = k.replace("'","\'")
if bogus:
query1 += ' OR '
query2 += ' OR '
query1 += "name LIKE '%%%s%%' OR VAlUE LIKE '%%%s%%'" % (k, k)
query2 += "name LIKE '%%%s%%' OR VAlUE LIKE '%%%s%%'" % (k, k)
bogus=True
query1 += ') ORDER BY %s LIMIT %d, %d' % (order_by, NUM_PER_PAGE*page, NUM_PER_PAGE)
cur.execute(query1)
factoids = cur.fetchall()
cur.execute(query2)
total = cur.fetchall()[0][0]
else:
cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '<alias>%%' AND name NOT LIKE '%%-also' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE))
factoids = cur.fetchall()
cur.execute("""SELECT COUNT(*) FROM facts WHERE value NOT LIKE '<alias>%%'""")
total = cur.fetchall()[0][0]
# Pagination links
npages = int(math.ceil(total / float(NUM_PER_PAGE)))
print '&middot;'
for i in range(npages):
print '<a href="factoids.cgi?db=%s&search=%s&order=%s&page=%s">%d</a> &middot;' % (database, search, order_by, i, i+1)
print '<br />Order by<br />&middot;';
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'name ASC', 'Name +')
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'name DESC', 'Name -')
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'popularity ASC', 'Popularity +')
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'popularity DESC', 'Popularity -')
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'added ASC', 'Date added +')
print ' <a href="factoids.cgi?db=%s&search=%s&order=%s&page=0">%s</a> &middot;' % (database, search, 'added DESC', 'Date added -')
print '<table cellspacing="0"><tr><th>Factoid</th><th>Value</th><th>Author</th></tr>'
url_re = re.compile('(?P<url>(https?://\S+|www\S+))')
def q(x):
x = str(x).replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('\n','<br />')
return url_re.sub(link, x)
def link(match): def link(match):
url = match.group('url') url = match.group('url')
txt = url txt = url
@ -21,89 +102,23 @@ def link(match):
txt = txt[:20] + '&hellip;' + txt[-10:] txt = txt[:20] + '&hellip;' + txt[-10:]
return '<a href="%s">%s</a>' % (url, txt) return '<a href="%s">%s</a>' % (url, txt)
def q(txt):
txt = str(txt).replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;').replace('\n','<br />').replace('$hr$','<hr />')
# linkify
rx = re.compile('(?P<url>(https?://\S+|www\S+))')
return rx.sub(link, txt)
database = 'ubuntu'
form = cgi.FieldStorage()
if 'db' in form:
database = form['db'].value
try:
page = int(form['page'].value)
except:
page = 0
order_by = 'added DESC'
try:
order_by = form['order'].value
if order_by not in ('added DESC', 'added ASC', 'name DESC', 'name ASC', 'popularity DESC','popularity ASC'):
order_by = 'added DESC'
except:
order_by = 'added DESC'
con = sqlite.connect('/home/dennis/ubugtu/data/facts/%s.db' % database)
cur = con.cursor()
if 'search' not in form:
cur.execute("""SELECT COUNT(*) FROM facts WHERE value NOT LIKE '<alias>%%'""")
num = cur.fetchall()[0][0]
npages = int(ceil(num / float(NUM_PER_PAGE)))
out('&middot;')
for i in range(npages):
out(' <a href="factoids.cgi?db=%s&order=%s&page=%s">%d</a> &middot;' % (database, order_by, i, i+1))
out('<br />Order by<br />&middot;')
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'name ASC', page, 'Name +'))
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'name DESC', page, 'Name -'))
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'popularity ASC', page, 'Popularity +'))
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'popularity DESC', page, 'Popularity -'))
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'added ASC', page, 'Date added +'))
out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database, 'added DESC', page, 'Date added -'))
out('<table cellspacing="0"><tr><th>Factoid</th><th>Value</th><th>Author</th></tr>')
if 'search' in form:
keys = form['search'].value.split()[:5]
ret = {}
for k in keys:
k = k.replace("'","\'")
cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE name LIKE '%%%s%%' OR VAlUE LIKE '%%%s%%'" % (k, k))
res = cur.fetchall()
for r in res:
r0 = r[0]
try:
ret[r][1] += 1
except:
ret[r0] = (r, 1)
keys = sorted(ret.keys(), lambda x, y: cmp(ret[x][1], ret[y][1]))
factoids = []
for k in keys[:50]:
factoids.append(ret[k][0])
else:
cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '<alias>%%' AND name NOT LIKE '%%-also' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE))
factoids = cur.fetchall()
i = 0 i = 0
for f in factoids: for f in factoids:
f = list(f) f = list(f)
f[2] = f[2][:30]
if '.' in f[3]:
f[3] = f[3][:f[3].find('.')]
cur.execute("SELECT value FROM facts WHERE name = %s", f[0] + '-also') cur.execute("SELECT value FROM facts WHERE name = %s", f[0] + '-also')
more = cur.fetchall() more = cur.fetchall()
if len(more): if len(more):
f[1] += ' $hr$' + ' $hr$'.join([x[0] for x in more]) f[1] += ' $hr$' + ' $hr$'.join([x[0] for x in more])
cur.execute("SELECT name FROM facts WHERE value LIKE %s", '<alias> ' + f[0]) cur.execute("SELECT name FROM facts WHERE value LIKE %s", '<alias> ' + f[0])
f[0] += ' \n' + ' \n'.join([x[0] for x in cur.fetchall()]) f[0] += ' \n' + ' \n'.join([x[0] for x in cur.fetchall()])
out('<tr') print '<tr'
if i % 2: out(' class="bg2"') if i % 2: print ' class="bg2"'
i += 1 i += 1
out('><td>%s</td><td>%s</td><td>%s<br />Added on: %s<br />Requested %s times</td>' % tuple([q(x) for x in f])) print '><td>%s</td><td>%s</td><td>%s<br />Added on: %s<br />Requested %s times</td>' % tuple([q(x) for x in f])
out('</table>') print '</table>'
print "Content-Type: text/html; charset=UTF-8" send_page('factoids.tmpl')
print ""
fd = open('factoids.tmpl')
tmpl = fd.read()
fd.close()
print tmpl % (buf)

View File

@ -151,7 +151,7 @@ class Encyclopedia(callbacks.Plugin):
text = text.strip() text = text.strip()
if text.lower() == self.registryValue('prefixchar') + irc.nick.lower(): if text.lower() == self.registryValue('prefixchar') + irc.nick.lower():
return irc.nick.lower() return irc.nick.lower()
if text[0] == self.registryValue('prefixchar'): if len(text) and text[0] == self.registryValue('prefixchar'):
text = text[1:] text = text[1:]
if text.lower().startswith(irc.nick.lower()) and (len(text) < 5 or not text[5].isalnum()): if text.lower().startswith(irc.nick.lower()) and (len(text) < 5 or not text[5].isalnum()):
t2 = text[5:].strip() t2 = text[5:].strip()
@ -201,20 +201,17 @@ class Encyclopedia(callbacks.Plugin):
factoids = cur.fetchall() factoids = cur.fetchall()
if len(factoids): if len(factoids):
f = factoids[0] f = factoids[0]
n = f[0] return Factoid(f[0],f[1],f[2],f[3],f[4])
if '-#' in n:
n = n[:n.find('-#')]
return Factoid(n,f[1],f[2],f[3],f[4])
def resolve_alias(self, channel, factoid, loop=0): def resolve_alias(self, channel, factoid, loop=0):
if loop >= 10: if loop >= 10:
return Factoid('','Error: infinite <alias> loop detected','','',0) return Factoid('','<reply> Error: infinite <alias> loop detected','','',0)
if factoid and factoid.value.lower().startswith('<alias>'): if factoid and factoid.value.lower().startswith('<alias>'):
new_factoids = self.get_factoids(factoid.value[7:].lower().strip(), channel, False) new_factoids = self.get_factoids(factoid.value[7:].lower().strip(), channel, False)
for x in ['channel_primary', 'global_primary']: for x in ['channel_primary', 'global_primary']:
if getattr(new_factoids, x): if getattr(new_factoids, x):
return self.resolve_alias(channel, getattr(new_factoids, x), loop+1) return self.resolve_alias(channel, getattr(new_factoids, x), loop+1)
return Factoid('','Error: unresolvable <alias>','','',0) return Factoid('','<reply> Error: unresolvable <alias> to %s' % factoid.value[7:].lower().strip(),'','',0)
else: else:
return factoid return factoid
@ -301,9 +298,9 @@ class Encyclopedia(callbacks.Plugin):
(msg.args[0], msg.nick, msg.args[1]))) (msg.args[0], msg.nick, msg.args[1])))
return return
ret = self.factoid_edit(text, channel, msg.prefix) ret = self.factoid_edit(text, channel, msg.prefix)
elif ' is ' in text and ('|' not in text or text.find(' is ') > text.find('|')): elif ' is ' in text and '|' not in text:
if not capab(msg.prefix, 'editfactoids'): if not capab(msg.prefix, 'editfactoids'):
if len(text[:text.find('is')]) > 20: if len(text[:text.find('is')]) > 15:
irc.error("I am only a bot, please don't think I'm intelligent :)") irc.error("I am only a bot, please don't think I'm intelligent :)")
else: else:
irc.reply("Your edit request has been forwarded to %s. Thank you for your attention to detail" % irc.reply("Your edit request has been forwarded to %s. Thank you for your attention to detail" %
@ -329,6 +326,9 @@ class Encyclopedia(callbacks.Plugin):
ret = None ret = None
if not ret: if not ret:
if len(text) > 15:
irc.error("I am only a bot, please don't think I'm intelligent :)")
return
retmsg = '' retmsg = ''
ret = self.registryValue('notfoundmsg') ret = self.registryValue('notfoundmsg')
if ret.count('%') == ret.count('%s') == 1: if ret.count('%') == ret.count('%s') == 1:
@ -418,6 +418,7 @@ class Encyclopedia(callbacks.Plugin):
ret = self.check_aliases(channel, factoid) ret = self.check_aliases(channel, factoid)
if ret: if ret:
return ret return ret
print("UPDATE facts SET value=%s where name=%s", (factoid.value,factoid.name))
cs.execute("UPDATE facts SET value=%s where name=%s", (factoid.value,factoid.name)) cs.execute("UPDATE facts SET value=%s where name=%s", (factoid.value,factoid.name))
db.commit() db.commit()
return retmsg return retmsg
@ -465,7 +466,10 @@ class Encyclopedia(callbacks.Plugin):
elif order == 'secondary': elif order == 'secondary':
ret.append(factoid.value.strip().replace('$chan',channel)) ret.append(factoid.value.strip().replace('$chan',channel))
else: else:
ret.append('%s is %s' % (factoid.name, factoid.value.replace('$chan',channel))) n = factoid.name
if '-#' in n:
n = n[:n.find('-#')]
ret.append('%s is %s' % (n, factoid.value.replace('$chan',channel)))
if not display_info: if not display_info:
break break
return ret return ret

View File

@ -6,7 +6,7 @@ for DIST in "$DIR"/*.list; do
DIST=${DIST:${#DIR}} DIST=${DIST:${#DIR}}
DIST=${DIST/.list} DIST=${DIST/.list}
touch "$DIR/$DIST.status" touch "$DIR/$DIST.status"
mkdir -p "$DIR/$DIST" mkdir -p "$DIR/$DIST/partial"
apt-get -qq -o "Dir::State::Lists=$DIR/$DIST" \ apt-get -qq -o "Dir::State::Lists=$DIR/$DIST" \
-o "Dir::etc::sourcelist=$DIR/$DIST.list" \ -o "Dir::etc::sourcelist=$DIR/$DIST.list" \
-o "Dir::State::status=$DIR/$DIST.status" \ -o "Dir::State::status=$DIR/$DIST.status" \