From c07e917777582ff1e70e8b57345397ef977d684e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 17 May 2003 07:44:15 +0000 Subject: Work on HTML generation svn:r8 --- .cvsignore | 2 + BibTeX.py | 70 ++++++++++++++----------- _template_.html | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.py | 42 +++++++++++++++ css/pubs.css | 5 ++ writeHTML.py | 36 ++++++++++++- 6 files changed, 282 insertions(+), 32 deletions(-) create mode 100644 .cvsignore create mode 100644 _template_.html create mode 100644 config.py diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..52e4e61 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,2 @@ +*.pyc +*.pyo diff --git a/BibTeX.py b/BibTeX.py index ad2d04e..9444a65 100644 --- a/BibTeX.py +++ b/BibTeX.py @@ -4,21 +4,13 @@ import cStringIO import re import sys +import config + __all__ = ( 'ParseError', 'BibTeX', 'BibTeXEntry', 'htmlize', 'ParsedAuthor', 'FileIter', 'Parser', 'parseFile', 'splitBibTeXEntriesBy', 'sortBibTexEntriesBy', ) - -INITIAL_STRINGS = { - 'jan' : 'January', 'feb' : 'February', - 'mar' : 'March', 'apr' : 'April', - 'may' : 'May', 'jun' : 'June', - 'jul' : 'July', 'aug' : 'August', - 'sep' : 'September', 'oct' : 'October', - 'nov' : 'November', 'dec' : 'December' - } - class ParseError(Exception): pass @@ -50,8 +42,15 @@ class BibTeX: del ent.entries['crossref'] ent.entries.update(cr.entries) ent.resolve() + newEntries = [] + for ent in self.entries: + if ent.type in config.OMIT_ENTRIES: + del self.byKey[ent.key] + else: + newEntries.append(ent) + self.entries = newEntries -def splitBibTeXEntriesBy(entries, field): +def splitEntriesBy(entries, field): result = {} for ent in entries: key = ent.get(field) @@ -61,8 +60,8 @@ def splitBibTeXEntriesBy(entries, field): result[key] = [ent] return result -def sortBibTeXEntriesBy(self, field): - tmp = [ ent.get(field), ent for ent in entries ] +def sortEntriesBy(self, field): + tmp = [ (ent.get(field), ent) for ent in entries ] tmp.sort() return [ t[2] for t in tmp ] @@ -81,6 +80,8 @@ class BibTeXEntry: return self.entries.get(k,v) def __getitem__(self, k): return self._get(k) + def __setitem__(self, k, v): + self.entries[k] = v def __str__(self): return self.format(70,1) def format(self, width=70,v=0): @@ -111,12 +112,10 @@ class BibTeXEntry: self.parsedAuthor = None def check(self): ok = 1 - if self.type in ('proceedings', 'journal'): - return 1 - elif self.type == 'inproceedings': - fields = 'booktitle', 'month', 'year' + if self.type == 'inproceedings': + fields = 'booktitle', 'year' elif self.type == 'article': - fields = 'journal', 'month', 'year' + fields = 'journal', 'year' elif self.type == 'techreport': fields = 'institution', 'number' elif self.type == 'misc': @@ -128,7 +127,7 @@ class BibTeXEntry: for field in fields: if not self.get(field): print "ERROR: %s has no %s field" % (self.key, field) - self.entries[field] = "???" + self.entries[field] = "%s:??"%field ok = 0 return ok @@ -153,7 +152,7 @@ class BibTeXEntry: if self.get("address"): res.append(",") res.append(self['address']) - res.append(", %s %s" % (self['month'], self['year'])) + res.append(", %s %s" % (self.get('month',""), self['year'])) if not self.get('pages'): pass elif "-" in self['pages']: @@ -171,7 +170,7 @@ class BibTeXEntry: res.append(" %s"%self['volume']) if self.get('number'): res.append("(%s)"%self['number']) - res.append(", %s %s" % (self['month'], self['year'])) + res.append(", %s %s" % (self.get('month',""), self['year'])) if not self.get('pages'): pass elif "-" in self['pages']: @@ -212,10 +211,11 @@ class BibTeXEntry: res = ["<Odd type %s>"%self.type] res[0:0] = [""] - res.append("") - res.append("" - "(BibTex  entry)") + res.append(" " + "(BibTeX entry)" + "") return htmlize("".join(res)) def to_html(self): @@ -226,15 +226,16 @@ class BibTeXEntry: ('www_html_url', 'HTML'), ('www_pdf_url', 'PDF'), ('www_ps_url', 'PS'), + ('www_txt_url', 'TXT'), ('www_ps_gz_url', 'gzipped PS')): - url = self.get('key') + url = self.get(key) if not url: continue availability.append('%s' %(url,name)) if availability: res.append(" (") res.append(", ".join(availability)) - res.append("") + res.append(")") + res.append("
by ") #res.append("\n\n" % self.parsedAuthor) htmlAuthors = [] @@ -243,7 +244,15 @@ class BibTeXEntry: a = " ".join(f+v+l) if j: a = "%s, %s" %(a,j) - htmlAuthors.append(htmlize(a)) + a = htmlize(a) + htmlAuthor = None + for pat, url in config.AUTHOR_RE_LIST: + if pat.search(a): + htmlAuthor = '%s' % (url, a) + break + if not htmlAuthor: + htmlAuthor = a + htmlAuthors.append(htmlAuthor) if len(htmlAuthors) == 1: res.append(htmlAuthors[0]) elif len(htmlAuthors) == 2: @@ -426,7 +435,7 @@ def split_von(f,v,l,x): class Parser: def __init__(self, fileiter, initial_strings): - self.strings = INITIAL_STRINGS.copy() + self.strings = config.INITIAL_STRINGS.copy() self.strings.update(initial_strings) self.fileiter = fileiter self.entries = {} @@ -650,8 +659,7 @@ def parseFile(filename): r.resolve() for e in r.entries: e.check() - return r - + return r if __name__ == '__main__': import sys diff --git a/_template_.html b/_template_.html new file mode 100644 index 0000000..7dafac9 --- /dev/null +++ b/_template_.html @@ -0,0 +1,159 @@ + + + + + + + +Anonymity Bibliography + + + + + + + + + + + +

Anonymity bibliography

+%(choices)s +

By subject | By date

+ +
+ + + + + + + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +


Publication search:
+


Subjects:
+ +%(sections)s + +

+
+ +

Publications by %(field)s

+ +
    +%(entries)s +
+ +

+ + + + diff --git a/config.py b/config.py new file mode 100644 index 0000000..cf7a4b2 --- /dev/null +++ b/config.py @@ -0,0 +1,42 @@ + +import re + +AUTHOR_URLS = { + 'Berthold' : 'http://page.inf.fu-berlin.de/~berthold/', + 'Miguel.*Castro' : 'http://research.microsoft.com/users/mcastro/', + 'Chaum' : 'http://www.chaum.org', + 'Danezis' : 'http://www.cl.cam.ac.uk/~gd216/', + 'Dingledine' : 'http://www.freehaven.net/~arma/cv.html', + 'Desmedt' : 'http://www.cs.fsu.edu/~desmedt/', + 'Jakobsson' : 'http://www.cs.ucsd.edu/users/markus/', + 'K.*Kurosawa' : 'http://kuro.cis.ibaraki.ac.jp/~kurosawa/', + 'B.*Liskov' : 'http://www.pmg.lcs.mit.edu/barbara_liskov.html', + 'Mathewson' : 'http://www.wangafu.net/~nickm/', + 'Mazières' : 'http://www.scs.cs.nyu.edu/~dm/', + 'A.*Pfitzmann' : 'http://dud.inf.tu-dresden.de/~pfitza/', + 'B.*Pfitzmann' : 'http://www.zurich.ibm.com/~bpf/', + 'Rivest' : 'http://theory.lcs.mit.edu/~rivest/', + 'Serjantov' : 'http://www.cl.cam.ac.uk/users/aas23/', + 'Syverson' : 'http://www.syverson.org/', + 'David.*Wagner' : 'http://www.cs.berkeley.edu/~daw/', + 'Shoup' : 'http://www.shoup.net/', + 'B.*Möller' : 'http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html', + + } + +INITIAL_STRINGS = { + 'jan' : 'January', 'feb' : 'February', + 'mar' : 'March', 'apr' : 'April', + 'may' : 'May', 'jun' : 'June', + 'jul' : 'July', 'aug' : 'August', + 'sep' : 'September', 'oct' : 'October', + 'nov' : 'November', 'dec' : 'December' + } + +OMIT_ENTRIES = ("proceedings", "journal") + +### Don't edit below this line + +AUTHOR_RE_LIST = [ + (re.compile(k, re.I), v,) for k, v in AUTHOR_URLS.iteritems() + ] diff --git a/css/pubs.css b/css/pubs.css index 3a5d623..7281a1d 100644 --- a/css/pubs.css +++ b/css/pubs.css @@ -27,6 +27,11 @@ SPAN.biblio A { text-decoration: underline; } +SPAN.bad { + text-decoration: underline; + background-color: #FDF; +} + P.l1 { margin-left: 0.5em; } diff --git a/writeHTML.py b/writeHTML.py index 689014e..0d2d41a 100644 --- a/writeHTML.py +++ b/writeHTML.py @@ -1,6 +1,40 @@ #!/usr/bin/python -import BiBTeX +import BibTeX +import config +bib = BibTeX.parseFile("anonbib.bib") +f = open("_template_.html") +template = f.read() +f.close() + +f = open("z.html", 'w') + +template_s, template_e = template.split("%(entries)s") + +print >>f, template_s + +entries = BibTeX.splitEntriesBy(bib.entries, "www_section") +sections = entries.keys() +sections.sort() +if entries.has_key(None): + for ent in entries[None]: + ent['www_section'] = "Miscellaneous" + + entries["Miscellaneous"] = entries[None] + del entries[None] + sections.append("Miscellaneous") + sections = filter(None, sections) + +for s in sections: + #XXX print '

'; + print >>f, '

%s

'%s + print >>f, "
    " + for e in entries[s]: + print >>f, e.to_html() + print >>f, "
" + + +print >>f, template_e -- cgit v1.2.3-70-g09d2