reprepro: presents & generates a Debian repository
authorFredrik Unger <fred@tree.se>
Wed, 19 Dec 2012 09:46:53 +0000 (10:46 +0100)
committerFredrik Unger <fred@tree.se>
Wed, 19 Dec 2012 09:46:53 +0000 (10:46 +0100)
Added a new script that presents and generates a Debian repository
for the selected reprepro. It generates links that then assures that
the files also gets moved to the correct location.

xinclude/reprepro.py [new file with mode: 0755]

diff --git a/xinclude/reprepro.py b/xinclude/reprepro.py
new file mode 100755 (executable)
index 0000000..94bb34e
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+from shutil import rmtree,copytree
+
+from lxml import etree
+from lxml.builder import ElementMaker
+
+from treecutter import constants as const
+
+class Reprepro(object):
+    def __init__(self, uri):
+        self.uri = uri
+        self.filelist = []
+
+    def files(self):
+        dirs = ['dists','pool']
+        rootdirs = [self.uri+'/'+d for d in dirs]
+        for rootdir,d in zip(rootdirs,dirs):
+            if os.path.exists(d):
+                rmtree(d)
+            copytree(rootdir, d)
+        for d in dirs:
+            for root, subdir, files in os.walk(d):
+                for file in files:
+                    self.filelist.append(os.path.join(root,file))
+
+    def db_xml(self):
+        db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
+        co = db.computeroutput()
+        for f in self.filelist:
+            co.append(db.filename(db.link(f,**{const.XLINK+"href": f})))
+        return db.para(co)
+
+def recursively_empty(e):
+    if e.text:
+        return False
+    return all((recursively_empty(c) for c in e.iterchildren()))
+
+def clean_db(xml):
+    context = etree.iterwalk(xml)
+    for action, elem in context:
+        parent = elem.getparent()
+        if recursively_empty(elem):
+            parent.remove(elem)
+
+if __name__ == "__main__":
+    for arg in sys.argv[1:]:
+        al = arg.split("=",1)
+        if al[0] == "lang":
+            lang = al[1]
+        if al[0] == "xptr":
+            argument = al[1]
+
+    repo = Reprepro(argument)
+    repo.files()
+    rxml = repo.db_xml()
+    clean_db(rxml)
+
+    #print(etree.tostring(cxml, pretty_print=True))
+    #sys.stdout.write(out.encode('utf-8'))
+    sys.stdout.write(etree.tostring(rxml,encoding='UTF-8',pretty_print=True))