aboutsummaryrefslogtreecommitdiff
path: root/SBoTools
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2021-06-25 14:14:27 -0400
committerB. Watson <yalhcru@gmail.com>2021-06-25 14:14:27 -0400
commit3d35e2ba0cc2b2de58287ab24585082552d544d6 (patch)
tree326796ab7b3aea90f352aa67446dd942ebc66d89 /SBoTools
parenta5a96cd7ae566bb1ee168cae14e1d1101bcd1797 (diff)
downloadlimnoria.slackfacts.plugins-3d35e2ba0cc2b2de58287ab24585082552d544d6.tar.gz
SBoTools: add DB update cron script, twiddle search result formatting
Diffstat (limited to 'SBoTools')
-rw-r--r--SBoTools/plugin.py65
1 files changed, 48 insertions, 17 deletions
diff --git a/SBoTools/plugin.py b/SBoTools/plugin.py
index 24df7ce..47fc28b 100644
--- a/SBoTools/plugin.py
+++ b/SBoTools/plugin.py
@@ -5,8 +5,6 @@
#
###
-# TODO: add maintainer name/email to the DB.
-
import os
import glob
import subprocess
@@ -48,6 +46,22 @@ class SBoTools(callbacks.Plugin):
return maxdeps
def InitDB(self):
+ filename = self.registryValue('dbpath')
+
+ # if updated database exists under as newfilename, it's
+ # complete and flushed, ready to use. the db-creation
+ # script that runs from cron uses a different name for
+ # db-creation, and renames to .new only when finished.
+ # no error-checking (if the rename fails, the bot logs an
+ # exception and someone has to fix it manually).
+ newfilename = filename + ".new"
+
+ if(os.path.exists(newfilename)):
+ if(self.db is not None):
+ self.db.close()
+ self.db = None
+ os.rename(newfilename, filename)
+
if self.db is None:
filename = self.registryValue('dbpath')
if(os.path.exists(filename)):
@@ -108,29 +122,36 @@ class SBoTools(callbacks.Plugin):
sql += " and b.name like " + tlike
maxresults = self.getMaxResults(msg)
- sql += " limit " + str(maxresults + 1)
cursor.execute(sql)
result = cursor.fetchall()
+
+ count = len(result)
+ toomany = (count > maxresults)
+ if(toomany):
+ del result[maxresults:]
+
if(len(result) == 0):
irc.reply("no results found")
else:
lines = []
+ lines.append(ircutils.bold(str(count)) + " results:")
for (i) in result:
c2 = db.cursor()
c2.execute("select b.name, c.name from builds b, categories c where b.category=c.id and b.id=?", (i[0],))
xres = c2.fetchall();
if(len(result) == 1):
+ # if there's only one result, jump straight to its !sboinfo
(name, cat) = xres[0]
- #irc.reply("would be showing !sboinfo " + cat + "/" + name);
self.SBoInfo(irc, msg, cat + "/" + name)
return;
for (name, cat) in xres:
- lines.append(cat + "/" + name)
+ lines.append(ircutils.bold(cat + "/" + name))
+
+ if(toomany):
+ lines.append("...")
- if(len(result) > maxresults):
- lines.append("[too many results, only showing first " + str(maxresults) + "]")
- irc.replies(lines, joiner=' | ')
+ irc.replies(lines, joiner=' ')
sbosearch = thread(wrap(sbosearch, [optional(('literal', ['-t'])), many('somethingWithoutSpaces')]))
@@ -164,20 +185,30 @@ class SBoTools(callbacks.Plugin):
else:
lines = []
for (bid, bname, cname, bdescrip, bversion, maint, email) in result:
- lines.append(cname + "/" + bname + " v" + bversion + ": " + bdescrip +
- ", " + maint + " <" + email + ">")
+ lines.append(ircutils.bold(cname + "/" + bname) + " v" + bversion + ": " + bdescrip +
+ ", " + maint + " <" + email + ">.")
maxdeps = self.getMaxDeps(msg)
- cursor.execute("select b.name from builds b, deps d where d.build_id=? and b.id=d.depends_on limit ?", (bid,maxdeps+1))
+ cursor.execute("select b.name from builds b, deps d where d.build_id=? and b.id=d.depends_on", (bid,))
depres = cursor.fetchall()
- if(len(depres) != 0):
+ if(len(depres) == 0):
+ lines.append("No external deps.")
+ else:
+ depcount = len(depres)
+ toomany = (depcount > maxdeps)
+ if(toomany):
+ del depres[maxdeps:]
deps = ""
for (depname) in depres:
deps += " " + depname[0]
- lines.append("deps:" + deps)
- if(len(depres) > maxdeps):
- lines.append("[too many deps, only showing " + str(maxdeps) + "]")
-
- irc.replies(lines, joiner=' | ')
+ if(toomany):
+ deps += " ..."
+ if(depcount == 1):
+ plural = ""
+ else:
+ plural = "s"
+ lines.append(str(depcount) + " dep" + plural + ":" + deps)
+
+ irc.replies(lines, joiner=' ')
def sboinfo(self, irc, msg, args, catbuild):
""" [<category/>]<build>