def writePageSet(config, bib, tag): if tag: bib_entries = [ b for b in bib.entries if tag in b.get('www_tags', "").split() ] else: bib_entries = bib.entries[:] if not bib_entries: print >> sys.stderr, "No entries with tag %r; skipping" % tag return tagdir = config.TAG_DIRECTORIES[tag] outdir = os.path.join(config.OUTPUT_DIR, tagdir) cache_url_path = BibTeX.smartJoin("../" * pathLength(tagdir), config.CACHE_DIR) if not os.path.exists(outdir): os.makedirs(outdir, 0755) ##### Sorted views: ## By topic. entries = BibTeX.sortEntriesBy(bib_entries, "www_section", "ZZZZZZZZZZZZZZ") entries = BibTeX.splitSortedEntriesBy(entries, "www_section") if entries[-1][0].startswith("<span class='bad'>"): entries[-1] = ("Miscellaneous", entries[-1][1]) entries = [(s, BibTeX.sortEntriesByDate(ents)) for s, ents in entries] 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")), tag=tag, config=config, cache_url_path=cache_url_path) f.close() ## By date. entries = BibTeX.sortEntriesByDate(bib_entries) entries = BibTeX.splitSortedEntriesBy(entries, 'year') for idx in -1, -2: try: if entries[idx][0].startswith("<span class='bad'>"): entries[idx] = ("Unknown", entries[idx][1]) elif entries[idx][0].startswith("forthcoming"): entries[idx] = ("Forthcoming", entries[idx][1]) except IndexError: continue sections = [ent[0] for ent in entries] first_year = int(entries[0][1][0]['year']) try: last_year = int(entries[-1][1][0].get('year')) except ValueError: last_year = int(entries[-2][1][0].get('year')) years = map(str, range(first_year, last_year + 1)) if entries[-1][0] == 'Unknown': years.append("Unknown") 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")), tag=tag, config=config, cache_url_path=cache_url_path) f.close() ## By author entries, url_map = BibTeX.splitEntriesByAuthor(bib_entries) 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), ), tag=tag, config=config, cache_url_path=cache_url_path, section_urls=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] ## 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 } 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))) print >> f, footer f.close() f = open(os.path.join(outdir, "bibtex.json"), 'w') json.dump(entries, f, default=jsonDumper) f.close()
def writePageSet(config, bib, tag): if tag: bib_entries = [ b for b in bib.entries if tag in b.get('www_tags', "").split() ] else: bib_entries = bib.entries[:] if not bib_entries: print >>sys.stderr, "No entries with tag %r; skipping"%tag return tagdir = config.TAG_DIRECTORIES[tag] outdir = os.path.join(config.OUTPUT_DIR, tagdir) cache_url_path = BibTeX.smartJoin("../"*pathLength(tagdir), config.CACHE_DIR) if not os.path.exists(outdir): os.makedirs(outdir, 0755) ##### Sorted views: ## By topic. entries = BibTeX.sortEntriesBy(bib_entries, "www_section", "ZZZZZZZZZZZZZZ") entries = BibTeX.splitSortedEntriesBy(entries, "www_section") if entries[-1][0].startswith("<span class='bad'>"): entries[-1] = ("Miscellaneous", entries[-1][1]) entries = [ (s, BibTeX.sortEntriesByDate(ents)) for s, ents in entries ] 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") ), tag=tag, config=config, cache_url_path=cache_url_path) f.close() ## By date. entries = BibTeX.sortEntriesByDate(bib_entries) entries = BibTeX.splitSortedEntriesBy(entries, 'year') for idx in -1, -2: if entries[idx][0].startswith("<span class='bad'>"): entries[idx] = ("Unknown", entries[idx][1]) elif entries[idx][0].startswith("forthcoming"): entries[idx] = ("Forthcoming", entries[idx][1]) sections = [ ent[0] for ent in entries ] first_year = int(entries[0][1][0]['year']) try: last_year = int(entries[-1][1][0].get('year')) except ValueError: last_year = int(entries[-2][1][0].get('year')) years = map(str, range(first_year, last_year+1)) if entries[-1][0] == 'Unknown': years.append("Unknown") 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") ), tag=tag, config=config, cache_url_path=cache_url_path) f.close() ## By author entries, url_map = BibTeX.splitEntriesByAuthor(bib_entries) 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), ), tag=tag, config=config, cache_url_path=cache_url_path, section_urls=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 ] ## 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 } 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))) print >>f, footer f.close() f = open(os.path.join(outdir,"bibtex.json"), 'w') json.dump(entries, f, default=jsonDumper) f.close()