in retire.py [0:0]
def update_stylesheet(pid):
xmlfile = join(stylesheets,'project.xml')
xmlfilet = join(stylesheets,'project.xml.t')
print("Updating %s" % xmlfile)
found = False
with open(xmlfile,'r') as r, open(xmlfilet,'w') as w:
for l in r:
if not found:
m = re.search(r'^(\s+<li><a href="/projects/)([^.]+)(.html">)[^<]+(</a></li>)', l)
if m:
stem = m.group(2)
if stem == pid:
print("Already present in projects.xml")
print(l)
w.close()
os.remove(xmlfilet)
return
if stem > pid: # Found insertion point
found = True
name = retirees[pid]['display_name']
w.write("%s%s%s%s%s\n" % (m.group(1), pid, m.group(3), name, m.group(4)))
w.write(l) # write the original line
if found:
print("Successfully added %s to %s" % (pid, xmlfile))
os.system("diff %s %s" % (xmlfile, xmlfilet))
os.rename(xmlfilet, xmlfile)
else:
print("Could not find where to add %s" % pid)