commit 032a4ffa9750f933b3d80738c85714751d5fdaba
parent 9a0a6efe091970ab153fbce4d8e1349332fc610f
Author: Nils Gillmann <ng0@n0.is>
Date: Sun, 7 Oct 2018 20:12:39 +0000
writeHTML.py: lint.
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat:
| M | writeHTML.py | | | 77 | ++++++++++++++++++++++++++++++++++++----------------------------------------- |
1 file changed, 36 insertions(+), 41 deletions(-)
diff --git a/writeHTML.py b/writeHTML.py
@@ -7,13 +7,13 @@ import sys
import re
import os
import json
-
-assert sys.version_info[:3] >= (2,2,0)
-os.umask(022)
-
import BibTeX
import config
+
+assert sys.version_info[:3] >= (2, 2, 0)
+os.umask(022)
+
def getTemplate(name):
f = open(name)
template = f.read()
@@ -43,7 +43,7 @@ def writeBody(f, sections, section_urls, cache_path, base_url):
(BibTeX.url_untranslate(s), u, sDisp)))
else:
print >>f, ('<li><h3><a name="%s">%s</a></h3>'%(
- BibTeX.url_untranslate(s),sDisp))
+ BibTeX.url_untranslate(s), sDisp))
print >>f, "<ul class='expand'>"
for e in entries:
print >>f, e.to_html(cache_path=cache_path, base_url=base_url)
@@ -64,7 +64,7 @@ def writeHTML(f, sections, sectionType, fieldName, choices,
hts = re.sub(r'\s+', ' ', s.strip())
hts = s.replace(" ", " ")
secStr.append("<p class='l2'><a href='#%s'>%s</a></p>\n"%
- ((BibTeX.url_untranslate(s),hts)))
+ ((BibTeX.url_untranslate(s), hts)))
secStr = "".join(secStr)
#
@@ -92,16 +92,15 @@ def writeHTML(f, sections, sectionType, fieldName, choices,
choiceStr = (" | ".join(choiceStr))
- fields = { 'command_line' : "",
- 'sectiontypes' : sectionType,
- 'choices' : choiceStr,
- 'field': fieldName,
- 'sections' : secStr,
- 'otherbibs' : tagListStr,
- 'title': title,
- 'short_title': short_title,
- "root" : root,
- }
+ fields = {'command_line' : "",
+ 'sectiontypes' : sectionType,
+ 'choices' : choiceStr,
+ 'field': fieldName,
+ 'sections' : secStr,
+ 'otherbibs' : tagListStr,
+ 'title': title,
+ 'short_title': short_title,
+ "root" : root,}
header, footer = getTemplate(config.TEMPLATE_FILE)
print >>f, header%fields
@@ -119,8 +118,8 @@ def jsonDumper(obj):
def writePageSet(config, bib, tag):
if tag:
- bib_entries = [ b for b in bib.entries
- if tag in b.get('www_tags', "").split() ]
+ bib_entries = [b for b in bib.entries
+ if tag in b.get('www_tags', "").split()]
else:
bib_entries = bib.entries[:]
@@ -143,16 +142,14 @@ def writePageSet(config, bib, tag):
if entries[-1][0].startswith("<span class='bad'>"):
entries[-1] = ("Miscellaneous", entries[-1][1])
- entries = [ (s, BibTeX.sortEntriesByDate(ents))
- for s, ents in entries
- ]
+ entries = [(s, BibTeX.sortEntriesByDate(ents))
+ for s, ents in entries]
- f = open(os.path.join(outdir,"topic.html"), 'w')
+ f = open(os.path.join(outdir, "topic.html"), 'w')
writeHTML(f, entries, "Topics", "topic",
(("By topic", None),
("By date", "./date.html"),
- ("By author", "./author.html")
- ),
+ ("By author", "./author.html")),
tag=tag, config=config,
cache_url_path=cache_url_path)
f.close()
@@ -169,7 +166,7 @@ def writePageSet(config, bib, tag):
entries[idx] = ("Forthcoming", entries[idx][1])
except IndexError:
continue
- sections = [ ent[0] for ent in entries ]
+ sections = [ent[0] for ent in entries]
first_year = int(entries[0][1][0]['year'])
try:
@@ -181,12 +178,11 @@ def writePageSet(config, bib, tag):
if entries[-1][0] == 'Unknown':
years.append("Unknown")
- f = open(os.path.join(outdir,"date.html"), 'w')
+ f = open(os.path.join(outdir, "date.html"), 'w')
writeHTML(f, entries, "Years", "date",
(("By topic", "./topic.html"),
("By date", None),
- ("By author", "./author.html")
- ),
+ ("By author", "./author.html")),
tag=tag, config=config,
cache_url_path=cache_url_path)
f.close()
@@ -194,12 +190,11 @@ def writePageSet(config, bib, tag):
## By author
entries, url_map = BibTeX.splitEntriesByAuthor(bib_entries)
- f = open(os.path.join(outdir,"author.html"), 'w')
+ f = open(os.path.join(outdir, "author.html"), 'w')
writeHTML(f, entries, "Authors", "author",
(("By topic", "./topic.html"),
("By date", "./date.html"),
- ("By author", None),
- ),
+ ("By author", None),),
tag=tag, config=config,
cache_url_path=cache_url_path,
section_urls=url_map)
@@ -208,29 +203,29 @@ def writePageSet(config, bib, tag):
## The big BibTeX file
entries = bib_entries[:]
- entries = [ (ent.key, ent) for ent in entries ]
+ entries = [(ent.key, ent) for ent in entries]
entries.sort()
- entries = [ ent[1] for ent in entries ]
+ entries = [ent[1] for ent in entries]
## Finding the root directory is done by writeHTML(), but
## the BibTeX file doesn't use that, so repeat the code here
root = "../"*pathLength(config.TAG_DIRECTORIES[tag])
if root == "": root = "."
- header,footer = getTemplate(config.BIBTEX_TEMPLATE_FILE)
- f = open(os.path.join(outdir,"bibtex.html"), 'w')
- print >>f, header % { 'command_line' : "",
- 'title': config.TAG_TITLES[tag],
- 'root': root }
+ header, footer = getTemplate(config.BIBTEX_TEMPLATE_FILE)
+ f = open(os.path.join(outdir, "bibtex.html"), 'w')
+ print >>f, header % {'command_line' : "",
+ 'title': config.TAG_TITLES[tag],
+ 'root': root}
for ent in entries:
print >>f, (
("<tr><td class='bibtex'><a name='%s'>%s</a>"
- "<pre class='bibtex'>%s</pre></td></tr>")
- %(BibTeX.url_untranslate(ent.key), ent.key, ent.format(90,8,1)))
+ "<pre class='bibtex'>%s</pre></td></tr>")
+ %(BibTeX.url_untranslate(ent.key), ent.key, ent.format(90, 8, 1)))
print >>f, footer
f.close()
- f = open(os.path.join(outdir,"bibtex.json"), 'w')
+ f = open(os.path.join(outdir, "bibtex.json"), 'w')
json.dump(entries, f, default=jsonDumper)
f.close()