--- /dev/null
+#!/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))