1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
###
# Copyright (c) 2021, B. Watson
# All rights reserved.
#
#
###
import os
import subprocess
import sys
import re
import sqlite3
from supybot import utils, plugins, ircutils, callbacks
from supybot.commands import *
import supybot.utils.minisix as minisix
try:
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('Slackpkg')
except ImportError:
# Placeholder that allows to run the plugin on a bot
# without the i18n module
_ = lambda x: x
class Slackpkg(callbacks.Plugin):
"""Provides Slackware package db lookups"""
threaded = True
db = None
def InitDB(self):
if self.db is None:
filename = self.registryValue('dbpath')
if(os.path.exists(filename)):
self.db = sqlite3.connect(filename)
return self.db
# search for packages by name
def pkgsearch(self, irc, msg, args, pkg):
""" Usage: pkg <packagename> (wildcards allowed)"""
db = self.InitDB();
if db is None:
irc.error("slackpkg database doesn't exist", Raise=True)
maxresults = self.registryValue('maxresults')
cursor = db.cursor()
cursor.execute("select c.name, p.name, p.descrip from categories c, packages p where c.id=p.category and p.name glob ? order by c.name, p.name limit ?", (pkg, maxresults+1))
result = cursor.fetchall()
lines = []
if len(result) == 0:
irc.reply("no matching packages")
else:
for (category, pkg, descrip) in result:
lines.append(format('%s/%s - %s', category, pkg, descrip))
if(len(result) > maxresults):
lines.append("[too many results, only showing first " + str(maxresults) + "]")
irc.replies(lines, joiner=' | ')
pkgsearch = thread(wrap(pkg, ['somethingWithoutSpaces']))
# search for packages by contents
def pkgfile(self, irc, msg, args, pkg):
""" Usage: pkgfile <path> (wildcards allowed)"""
db = self.InitDB();
if db is None:
irc.error("slackpkg database doesn't exist", Raise=True)
maxresults = self.registryValue('maxresults')
cursor = db.cursor()
cursor.execute("select distinct c.name, p.name, p.descrip from categories c, packages p, files f where c.id=p.category and p.id=f.package and f.path glob ? order by c.name, p.name limit ?", (pkg, maxresults+1))
result = cursor.fetchall()
lines = []
if len(result) == 0:
irc.reply("no matching packages")
else:
for (category, pkg, descrip) in result:
lines.append(format('%s/%s - %s', category, pkg, descrip))
if(len(result) > maxresults):
lines.append("[too many results, only showing first " + str(maxresults) + "]")
irc.replies(lines, joiner=' | ')
pkgfile = thread(wrap(pkgfile, ['somethingWithoutSpaces']))
#def which(self, irc, msg, args, filename):
Class = Slackpkg
|