diff options
-rw-r--r-- | SBoTools/config.py | 10 | ||||
-rw-r--r-- | SBoTools/plugin.py | 33 | ||||
-rwxr-xr-x | bin/sbodb.pl | 72 |
3 files changed, 91 insertions, 24 deletions
diff --git a/SBoTools/config.py b/SBoTools/config.py index b13dc28..d07f840 100644 --- a/SBoTools/config.py +++ b/SBoTools/config.py @@ -33,10 +33,8 @@ conf.registerGlobalValue(SBoTools, 'dbpath', registry.String("/home/slackfacts/supybot/SBoTools.sqlite3", _("""Path to sqite3 database."""))) conf.registerGlobalValue(SBoTools, 'maxresults', - registry.Integer(5, _("""Maximum number of results to send to client."""))) + registry.Integer(5, _("""Maximum number of results for sbosearch command"""))) + +conf.registerGlobalValue(SBoTools, 'maxdeps', + registry.Integer(10, _("""Maximum number of dependencies for sboinfo command"""))) -## conf.registerGlobalValue(SBoTools, 'slackpath', -## registry.String("/data/mirrors/slackware/slackware64-14.2", _("""Filesystem path to Slackware mirror (NO trailing slash!)"""))) -## -## conf.registerGlobalValue(SBoTools, 'baseurl', -## registry.String("https://slackware.uk/slackware/slackware64-14.2", _("""Web URL of Slackware mirror (NO trailing slash!)"""))) diff --git a/SBoTools/plugin.py b/SBoTools/plugin.py index 0e18e9d..24df7ce 100644 --- a/SBoTools/plugin.py +++ b/SBoTools/plugin.py @@ -40,6 +40,13 @@ class SBoTools(callbacks.Plugin): maxresults *= 5 return maxresults + def getMaxDeps(self, msg): + maxdeps = self.registryValue('maxdeps') + if msg.channel is None: + # private message, increase limit + maxdeps *= 10 + return maxdeps + def InitDB(self): if self.db is None: filename = self.registryValue('dbpath') @@ -142,25 +149,33 @@ class SBoTools(callbacks.Plugin): db = self.InitDB(); cursor = db.cursor() - if(category is None): - cursor.execute("select b.id, b.name, c.name, b.descrip, b.version from builds b, categories c where b.category = c.id and b.name = ?", (build,)) - else: - cursor.execute("select b.id, b.name, c.name, b.descrip, b.version from builds b, categories c where c.id = ? and b.category = c.id and b.name = ?", (category, build,)) + + sql = """select b.id, b.name, c.name, b.descrip, b.version, m.name, e.addr + from builds b, categories c, maintainers m, emails e where """ + if(category is not None): + sql += "c.id=" + str(category) + " and " + sql += """b.category = c.id and b.maintainer = m.id and b.email = e.id + and b.name=?""" + cursor.execute(sql, (build,)) result = cursor.fetchall() if(len(result) == 0): irc.reply("no results found") else: lines = [] - for (bid, bname, cname, bdescrip, bversion) in result: - lines.append(cname + "/" + bname + " v" + bversion + ": " + bdescrip) - cursor.execute("select b.name from builds b, deps d where d.build_id=? and b.id=d.depends_on", (bid,)) + for (bid, bname, cname, bdescrip, bversion, maint, email) in result: + lines.append(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)) depres = cursor.fetchall() if(len(depres) != 0): deps = "" for (depname) in depres: - deps += depname[0] + " " - lines.append("deps: " + deps) + deps += " " + depname[0] + lines.append("deps:" + deps) + if(len(depres) > maxdeps): + lines.append("[too many deps, only showing " + str(maxdeps) + "]") irc.replies(lines, joiner=' | ') diff --git a/bin/sbodb.pl b/bin/sbodb.pl index bfd997e..06c8215 100755 --- a/bin/sbodb.pl +++ b/bin/sbodb.pl @@ -1,9 +1,15 @@ #!/usr/bin/perl -w -# create SBo.sqlite3 database for SBo limnoria plugin. -# requires SLACKBUILDS.txt and TAGS.txt from the SBo repo. -# https://slackware.uk/slackbuilds.org/14.2/SLACKBUILDS.TXT -# https://slackware.uk/slackbuilds.org/14.2/TAGS.txt +# create SBo.sqlite3 database for SBoTools limnoria plugin. +# run with one argument: the path to the SBo repo. This is +# the directory named after the version number, which contains +# SLACKBUILDS.TXT. A git clone will *not* do, needs to be a +# rsync or wget -r copy. + +# Actually only SLACKBUILDS.TXT, TAGS.txt, and the */*/*.info files +# are used. + +# database isn't fully normalized. *shrug*. print <<EOF; pragma journal_mode = memory; @@ -19,7 +25,11 @@ create table builds ( descrip varchar not null, category integer not null, version varchar not null, - foreign key (category) references categories); + maintainer integer not null, + email integer not null, + foreign key (category) references categories, + foreign key (maintainer) references maintainers, + foreign key (email) references emails); create table deps ( build_id integer not null, @@ -32,10 +42,20 @@ create table tags ( tag varchar not null, foreign key (build_id) references builds); +create table maintainers ( + id integer not null, + name varchar not null); + +create table emails ( + id integer not null, + addr varchar not null); + create unique index t_idx on tags(build_id, tag); EOF +$sbopath = shift || "."; + $lastcat = 0; sub get_cat_id { my $catname = shift; @@ -47,11 +67,38 @@ sub get_cat_id { return $catids{$catname}; } -open $sbtxt, "<" . ($ARGV[0] || "SLACKBUILDS.TXT") or die $!; +$lastmaint = $lastemail = 0; +sub get_maint { + my ($cat, $build) = @_; + open my $info, "<$sbopath/$cat/$build/$build.info" or die $!; + while(<$info>) { + /^MAINTAINER="(.*?)"/m and $mname = $1; + /^EMAIL="(.*?)"/m and $ename = $1; + } + close $info; + + if(!$maintids{$mname}) { + $mname =~ s/'/''/g; + $lastmaint++; + print "insert into maintainers values($lastmaint, '$mname');\n"; + $maintids{$mname} = $lastmaint; + } + + if(!$emailids{$ename}) { + $ename =~ s/'/''/g; + $lastemail++; + print "insert into emails values($lastemail, '$ename');\n"; + $emailids{$ename} = $lastemail; + } + + return ($maintids{$mname}, $emailids{$ename}); +} + +open $sbtxt, "<" . $sbopath . "/SLACKBUILDS.TXT" or die $!; { local $/ = ''; while(<$sbtxt>) { - my ($name, $cat, $ver, $deps, $desc,); + my ($name, $cat, $ver, $deps, $desc, $maintid, $emailid); $deps = ""; chomp; /^SLACKBUILD NAME:\s+(\S+)$/m and $name = $1; @@ -70,6 +117,11 @@ open $sbtxt, "<" . ($ARGV[0] || "SLACKBUILDS.TXT") or die $!; $buildver{$name} = $ver; $builddeps{$name} = $deps; $builddesc{$name} = $desc; + + ($maintid, $emailid) = get_maint($cat, $name); + $buildmaint{$name} = $maintid; + $buildemail{$name} = $emailid; + push @builds, $name; } } @@ -87,7 +139,9 @@ insert into builds values( '$_', '$builddesc{$_}', $buildcat{$_}, - '$buildver{$_}'); + '$buildver{$_}', + $buildmaint{$_}, + $buildemail{$_}); EOF } @@ -104,7 +158,7 @@ EOF } } -open $tagstxt, "<" . ($ARGV[1] || "TAGS.txt") or die $!; +open $tagstxt, "<" . $sbopath . "/TAGS.txt" or die $!; while(<$tagstxt>) { my ($build, $t, @tags); chomp; |