### # 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 (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 (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