From b568714b60aa9ba2a7b10c5730c5fa5d4ef29ce1 Mon Sep 17 00:00:00 2001 From: Fredrik Unger Date: Wed, 19 Dec 2012 10:46:53 +0100 Subject: [PATCH] reprepro: presents & generates a Debian repository 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 | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 xinclude/reprepro.py diff --git a/xinclude/reprepro.py b/xinclude/reprepro.py new file mode 100755 index 0000000..94bb34e --- /dev/null +++ b/xinclude/reprepro.py @@ -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)) -- 2.30.2