find-replacements 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
  3. import pyalpm
  4. import pycman.config
  5. def search(pkgnames):
  6. pkgnames = set(pkgnames) # for faster set operations
  7. exact = dict((pkgname,set()) for pkgname in pkgnames)
  8. suggest = dict((pkgname,set()) for pkgname in pkgnames)
  9. pycman_options = pycman.config.make_parser().parse_args([])
  10. handle = pycman.config.init_with_config_and_options(pycman_options)
  11. dbs = handle.get_syncdbs()
  12. for db in dbs:
  13. for pkg in db.search('.*'):
  14. if pkg.name in pkgnames:
  15. exact[pkg.name].add(pkg)
  16. reps = set(pkg.replaces).intersection(pkgnames)
  17. for pkgname in reps:
  18. exact[pkgname].add(pkg)
  19. provs = set([provide.split('=', 1)[0] for provide in pkg.provides]).intersection(pkgnames)
  20. for pkgname in provs:
  21. suggest[pkgname].add(pkg)
  22. return exact, suggest
  23. def main(pkgnames):
  24. exact, suggest = search(pkgnames)
  25. for pkgname in pkgnames:
  26. if len(exact[pkgname]) > 0:
  27. print(pkgname + ":" + (",".join(sorted([pkg.db.name+"/"+pkg.name for pkg in exact[pkgname]]))))
  28. elif len(suggest[pkgname]) > 0:
  29. print(pkgname + ":none:" + (",".join(sorted([pkg.db.name+"/"+pkg.name for pkg in suggest[pkgname]]))))
  30. else:
  31. print(pkgname + ":none")
  32. if __name__ == "__main__":
  33. import sys
  34. main(sys.argv[1:])