anvil/tools/yumfind
Joshua Harlow b3fa0ba30f Turn on dup listing so duplicates can be checked.
Change-Id: I5fe680eda8cb41c8d113bc73e752230b78df4941
2013-06-30 19:13:26 -07:00

48 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python
import warnings
warnings.filterwarnings("ignore")
import os
import pkg_resources
import sys
from yum import YumBase
if __name__ == '__main__':
if len(sys.argv) != 3:
print("%s package-name python-name" % (os.path.basename(sys.argv[0])))
sys.exit(1)
pkg_name = sys.argv[1]
py_name = sys.argv[2]
req = pkg_resources.Requirement.parse(py_name)
base = YumBase()
base.doConfigSetup(debuglevel=-1, errorlevel=-1)
pkgs = base.doPackageLists(patterns=[pkg_name], ignore_case=True,
showdups=True)
all_pkgs = list(pkgs.available)
all_pkgs.extend(pkgs.installed)
yum_map = {}
for pkg in all_pkgs:
for provides in pkg.provides:
pkg_info = (pkg.version, pkg.repo, pkg)
yum_map.setdefault(provides[0], set()).add(pkg_info)
matches = []
yum_versions = yum_map.get(pkg_name, [])
for (version, repo, pkg) in yum_versions:
if version in req:
matches.append(pkg)
if matches:
# Pick the newest match.
match = sorted(matches)[-1]
print(match)
sys.exit(0)
else:
sys.exit(1)