From a3481af25cb845676755701d1cb55f485542fffc Mon Sep 17 00:00:00 2001 From: Dennis Kaarsemaker Date: Sat, 10 Feb 2007 22:47:18 +0100 Subject: [PATCH] Fixy fixy! --- Bugtracker/plugin.py | 13 ++- Encyclopedia/README.txt | 2 +- Encyclopedia/editlogs.cgi | 9 -- Encyclopedia/factoids.cgi | 183 +++++++++++++++++++++----------------- Encyclopedia/plugin.py | 26 +++--- Encyclopedia/update_apt | 2 +- 6 files changed, 121 insertions(+), 114 deletions(-) delete mode 100755 Encyclopedia/editlogs.cgi diff --git a/Bugtracker/plugin.py b/Bugtracker/plugin.py index a6f470e..71ce99a 100644 --- a/Bugtracker/plugin.py +++ b/Bugtracker/plugin.py @@ -351,7 +351,6 @@ class Bugtracker(callbacks.PluginRegexp): def turlSnarfer(self, irc, msg, match): r"(?Phttps?://\S*?)/(Bugs/0*|str.php\?L|show_bug.cgi\?id=|bugreport.cgi\?bug=|(bugs|\+bug)/|ticket/|tracker/|\S*aid=)(?P\d+)(?P&group_id=\d+&at_id=\d+)?" - print match if msg.args[0][0] == '#' and not self.registryValue('bugSnarfer', msg.args[0]): return 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) def get_tracker(self,snarfurl,sfdata): + snarfurl = snarfurl.replace('sf.net','sourceforge.net') snarfhost = snarfurl.replace('http://','').replace('https://','') if '/' in snarfurl: snarfhost = snarfhost[:snarfhost.index('/')] @@ -527,10 +527,10 @@ class Malone(IBugtracker): try: statuses = ['Rejected', 'Fix Released', 'Fix Committed', 'Unconfirmed', 'Needs Info', 'In Progress', 'Confirmed'] 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'] 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'] in severities and task2['importance'] not in severities: 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['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 not (task1['status'] == task2['status']): if statuses.index(task1['status']) < statuses.index(task2['status']): return -1 @@ -677,7 +677,6 @@ class Trac(IBugtracker): severity = l[l.find('>')+1:l.find('')+1:l.find('%s
' % (file, file) - -send_page('plain.tmpl') diff --git a/Encyclopedia/factoids.cgi b/Encyclopedia/factoids.cgi index 2b4cee8..4b541e2 100755 --- a/Encyclopedia/factoids.cgi +++ b/Encyclopedia/factoids.cgi @@ -1,109 +1,124 @@ #!/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 datetime -import cgi, cgitb -from math import ceil -import re -cgitb.enable +import sys +sys.path.append('/var/www/bots.ubuntulinux.nl') +from commoncgi import * +### Variables NUM_PER_PAGE=50.0 +datadir = '/home/dennis/ubugtu/data/facts' +default_database = 'ubuntu' -buf = '' -def out(txt): - global buf - buf += str(txt) +databases = [x for x in os.listdir(datadir)] +# 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 '%%' 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 '%%'""") + total = cur.fetchall()[0][0] + +# Pagination links +npages = int(math.ceil(total / float(NUM_PER_PAGE))) +print '·' +for i in range(npages): + print '%d ·' % (database, search, order_by, i, i+1) + +print '
Order by
·'; +print ' %s ·' % (database, search, 'name ASC', 'Name +') +print ' %s ·' % (database, search, 'name DESC', 'Name -') +print ' %s ·' % (database, search, 'popularity ASC', 'Popularity +') +print ' %s ·' % (database, search, 'popularity DESC', 'Popularity -') +print ' %s ·' % (database, search, 'added ASC', 'Date added +') +print ' %s ·' % (database, search, 'added DESC', 'Date added -') + +print '' + +url_re = re.compile('(?P(https?://\S+|www\S+))') +def q(x): + x = str(x).replace('&','&').replace('<','<').replace('>','>').replace('\n','
') + return url_re.sub(link, x) def link(match): url = match.group('url') txt = url if len(txt) > 30: txt = txt[:20] + '…' + txt[-10:] return '%s' % (url, txt) - -def q(txt): - txt = str(txt).replace('&','&').replace('<','<').replace('>','>').replace('"','"').replace('\n','
').replace('$hr$','
') - # linkify - rx = re.compile('(?P(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 '%%'""") - num = cur.fetchall()[0][0] - npages = int(ceil(num / float(NUM_PER_PAGE))) - out('·') - for i in range(npages): - out(' %d ·' % (database, order_by, i, i+1)) - out('
Order by
·') - out(' %s ·' % (database, 'name ASC', page, 'Name +')) - out(' %s ·' % (database, 'name DESC', page, 'Name -')) - out(' %s ·' % (database, 'popularity ASC', page, 'Popularity +')) - out(' %s ·' % (database, 'popularity DESC', page, 'Popularity -')) - out(' %s ·' % (database, 'added ASC', page, 'Date added +')) - out(' %s ·' % (database, 'added DESC', page, 'Date added -')) - -out('
FactoidValueAuthor
') - -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 '%%' 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 for f in factoids: 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') more = cur.fetchall() if len(more): f[1] += ' $hr$' + ' $hr$'.join([x[0] for x in more]) cur.execute("SELECT name FROM facts WHERE value LIKE %s", ' ' + f[0]) f[0] += ' \n' + ' \n'.join([x[0] for x in cur.fetchall()]) - out('' % tuple([q(x) for x in f])) + print '>' % tuple([q(x) for x in f]) -out('
FactoidValueAuthor
%s%s%s
Added on: %s
Requested %s times
%s%s%s
Added on: %s
Requested %s times
') +print '' -print "Content-Type: text/html; charset=UTF-8" -print "" - -fd = open('factoids.tmpl') -tmpl = fd.read() -fd.close() -print tmpl % (buf) +send_page('factoids.tmpl') diff --git a/Encyclopedia/plugin.py b/Encyclopedia/plugin.py index 740e1cb..4cc32d9 100644 --- a/Encyclopedia/plugin.py +++ b/Encyclopedia/plugin.py @@ -151,7 +151,7 @@ class Encyclopedia(callbacks.Plugin): text = text.strip() if text.lower() == self.registryValue('prefixchar') + 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:] if text.lower().startswith(irc.nick.lower()) and (len(text) < 5 or not text[5].isalnum()): t2 = text[5:].strip() @@ -201,20 +201,17 @@ class Encyclopedia(callbacks.Plugin): factoids = cur.fetchall() if len(factoids): f = factoids[0] - n = f[0] - if '-#' in n: - n = n[:n.find('-#')] - return Factoid(n,f[1],f[2],f[3],f[4]) + return Factoid(f[0],f[1],f[2],f[3],f[4]) def resolve_alias(self, channel, factoid, loop=0): if loop >= 10: - return Factoid('','Error: infinite loop detected','','',0) + return Factoid('',' Error: infinite loop detected','','',0) if factoid and factoid.value.lower().startswith(''): new_factoids = self.get_factoids(factoid.value[7:].lower().strip(), channel, False) for x in ['channel_primary', 'global_primary']: if getattr(new_factoids, x): return self.resolve_alias(channel, getattr(new_factoids, x), loop+1) - return Factoid('','Error: unresolvable ','','',0) + return Factoid('',' Error: unresolvable to %s' % factoid.value[7:].lower().strip(),'','',0) else: return factoid @@ -301,9 +298,9 @@ class Encyclopedia(callbacks.Plugin): (msg.args[0], msg.nick, msg.args[1]))) return 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 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 :)") else: 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 if not ret: + if len(text) > 15: + irc.error("I am only a bot, please don't think I'm intelligent :)") + return retmsg = '' ret = self.registryValue('notfoundmsg') if ret.count('%') == ret.count('%s') == 1: @@ -418,6 +418,7 @@ class Encyclopedia(callbacks.Plugin): ret = self.check_aliases(channel, factoid) if 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)) db.commit() return retmsg @@ -465,9 +466,12 @@ class Encyclopedia(callbacks.Plugin): elif order == 'secondary': ret.append(factoid.value.strip().replace('$chan',channel)) 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: - break + break return ret def search_factoid(self, factoid, channel): diff --git a/Encyclopedia/update_apt b/Encyclopedia/update_apt index ab8152d..e759af8 100755 --- a/Encyclopedia/update_apt +++ b/Encyclopedia/update_apt @@ -6,7 +6,7 @@ for DIST in "$DIR"/*.list; do DIST=${DIST:${#DIR}} DIST=${DIST/.list} touch "$DIR/$DIST.status" - mkdir -p "$DIR/$DIST" + mkdir -p "$DIR/$DIST/partial" apt-get -qq -o "Dir::State::Lists=$DIR/$DIST" \ -o "Dir::etc::sourcelist=$DIR/$DIST.list" \ -o "Dir::State::status=$DIR/$DIST.status" \