aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SBoTools/plugin.py65
-rwxr-xr-xbin/sbotools-update-db.sh38
2 files changed, 86 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>
diff --git a/bin/sbotools-update-db.sh b/bin/sbotools-update-db.sh
new file mode 100755
index 0000000..07ef9ec
--- /dev/null
+++ b/bin/sbotools-update-db.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# update the SBoTools.sqlite3 for the SBoTools limnoria plugin.
+# should be run from cron probably daily. also can be run manually.
+# run this as the slackfacts user, not root.
+
+# configurables:
+BOTDIR=/home/slackfacts/supybot
+DBFILE=$BOTDIR/SBoTools.sqlite3
+SCRIPT=$BOTDIR/limnoria.slackfacts.plugins/bin/sbodb.pl
+SBOTREE=/data/mirrors/slackbuilds.org/14.2
+SQLITE3=/usr/bin/sqlite3
+LOG=$BOTDIR/sbotools-update-db.log
+DATEFILE=$BOTDIR/sbotools-update-db.lastdate
+
+# 1st line of ChangeLog.txt is the date of the last SBo update.
+head -n 1 $SBOTREE/ChangeLog.txt > $DATEFILE.new
+
+# 'diff' returns true if the files are the same (non-intuitive).
+# if there hasn't been an SBo update since the last DB update, we
+# don't need to update the DB again.
+if [ -e $DATEFILE && diff $DATEFILE $DATEFILE.new > /dev/null ]; then
+ rm -f $DATEFILE.new
+ exit 0
+fi
+
+( $SCRIPT $SBOTREE | $SQLITE3 $DBFILE.update ) &> $LOG
+
+if [ "$?" = "0" ]; then
+ mv $DBFILE.update $DBFILE.new
+ mv $DATEFILE.new $DATEFILE
+ rm -f $LOG
+ exit 0
+else
+ echo "$0: update failed"
+ cat $LOG
+ exit 1
+fi