1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/env python3
"""
Example: Localize metadata files of a local repository
Use case:
We have a local repositository in the rpm-md format
and want to paths to all its metadata files.
Repomd content is just a bonus.
"""
import sys
import librepo
import pprint
METADATA_PATH = "downloaded_metadata"
if __name__ == "__main__":
h = librepo.Handle()
r = librepo.Result()
# Repository with repodata in the rpm-md format
h.setopt(librepo.LRO_REPOTYPE, librepo.LR_YUMREPO)
# Path to metadata
h.setopt(librepo.LRO_URLS, [METADATA_PATH])
# Do not duplicate (copy) metadata, just localise them
h.setopt(librepo.LRO_LOCAL, True)
try:
h.perform(r)
except librepo.LibrepoException as e:
rc, msg, general_msg = e
print("Error: {}".format(msg))
sys.exit(1)
print("Repomd content:")
pprint.pprint(r.getinfo(librepo.LRR_YUM_REPOMD))
print("\nPaths to metadata files:")
for data_type, path in r.getinfo(librepo.LRR_YUM_REPO).iteritems():
print("%15s: %s" % (data_type, path))
sys.exit(0)
|