summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-12-21 12:33:26 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-12-21 12:33:26 -0500
commitd13133aec0060f975c410bd95156ad9369e80188 (patch)
treed12f8888681528b1654cdd720dee6344d275d0e1
parent5aea316f267a1d83419baace5b97adf3cc61a424 (diff)
add a find-replacements script
I use it like cut -d: -f1 < blacklist.txt |xargs ./find-replacements It outputs lines in one of the formats: pkgname:repo1/replacement1[,repo2/replacement2,...] pkgname:none[:repo1/suggested_replacement2,repo2/suggested_replacement2,...] Packages should only have one replacement, and it should be in [libre] or [libre-multilib]. If there are no replacements, it suggests replacements, which are packages that provide the blacklisted package.
-rwxr-xr-xfind-replacements39
1 files changed, 39 insertions, 0 deletions
diff --git a/find-replacements b/find-replacements
new file mode 100755
index 0000000..4b5fdee
--- /dev/null
+++ b/find-replacements
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
+
+import pyalpm
+import pycman.config
+
+def search(pkgnames):
+ pkgnames = set(pkgnames) # for faster set operations
+ exact = dict((pkgname,set()) for pkgname in pkgnames)
+ suggest = dict((pkgname,set()) for pkgname in pkgnames)
+
+ pycman_options = pycman.config.make_parser().parse_args([])
+ handle = pycman.config.init_with_config_and_options(pycman_options)
+ dbs = handle.get_syncdbs()
+ for db in dbs:
+ for pkg in db.search('.*'):
+ if pkg.name in pkgnames:
+ exact[pkg.name].add(pkg)
+ reps = set(pkg.replaces).intersection(pkgnames)
+ for pkgname in reps:
+ exact[pkgname].add(pkg)
+ provs = set([provide.split('=', 1)[0] for provide in pkg.provides]).intersection(pkgnames)
+ for pkgname in provs:
+ suggest[pkgname].add(pkg)
+ return exact, suggest
+
+def main(pkgnames):
+ exact, suggest = search(pkgnames)
+ for pkgname in pkgnames:
+ if len(exact[pkgname]) > 0:
+ print(pkgname + ":" + (",".join(sorted([pkg.db.name+"/"+pkg.name for pkg in exact[pkgname]]))))
+ elif len(suggest[pkgname]) > 0:
+ print(pkgname + ":none:" + (",".join(sorted([pkg.db.name+"/"+pkg.name for pkg in suggest[pkgname]]))))
+ else:
+ print(pkgname + ":none")
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])