#!/usr/bin/python2.2 # Make sure tabs expand to 8 spaces in vim # vim: expandtab import os.path, rfc822, sys, string, re from xml.dom import implementation, ext from config import dir, odir """if os.path.isdir("incoming"): dir = "incoming" elif os.path.isdir("../incoming"): dir = "../incoming" else: dir = "/home/rhertzog/shared/paquets/debian/pts/incoming" odir = dir + "/../base" """ def add_maintainer_info(child, content, doc): (name, email) = rfc822.parseaddr(content) text = doc.createTextNode(unicode(name,'iso-8859-1')) # Take care of non-ascii item_elt = doc.createElement("name") item_elt.appendChild(text) child.appendChild(item_elt) text = doc.createTextNode(email) item_elt = doc.createElement("email") item_elt.appendChild(text) child.appendChild(item_elt) def update_sources_info(m, dist): """Update the XML information with the given Message (Package entry)""" global odir # Make sure the directory exists package = m["Package"] hash = package[0] if package[0:3] == "lib": hash = package[0:4] if not os.path.isdir(odir + "/" + hash + "/" + package): if not os.path.isdir(odir + "/" + hash): os.mkdir(odir + "/" + hash) os.mkdir(odir + "/" + hash + "/" + package) # Create the XML DOM object doc = implementation.createDocument(None, None, None) root = doc.createElement("source") doc.appendChild(root) root.setAttribute("release", dist); if re.search("-\d+\.\d+(\.\d+)?$", m["version"]): root.setAttribute("nmu", "yes") for tag in m.keys(): child = doc.createElement(tag) root.appendChild(child) if tag == "binary" or tag[0:5] == "build": for item in re.split(", ?", m[tag]): text = doc.createTextNode(item) item_elt = doc.createElement("item") item_elt.appendChild(text) child.appendChild(item_elt) elif tag == "maintainer": add_maintainer_info(child, m[tag], doc) elif tag == "uploaders": for item in re.split(", ?", m[tag]): item_elt = doc.createElement("item") add_maintainer_info(item_elt, item, doc) child.appendChild(item_elt) elif tag == "files": for line in string.split(m[tag], "\n"): item_elt = doc.createElement("item") child.appendChild(item_elt) line = line.strip() fields = ["md5sum", "size", "filename"] values = string.split(line) for i in range(len(fields)): new_elt = doc.createElement(fields[i]) text = doc.createTextNode(values[i]) new_elt.appendChild(text) item_elt.appendChild(new_elt) else: text = doc.createTextNode(m[tag]) child.appendChild(text) # Print the DOM object to a file try: f = open("%s/%s/%s/%s.xml" % (odir, hash, package, dist), "w") ext.PrettyPrint(doc, f, "iso-8859-1") f.close() except: sys.stderr.write("Output problem for" + m["package"] + "\n"); def treat_sources_file(f, dist): """Scan the given Sources file and treat each Package entry""" while 1: try: m = rfc822.Message(f) if len(m) == 0: #eof break update_sources_info(m, dist) except EOFError: break for comp in ["main", "contrib", "non-free"]: for dist in ["stable", "testing", "unstable"]: f = open(dir + "/Sources_%s_%s" % (dist, comp), "r") treat_sources_file(f, dist) f.close() f = open(dir + "/Sources-nonus_%s_%s" % (dist, comp), "r") treat_sources_file(f, dist) f.close() # Experimental f = open(dir + "/Sources-experimental_" + comp, "r") treat_sources_file(f, "experimental") f.close()