From 9120eec15a3adedab8307232ae00cb3ae035159c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 29 Jun 2021 02:57:41 -0400 Subject: SBoTools: add sborevdep (reverse dependency search) --- SBoTools/plugin.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/SBoTools/plugin.py b/SBoTools/plugin.py index 7ffd824..9e03ad7 100644 --- a/SBoTools/plugin.py +++ b/SBoTools/plugin.py @@ -263,4 +263,61 @@ class SBoTools(callbacks.Plugin): sbomaint = thread(wrap(sbomaint, [many('somethingWithoutSpaces')])) + def getDependees(self, rflag, buildid, db): + retlist = [] + cursor = db.cursor() + cursor.execute("select c.name, b.name, build_id from builds b, categories c, deps d where b.category=c.id and b.id=d.build_id and d.depends_on=?", (buildid,)) + result = cursor.fetchall() + for (cat, name, bid) in result: + retlist.append(ircutils.bold(cat + "/" + name)) + if(rflag): + sublist = self.getDependees(rflag, bid, db) + if(len(sublist) > 0): + retlist.append("[") + retlist.extend(sublist) + retlist.append("]") + return retlist + + def sborevdep(self, irc, msg, args, rflag, catbuild): + """ [-r] + + Show builds that depend on . With -r, show builds that + depend on each result, recursively. + """ + + category = None + build = None + + t = catbuild.split('/',1) + if(len(t) == 1): + build = catbuild + else: + category = self.getCategory(t[0]) + if(category is None): + irc.error("invalid category '" + t[0] + "'", Raise=True) + build = t[1] + + db = self.InitDB(); + cursor = db.cursor() + sql = "select b.id from builds b" + if(category is None): + sql += " where " + else: + sql += ", categories c where c.id=" + str(category) + " and b.category=c.id and " + sql += "b.name=?" + cursor.execute(sql, (build,)) + + result = cursor.fetchall() + if(len(result) == 0): + irc.reply("no such build: " + catbuild) + return + + lines = self.getDependees(rflag, result[0][0], db) + if(len(lines) == 0): + irc.reply("nothing depends on " + catbuild) + else: + irc.replies(lines, joiner=' ') + + sborevdep = thread(wrap(sborevdep, [optional(('literal', ['-r'])), 'somethingWithoutSpaces'])) + Class = SBoTools -- cgit v1.2.3