From adc4079a71c331fcb5c0d506a9d152307b5daeb2 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 26 Nov 2006 06:20:01 +0000 Subject: 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 --- reconcile.py | 93 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 46 deletions(-) (limited to 'reconcile.py') 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) - -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) - -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 - -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) - -if not all_ok: - print >>f, "\n\n\nErrors remain; not finished.\n" - -f.close() +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 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) + + 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 + + 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" + + f.close() -- cgit v1.2.3-70-g09d2