anvil/tools/yumfind
Joshua Harlow 3bf677aa51 Fix building anvils requirements.
It doesn't appear like the correct versions are being
built so create a helper tool that can search for the
correct versions and install those if they exist or
build the ones that are missing.

Change-Id: I03869556a8e321c06ad3ed0b81bb7e8f647e4c8e
2013-06-30 10:56:33 -07:00

43 lines
1023 B
Python
Executable File

#!/usr/bin/python
import warnings
warnings.filterwarnings("ignore")
import logging
import pkg_resources
import sys
from yum import YumBase
if __name__ == '__main__':
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)
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)