def update_xml()

in scripts/newtlp.py [0:0]


def update_xml(pid):
    xmlfile = os.path.join(DATADIR,'committees.xml')
    xmlfilet = os.path.join(DATADIR,'committees.xml.t')
    print("Updating committees.xml")
    notYetFound = True
    with open(xmlfile,'r') as r, open(xmlfilet,'w') as w:
        for l in r:
            if notYetFound:
                m = re.search("^(\\s+)<location>committees/(.+)\\.rdf<",l)
                if m:
                    indent = m.group(1)
                    mid = m.group(2)
                    if mid > pid: # found insertion point
                        w.write("%s<location>committees/%s.rdf</location>\n" % (indent, pid))
                        notYetFound = False
                    elif mid == pid:
                        print("ERROR: committees.xml already contains %s" % pid)
                        w.close()
                        os.remove(xmlfilet)
                        return
                else:
                    if l.startswith("</list"): # EOF
                        w.write("%s<location>committees/%s.rdf</location>\n" % (indent, pid))
                        notYetFound = False
            w.write(l) # write the original line
    os.rename(xmlfilet,xmlfile)