--- /dev/null
+#!/usr/bin/env python
+
+from glob import glob
+import sys
+import subprocess
+import re
+
+
+def call_cmd(cmd):
+ try:
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
+ except subprocess.CalledProcessError as err:
+ sys.stderr.write(err.output.decode())
+ exit(err.returncode)
+ return proc.stdout
+
+
+def recur_reqs(req):
+ if len(rpm_provides[req]) > 1:
+ print "Use first ocurance of package '" + req +\
+ "'. TODO get newer version."
+ pkg_file = rpm_provides[req][0]["file"]
+ print pkg_file
+ out = call_cmd("rpm -qpR " + pkg_file)
+ for line in out:
+ pkg = line.strip()
+ if pkg in rpm_provides:
+ recur_reqs(pkg)
+ # else:
+ # print "Not found '{}'".format(pkg)
+
+
+if len(sys.argv) != 3:
+ print "Usage: {} <gbs_root_path> <required_pkg>".format(sys.argv[0])
+ print "Search for <required_pkg> and all its dependencies in GBS cache"
+ exit(0)
+
+cache = sys.argv[1] + "/local/cache"
+req = sys.argv[2]
+
+rpm_provides = {}
+
+cached_rpms = glob(cache + "/*/*.rpm")
+for rpm in cached_rpms:
+ out = call_cmd("rpm -qpp " + rpm)
+ for line in out:
+ pkg = re.search(r"(.*)-([\d.]*)-([\d.]*).x86_64", line)
+ if pkg:
+ if pkg.group(1) not in rpm_provides:
+ rpm_provides[pkg.group(1)] = []
+ rpm_provides[pkg.group(1)].append({"file": rpm,
+ "version1": pkg.group(2),
+ "version2": pkg.group(3)})
+if req in rpm_provides:
+ recur_reqs(req)
+else:
+ print "'{}' not found in caches".format(req)