Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleš Matěj <amatej@redhat.com>2021-08-03 16:17:43 +0300
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>2021-09-23 14:54:10 +0300
commit0633e31e491179f0153ef8267874812b4691957b (patch)
treebb0a79e7b77e2aaa1d0e13bcc389507a3dcf3ffb
parent0c050128f7e24222011cdfcc67ba58da744affa9 (diff)
Add xml_parse_main_metadata_together to python parser examples
-rwxr-xr-xexamples/python/repodata_parsing.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/python/repodata_parsing.py b/examples/python/repodata_parsing.py
index ea517a1..4519518 100755
--- a/examples/python/repodata_parsing.py
+++ b/examples/python/repodata_parsing.py
@@ -211,6 +211,48 @@ def second_method():
for pkg in packages.values():
print_package_info(pkg)
+def third_method():
+ """Parsing main metadata types (primary, filelists, other) at the same time.
+ This approach significantly reduces memory footprint because we don't need
+ to keep all the packages in memory, user can handle them one by one.
+
+ The API reflects xml_parse_primary/filelists/other except that it handles
+ all of them at the same time.
+
+ """
+ def warningcb(warning_type, message):
+ print("PARSER WARNING: %s" % message)
+ return True
+
+ repomd = cr.Repomd()
+ cr.xml_parse_repomd(os.path.join(REPO_PATH, "repodata/repomd.xml"), repomd, warningcb)
+
+ primary_xml_path = None
+ filelists_xml_path = None
+ other_xml_path = None
+ for record in repomd.records:
+ if record.type == "primary":
+ primary_xml_path = os.path.join(REPO_PATH, record.location_href)
+ elif record.type == "filelists":
+ filelists_xml_path = os.path.join(REPO_PATH, record.location_href)
+ elif record.type == "other":
+ other_xml_path = os.path.join(REPO_PATH, record.location_href)
+
+ #
+ # Main XML metadata parsing (primary, filelists, other)
+ #
+
+ def pkgcb(pkg):
+ # Called when whole package entry from all 3 metadata xml files is parsed
+ print_package_info(pkg)
+
+ cr.xml_parse_main_metadata_together(primary_xml_path,
+ filelists_xml_path,
+ other_xml_path,
+ None,
+ pkgcb,
+ warningcb,
+ False)
if __name__ == "__main__":
print('"All in one shot" method:')
@@ -221,3 +263,7 @@ if __name__ == "__main__":
print("Callback based method:")
second_method()
+ print()
+
+ print("Streaming callback based method:")
+ third_method()