From: Luke Macken Date: Sun, 8 Feb 2015 05:30:33 +0000 (-0700) Subject: Examples: Add a simple modifyrepo python example X-Git-Tag: upstream/0.10.0~129^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfdc977be96b9d01b8dbbec3ae5b26c92c11290c;p=services%2Fcreaterepo_c.git Examples: Add a simple modifyrepo python example --- diff --git a/examples/python/simple_modifyrepo.py b/examples/python/simple_modifyrepo.py new file mode 100644 index 0000000..99721e5 --- /dev/null +++ b/examples/python/simple_modifyrepo.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +""" +An example of inserting updateinfo.xml into repodata. +""" +import os +import shutil + +import createrepo_c as cr + +REPO_PATH = "repo/" + + +def modifyrepo(filename, repodata): + repodata = os.path.join(repodata, 'repodata') + uinfo_xml = os.path.join(repodata, 'updateinfo.xml') + shutil.copyfile(filename, uinfo_xml) + + uinfo_rec = cr.RepomdRecord('updateinfo', uinfo_xml) + uinfo_rec_comp = uinfo_rec.compress_and_fill(cr.SHA256, cr.XZ) + uinfo_rec_comp.rename_file() + uinfo_rec_comp.type = 'updateinfo' + os.unlink(uinfo_xml) + + repomd_xml = os.path.join(repodata, 'repomd.xml') + repomd = cr.Repomd(repomd_xml) + repomd.set_record(uinfo_rec_comp) + with file(repomd_xml, 'w') as repomd_file: + repomd_file.write(repomd.xml_dump()) + + +if __name__ == '__main__': + # Generate the updateinfo.xml + execfile('updateinfo_gen_02.py') + + modifyrepo(OUT_FILE, REPO_PATH)