aboutsummaryrefslogtreecommitdiffstats
path: root/reconcile.py
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-11-26 06:20:01 +0000
committerNick Mathewson <nickm@torproject.org>2006-11-26 06:20:01 +0000
commitadc4079a71c331fcb5c0d506a9d152307b5daeb2 (patch)
tree6e69e7e550527b123bdabdb92fa72bb407b5b633 /reconcile.py
parentfacf12ce463ba1c05b9147f2e79de550864af4a8 (diff)
downloadanonbib-adc4079a71c331fcb5c0d506a9d152307b5daeb2.tar.gz
r9809@Kushana: nickm | 2006-11-26 01:14:14 -0500
Write command-line code in a check for __name__=="__main__" so I can run anonbib stuff through pychecker. svn:r186
Diffstat (limited to 'reconcile.py')
-rw-r--r--reconcile.py77
1 files changed, 39 insertions, 38 deletions
diff --git a/reconcile.py b/reconcile.py
index 46ba1a4..5df1465 100644
--- a/reconcile.py
+++ b/reconcile.py
@@ -242,49 +242,50 @@ def emitKnown(f, ent, matches):
print >>f, "%%"
print >>f, "%"+(ent.format(77,4,1,invStrings).replace("\n", "\n%"))
-if len(sys.argv) != 2:
- print "reconcile.py expects 1 argument"
- sys.exit(1)
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print "reconcile.py expects 1 argument"
+ sys.exit(1)
-print "========= Scanning master =========="
-master = MasterBibTeX()
-master = BibTeX.parseFile(config.MASTER_BIB, master)
-master.buildIndex()
+ print "========= Scanning master =========="
+ master = MasterBibTeX()
+ master = BibTeX.parseFile(config.MASTER_BIB, master)
+ master.buildIndex()
-print "========= Scanning new file ========"
-try:
- fn = sys.argv[1]
- input = BibTeX.parseFile(fn)
-except BibTeX.ParseError, e:
- print "Error parsing %s: %s"%(fn,e)
- sys.exit(1)
+ print "========= Scanning new file ========"
+ try:
+ fn = sys.argv[1]
+ input = BibTeX.parseFile(fn)
+ except BibTeX.ParseError, e:
+ print "Error parsing %s: %s"%(fn,e)
+ sys.exit(1)
-f = open('tmp.bib', 'w')
-keys = input.newStrings.keys()
-keys.sort()
-for k in keys:
- v = input.newStrings[k]
- print >>f, "@string{%s = {%s}}"%(k,v)
+ f = open('tmp.bib', 'w')
+ keys = input.newStrings.keys()
+ keys.sort()
+ for k in keys:
+ v = input.newStrings[k]
+ print >>f, "@string{%s = {%s}}"%(k,v)
-invStrings = input.invStrings
+ invStrings = input.invStrings
-for e in input.entries:
- if not (e.get('title') and e.get('author')):
- print >>f, "%%\n%%%% Not enough information to search for a match: need title and author.\n%%"
- emit(f, e)
- continue
+ for e in input.entries:
+ if not (e.get('title') and e.get('author')):
+ print >>f, "%%\n%%%% Not enough information to search for a match: need title and author.\n%%"
+ emit(f, e)
+ continue
- matches = master.includes(e, all=1)
- if not matches:
- print >>f, "%%\n%%%% This entry is probably new: No match found.\n%%"
- emit(f, e)
- else:
- print >>f, "%%"
- print >>f, "%%%% Possible match found for this entry; max goodness",\
- matches[-1][0], "\n%%"
- emitKnown(f, e, matches)
+ matches = master.includes(e, all=1)
+ if not matches:
+ print >>f, "%%\n%%%% This entry is probably new: No match found.\n%%"
+ emit(f, e)
+ else:
+ print >>f, "%%"
+ print >>f, "%%%% Possible match found for this entry; max goodness",\
+ matches[-1][0], "\n%%"
+ emitKnown(f, e, matches)
-if not all_ok:
- print >>f, "\n\n\nErrors remain; not finished.\n"
+ if not all_ok:
+ print >>f, "\n\n\nErrors remain; not finished.\n"
-f.close()
+ f.close()