aboutsummaryrefslogtreecommitdiffstats
path: root/writeHTML.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2016-02-04 21:28:27 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2016-02-04 21:28:27 -0500
commit59dfd23bc8abc331b44c5f87e6a1b5dae3dc1036 (patch)
treeaa12195663550b7099011785521eb1c6fbc88dda /writeHTML.py
parentb0a3a31d5caaeafb63ff415fc9b86b537b759f21 (diff)
downloadanonbib-59dfd23bc8abc331b44c5f87e6a1b5dae3dc1036.tar.gz
Nicer interface for BibTeX class
Diffstat (limited to 'writeHTML.py')
-rwxr-xr-xwriteHTML.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/writeHTML.py b/writeHTML.py
index c43da6b..871839a 100755
--- a/writeHTML.py
+++ b/writeHTML.py
@@ -24,6 +24,7 @@ def getTemplate(name):
template_s, template_e = template.split("%(entries)s")
return template_s, template_e
+
def pathLength(s):
n = 0
while s:
@@ -33,6 +34,7 @@ def pathLength(s):
s = parent
return n
+
def writeBody(f, sections, section_urls, cache_path, base_url):
'''f: an open file
sections: list of (sectionname, [list of BibTeXEntry])
@@ -52,6 +54,7 @@ def writeBody(f, sections, section_urls, cache_path, base_url):
print >>f, e.to_html(cache_path=cache_path, base_url=base_url)
print >>f, "</ul></li>"
+
def writeHTML(f, sections, sectionType, fieldName, choices,
tag, config, cache_url_path, section_urls={}):
"""sections: list of (sectionname, [list of BibTeXEntry])'''
@@ -107,10 +110,11 @@ def writeHTML(f, sections, sectionType, fieldName, choices,
}
header, footer = getTemplate(config.TEMPLATE_FILE)
- print >>f, header%fields
+ print >>f, header % fields
writeBody(f, sections, section_urls, cache_path=cache_url_path,
base_url=root)
- print >>f, footer%fields
+ print >>f, footer % fields
+
def jsonDumper(obj):
if isinstance(obj, BibTeX.BibTeXEntry):
@@ -118,17 +122,18 @@ def jsonDumper(obj):
e['key'] = obj.key
return e
else:
- raise TypeError("Do not know how to serialize %s"%(obj.__class,))
+ raise TypeError("Do not know how to serialize %s" % (obj.__class,))
+
def writePageSet(config, bib, tag):
if tag:
- bib_entries = [ b for b in bib.entries.values()
+ bib_entries = [ b for b in bib
if tag in b.get('www_tags', "").split() ]
else:
- bib_entries = bib.entries.copy().values()
+ bib_entries = bib.entries.values()[:]
if not bib_entries:
- print >>sys.stderr, "No entries with tag %r; skipping"%tag
+ print >>sys.stderr, "No entries with tag %r; skipping" % tag
return
tagdir = config.TAG_DIRECTORIES[tag]