diff options
| author | B. Watson <yalhcru@gmail.com> | 2021-06-29 02:57:41 -0400 | 
|---|---|---|
| committer | B. Watson <yalhcru@gmail.com> | 2021-06-29 02:57:41 -0400 | 
| commit | 9120eec15a3adedab8307232ae00cb3ae035159c (patch) | |
| tree | 387e0ac52233e551c44d6f2723dac06dfc01554b | |
| parent | 30b238ef6db7c5b5b6d80c1e51aa2600e896abe2 (diff) | |
| download | limnoria.slackfacts.plugins-9120eec15a3adedab8307232ae00cb3ae035159c.tar.gz | |
SBoTools: add sborevdep (reverse dependency search)
| -rw-r--r-- | SBoTools/plugin.py | 57 | 
1 files changed, 57 insertions, 0 deletions
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] <build> + +        Show builds that depend on <build>. 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  | 
