mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Various updates.
This commit is contained in:
parent
ce27a25e7d
commit
df3dcb7e2a
@ -38,6 +38,7 @@ from baseplugin import *
|
|||||||
import string
|
import string
|
||||||
import getopt
|
import getopt
|
||||||
import os.path
|
import os.path
|
||||||
|
import operator
|
||||||
|
|
||||||
import sqlite
|
import sqlite
|
||||||
|
|
||||||
@ -77,11 +78,13 @@ def makeDb(dbfilename, indexfd, replace=False):
|
|||||||
)""")
|
)""")
|
||||||
cursor.execute("""CREATE TABLE in_category (
|
cursor.execute("""CREATE TABLE in_category (
|
||||||
port_id INTEGER,
|
port_id INTEGER,
|
||||||
category_id INTEGER
|
category_id INTEGER,
|
||||||
|
UNIQUE (port_id, category_id) ON CONFLICT IGNORE
|
||||||
)""")
|
)""")
|
||||||
cursor.execute("""CREATE TABLE depends (
|
cursor.execute("""CREATE TABLE depends (
|
||||||
port_id INTEGER,
|
port_id INTEGER,
|
||||||
depends_id INTEGER
|
depends_id INTEGER,
|
||||||
|
UNIQUE (port_id, depends_id) ON CONFLICT IGNORE
|
||||||
)""")
|
)""")
|
||||||
lines = map(lambda s: s.rstrip().split('|'), indexfd)
|
lines = map(lambda s: s.rstrip().split('|'), indexfd)
|
||||||
for fields in lines:
|
for fields in lines:
|
||||||
@ -114,13 +117,13 @@ def makeDb(dbfilename, indexfd, replace=False):
|
|||||||
depends_id = cursor.fetchone()[0]
|
depends_id = cursor.fetchone()[0]
|
||||||
cursor.execute("INSERT INTO depends VALUES (%s, %s)",
|
cursor.execute("INSERT INTO depends VALUES (%s, %s)",
|
||||||
port_id, depends_id)
|
port_id, depends_id)
|
||||||
for dep in r_deps.split():
|
## for dep in r_deps.split():
|
||||||
cursor.execute("""SELECT id FROM ports WHERE name=%s""", name)
|
## cursor.execute("""SELECT id FROM ports WHERE name=%s""", name)
|
||||||
port_id = cursor.fetchone()[0]
|
## port_id = cursor.fetchone()[0]
|
||||||
cursor.execute("""SELECT id FROM ports WHERE name=%s""", dep)
|
## cursor.execute("""SELECT id FROM ports WHERE name=%s""", dep)
|
||||||
depends_id = cursor.fetchone()[0]
|
## depends_id = cursor.fetchone()[0]
|
||||||
cursor.execute("INSERT INTO depends VALUES (%s, %s)",
|
## cursor.execute("INSERT INTO depends VALUES (%s, %s)",
|
||||||
port_id, depends_id)
|
## port_id, depends_id)
|
||||||
indexfd.close()
|
indexfd.close()
|
||||||
cursor.execute("CREATE INDEX in_category_port_id ON in_category (port_id)")
|
cursor.execute("CREATE INDEX in_category_port_id ON in_category (port_id)")
|
||||||
cursor.execute("CREATE INDEX depends_port_id ON depends (port_id)")
|
cursor.execute("CREATE INDEX depends_port_id ON depends (port_id)")
|
||||||
@ -139,8 +142,6 @@ class FreeBSD(callbacks.Privmsg):
|
|||||||
self.db = makeDb(dbFile, getIndex())
|
self.db = makeDb(dbFile, getIndex())
|
||||||
|
|
||||||
_globtrans = string.maketrans('?*', '_%')
|
_globtrans = string.maketrans('?*', '_%')
|
||||||
abbrev = utils.abbrev(['name', 'category', 'depends',
|
|
||||||
'info', 'maintainer', 'website'])
|
|
||||||
def searchports(self, irc, msg, args):
|
def searchports(self, irc, msg, args):
|
||||||
"""[--name=<glob>] [--category=<glob>] [--depends=<glob>] """ \
|
"""[--name=<glob>] [--category=<glob>] [--depends=<glob>] """ \
|
||||||
"""[--info=<glob>] [--maintainer=<glob>] [--website=<glob>]
|
"""[--info=<glob>] [--maintainer=<glob>] [--website=<glob>]
|
||||||
@ -159,8 +160,12 @@ class FreeBSD(callbacks.Privmsg):
|
|||||||
tables = ['ports']
|
tables = ['ports']
|
||||||
constraints = []
|
constraints = []
|
||||||
arguments = []
|
arguments = []
|
||||||
|
dependsConstraints = []
|
||||||
|
dependsArguments = []
|
||||||
for (option, argument) in optlist:
|
for (option, argument) in optlist:
|
||||||
option = self.abbrev[option[2:].lower()]
|
if len(argument.translate(string.ascii, '*%_?')) < 2:
|
||||||
|
irc.error(msg, 'You must provide 2 non-wildcard characters.')
|
||||||
|
option = option[2:]
|
||||||
argument = argument.translate(self._globtrans)
|
argument = argument.translate(self._globtrans)
|
||||||
if option in ('name', 'info', 'maintainer', 'website'):
|
if option in ('name', 'info', 'maintainer', 'website'):
|
||||||
constraints.append('ports.%s LIKE %%s' % option)
|
constraints.append('ports.%s LIKE %%s' % option)
|
||||||
@ -176,20 +181,29 @@ class FreeBSD(callbacks.Privmsg):
|
|||||||
elif option == 'depends':
|
elif option == 'depends':
|
||||||
if 'depends' not in tables:
|
if 'depends' not in tables:
|
||||||
tables.append('depends')
|
tables.append('depends')
|
||||||
constraints.append('ports.id=depends.port_id')
|
dependsConstraints.append('ports.id=depends.port_id')
|
||||||
constraints.append("""depends.depends_id IN
|
dependsConstraints.append("""depends.depends_id IN
|
||||||
(SELECT ports.id FROM ports
|
(SELECT ports.id FROM ports
|
||||||
WHERE ports.name LIKE %s)""")
|
WHERE ports.name LIKE %s)""")
|
||||||
arguments.append(argument)
|
else:
|
||||||
sql = """SELECT ports.name FROM %s WHERE %s """ % \
|
for (i, s) in enumerate(dependsConstraints):
|
||||||
(', '.join(tables), ' AND '.join(constraints))
|
if s.startswith('depends.depends_id IN'):
|
||||||
|
s = s.replace('%s)', '%s OR ports.name LIKE %s)')
|
||||||
|
dependsConstraints[i] = s
|
||||||
|
dependsArguments.append(argument)
|
||||||
|
sql = """SELECT ports.name FROM %s WHERE %s""" % \
|
||||||
|
(', '.join(tables), ' AND '.join(constraints+dependsConstraints))
|
||||||
debug.printf(sql)
|
debug.printf(sql)
|
||||||
cursor.execute(sql, *arguments)
|
cursor.execute(sql, *(arguments+dependsArguments))
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'No ports matched those constraints.')
|
irc.reply(msg, 'No ports matched those constraints.')
|
||||||
return
|
return
|
||||||
names = [t[0] for t in cursor.fetchall()]
|
names = [t[0] for t in cursor.fetchall()]
|
||||||
irc.reply(msg, ', '.join(names))
|
if reduce(operator.add, map((2).__add__, map(len, names))) > 450:
|
||||||
|
irc.reply(msg, '%s ports matched those constraints. ' \
|
||||||
|
'Please narrow your search.' % cursor.rowcount)
|
||||||
|
else:
|
||||||
|
irc.reply(msg, ', '.join(names))
|
||||||
|
|
||||||
|
|
||||||
def numports(self, irc, msg, args):
|
def numports(self, irc, msg, args):
|
||||||
|
Loading…
Reference in New Issue
Block a user