From 023a13db0f872156b098cff9e6005875ea368e3d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 20 May 2003 15:43:38 +0000 Subject: Add BibTeX file, by-author listing svn:r11 --- writeHTML.py | 83 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 28 deletions(-) (limited to 'writeHTML.py') diff --git a/writeHTML.py b/writeHTML.py index 8037abd..2ffd7c7 100644 --- a/writeHTML.py +++ b/writeHTML.py @@ -5,36 +5,30 @@ import re import BibTeX import config -TEMPLATE_S, TEMPLATE_E = None, None - -def getTemplate(): - global TEMPLATE_S - global TEMPLATE_E - if not TEMPLATE_S: - f = open("_template_.html") - template = f.read() - f.close() - TEMPLATE_S, TEMPLATE_E = template.split("%(entries)s") - return TEMPLATE_S, TEMPLATE_E - -def url_untranslate(s): - s = s.replace(" ", "+") - s = re.sub(r'([%<>])', - lambda m: "%%%02x"%ord(m.group(1)), - s) - return s - -def writeBody(f, sections): +def getTemplate(name): + f = open(name+".html") + template = f.read() + f.close() + template_s, template_e = template.split("%(entries)s") + return template_s, template_e + +def writeBody(f, sections, section_urls): '''f: an open file sections: list of (sectionname, [list of BibTeXEntry])''' for s, entries in sections: - print >>f, ('

%s

'%(url_untranslate(s),s)) + u = section_urls.get(s) + if u: + print >>f, ('

%s

'%( + u, BibTeX.url_untranslate(s),s)) + else: + print >>f, ('

%s

'%( + BibTeX.url_untranslate(s),s)) print >>f, "" -def writeHTML(f, sections, sectionType, fieldName, choices): +def writeHTML(f, sections, sectionType, fieldName, choices, section_urls={}): """sections: list of (sectionname, [list of BibTeXEntry])''' sectionType: str fieldName: str @@ -43,7 +37,7 @@ def writeHTML(f, sections, sectionType, fieldName, choices): secStr = [] for s, _ in sections: secStr.append("

%s

\n"% - ((url_untranslate(s),s))) + ((BibTeX.url_untranslate(s),s))) secStr = "".join(secStr) # @@ -63,9 +57,9 @@ def writeHTML(f, sections, sectionType, fieldName, choices): 'sections' : secStr, } - header, footer = getTemplate() + header, footer = getTemplate("_template_") print >>f, header%fields - writeBody(f, sections) + writeBody(f, sections, section_urls) print >>f, footer%fields bib = BibTeX.parseFile(config.MASTER_BIB) @@ -86,7 +80,9 @@ entries = [ (s, BibTeX.sortEntriesByAuthor(ents)) f = open("topic.html", 'w') writeHTML(f, entries, "Topics", "topic", (("By topic", None), - ("By date", "./date.html"))) + ("By date", "./date.html"), + ("By author", "./author.html") + )) f.close() ## By date. @@ -107,7 +103,38 @@ if entries[-1][0] == 'Unknown': f = open("date.html", 'w') writeHTML(f, entries, "Years", "date", (("By topic", "./topic.html"), - ("By date", None))) + ("By date", None), + ("By author", "./author.html") + )) +f.close() + +## By author +entries, url_map = BibTeX.splitEntriesByAuthor(bib.entries) + +f = open("author.html", 'w') +writeHTML(f, entries, "Authors", "author", + (("By topic", "./topic.html"), + ("By date", "./date.html"), + ("By author", None), + ), + url_map) +f.close() + +## The big BibTeX file + +entries = bib.entries[:] +entries = [ (ent.key, ent) for ent in entries ] +entries.sort() +entries = [ ent[1] for ent in entries ] +header,footer = getTemplate("_template_bibtex") +f = open("bibtex.html", 'w') +print >>f, header % { 'command_line' : "" } +for ent in entries: + print >>f, ( + ("%s" + "
%s
") + %(BibTeX.url_untranslate(ent.key), ent.key, ent.format(90,8,1))) + ##print >>f, "

%s

" % ent.format(80,1) +print >>f, footer f.close() -## The big BibTeX -- cgit v1.2.3-70-g09d2