From c666e2e0794ba284b5a0c0f17d54c4a3233ea187 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 9 Sep 2003 00:25:29 +0000 Subject: Add a simple caching implementation svn:r67 --- BibTeX.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'BibTeX.py') diff --git a/BibTeX.py b/BibTeX.py index ac5ba5d..b9d36ec 100644 --- a/BibTeX.py +++ b/BibTeX.py @@ -3,6 +3,7 @@ import cStringIO import re import sys +import os import config @@ -414,21 +415,33 @@ class BibTeXEntry: res.append("%s"%( url_untranslate(self.key),htmlize(self['title']))) - availability = [] - for key, name in (('www_abstract_url', 'abstract'), - ('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) - if not url: continue - url = unTeXescapeURL(url) - availability.append('%s' %(url,name)) - if availability: - res.append(" (") - res.append(", ".join(availability)) - res.append(")") + for cached in 0,1: + availability = [] + for key, name, ext in (('www_abstract_url', 'abstract','abstract'), + ('www_html_url', 'HTML', 'html'), + ('www_pdf_url', 'PDF', 'pdf'), + ('www_ps_url', 'PS', 'ps'), + ('www_txt_url', 'TXT', 'txt'), + ('www_ps_gz_url', 'gzipped PS','ps.gz') + ): + if cached: + url = os.path.join(".", config.CACHE_DIR, + "%s.%s"%(self.key,ext)) + fname = os.path.join(config.OUTPUT_DIR, config.CACHE_DIR, + "%s.%s"%(self.key,ext)) + if not os.path.exists(fname): continue + else: + url = self.get(key) + if not url: continue + url = unTeXescapeURL(url) + availability.append('%s' %(url,name)) + + if availability: + res.append(" (") + if cached: res.append("Cached: ") + res.append(", ".join(availability)) + res.append(")") + res.append("
by ") #res.append("\n\n" % self.parsedAuthor) -- cgit v1.2.3-70-g09d2