2 # -*- coding: utf-8 -*-
6 from shutil import rmtree,copytree
9 from lxml.builder import ElementMaker
11 from treecutter import constants as const
13 class Reprepro(object):
14 def __init__(self, uri):
19 dirs = ['dists','pool']
20 rootdirs = [self.uri+'/'+d for d in dirs]
21 for rootdir,d in zip(rootdirs,dirs):
26 for root, subdir, files in os.walk(d):
28 self.filelist.append(os.path.join(root,file))
31 db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
32 co = db.computeroutput()
33 for f in self.filelist:
34 co.append(db.filename(db.link(f,**{const.XLINK+"href": f})))
37 def recursively_empty(e):
40 return all((recursively_empty(c) for c in e.iterchildren()))
43 context = etree.iterwalk(xml)
44 for action, elem in context:
45 parent = elem.getparent()
46 if recursively_empty(elem):
49 if __name__ == "__main__":
50 for arg in sys.argv[1:]:
57 repo = Reprepro(argument)
62 #print(etree.tostring(cxml, pretty_print=True))
63 #sys.stdout.write(out.encode('utf-8'))
64 sys.stdout.write(etree.tostring(rxml,encoding='UTF-8',pretty_print=True))