Skip to content

Instantly share code, notes, and snippets.

@dmnks
Last active January 29, 2019 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmnks/787b121503ba1e9d1565d58b4a4e3a62 to your computer and use it in GitHub Desktop.
Save dmnks/787b121503ba1e9d1565d58b4a4e3a62 to your computer and use it in GitHub Desktop.
Identify Fedora components depending on the passed list of SRPMs and print them out in wiki format.
# Identify Fedora components depending on the passed list of SRPMs and print
# them out in wiki format.
import sys
import dnf
# Source RPMs to analyze
SOURCES = sys.argv[1:]
# Repos to inspect
REPOS = [
('fedora',
'https://mirrors.fedoraproject.org/metalink?'
'repo=fedora-rawhide&arch=x86_64'),
]
def init(repos):
"""Return a new base object using the given repositories."""
base = dnf.Base()
conf = base.conf
for repo in repos:
name, url = repo
repo = base.repos.add_new_repo(name, conf)
repo.metalink = url
base.fill_sack()
return base
def binaries(base, sources):
"""Yield binary packages built from the given source packages."""
visited = set()
q = base.sack.query()
for pkg in q.available():
if pkg.source_name not in sources or pkg.name in visited:
continue
visited.add(pkg.name)
yield pkg
def requiring(base, pkg):
"""Yield binary packages requiring the given binary package."""
q = base.sack.query()
for pkg in q.filter(requires=pkg.provides):
yield pkg
def analyze(base, sources):
"""Produce the result dict to dump."""
result = {}
for pkg in binaries(base, sources):
for req in requiring(base, pkg):
if req.source_name in sources:
continue
source = result.setdefault(req.source_name, {})
source['tracker'] = 'N/A' # This has to be edited manually
reqs = source.setdefault('requires', [])
if pkg.name not in reqs:
reqs.append(pkg.name)
rpms = source.setdefault('rpms', [])
if req.name not in rpms:
rpms.append(req.name)
return result
def dump(result):
"""Dump the result dict to stdout (in wiki format)."""
for name, source in sorted(result.items(), key=lambda x: x[0]):
print('* %s' % name)
for key, val in source.items():
if isinstance(val, list):
val = ', '.join(sorted(val))
print('** %s: %s' % (key, val))
base = init(REPOS)
result = analyze(base, SOURCES)
dump(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment