aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BibTeX.py37
-rw-r--r--rank.py2
-rwxr-xr-xupdateCache.py8
3 files changed, 21 insertions, 26 deletions
diff --git a/BibTeX.py b/BibTeX.py
index 5528df0..93e8860 100644
--- a/BibTeX.py
+++ b/BibTeX.py
@@ -24,17 +24,10 @@ class ParseError(Exception):
class BibTeX:
"""A parsed BibTeX file"""
+
def __init__(self):
self.entries = {}
- def addEntry(self, ent):
- """Add a BibTeX entry to this file."""
- k = ent.key
- if k.lower() in self.entries:
- print >> sys.stderr, "Already have an entry named %s" % k
- return
- self[k] = ent
-
def __contains__(self, key):
return key.lower() in self.entries
@@ -50,6 +43,13 @@ class BibTeX:
def __iter__(self):
return iter(self.entries.values())
+ def add_entry(self, ent):
+ """Add a BibTeX entry to this file."""
+ if ent.key in self:
+ print >> sys.stderr, "Already have an entry named %s" % ent.key
+ return
+ self[ent.key] = ent
+
def resolve(self):
"""Validate all entries in this file, and resolve cross-references"""
seen = {}
@@ -77,9 +77,9 @@ class BibTeX:
ent[k] = cr[k]
ent.resolve()
- self.remove_unrequired()
+ self.sanitize()
- def remove_unrequired(self):
+ def sanitize(self):
rk = config.REQUIRE_KEY
if rk is None:
rk = "title"
@@ -88,19 +88,14 @@ class BibTeX:
if ent.type in config.OMIT_ENTRIES or rk not in ent:
ent.check()
del self[ent.key]
-
- for ent in self:
- ent.check()
+ else:
+ ent.check()
class FileIter:
- def __init__(self, fname=None, file=None, it=None, string=None):
- if fname:
- file = open(fname, 'r')
- if string:
- file = cStringIO.StringIO(string)
- if file:
- self.iter = iter(file)
+ def __init__(self, fname):
+ file = open(fname, 'r')
+ self.iter = iter(file)
assert self.iter
self.lineno = 0
@@ -327,7 +322,7 @@ class Parser:
d[v[i].lower()] = v[i+1]
ent = BibTeXEntry(self.curEntType, key, d)
ent.entryLine = self.entryLine
- self.result.addEntry(ent)
+ self.result.add_entry(ent)
return line
diff --git a/rank.py b/rank.py
index 175a10d..ca5d5b8 100644
--- a/rank.py
+++ b/rank.py
@@ -183,7 +183,7 @@ if __name__ == '__main__':
remove_old()
print "Downloading missing ranks."
- for ent in bib.entries:
+ for ent in bib:
getCite(ent['title'], cache=True, update=True)
if suggest:
diff --git a/updateCache.py b/updateCache.py
index 7b7fe64..f247c24 100755
--- a/updateCache.py
+++ b/updateCache.py
@@ -10,6 +10,7 @@ import signal
import time
import gzip
+from utils import smartJoin
import BibTeX
import config
import urllib2
@@ -31,9 +32,8 @@ def tryUnlink(fn):
pass
def getCacheFname(key, ftype, section):
- return BibTeX.smartJoin(config.OUTPUT_DIR,config.CACHE_DIR,
- section,
- "%s.%s"%(key,ftype))
+ return smartJoin(config.OUTPUT_DIR,config.CACHE_DIR,
+ section, "%s.%s" % (key,ftype))
def downloadFile(key, ftype, section, url,timeout=None):
if timeout is None:
@@ -111,7 +111,7 @@ def getCachedURL(key, ftype, section):
def downloadAll(bibtex, missingOnly=0):
"""returns list of tuples of key, ftype, url, error"""
errors = []
- for e in bibtex.entries:
+ for e in bibtex:
urls = getURLs(e)
key = e.key
section = e.get("www_cache_section", ".")