-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
38 lines (31 loc) · 1.16 KB
/
driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import argparse, os
import bibutil.fuzzy_match, bibutil.html
import bibtexparser
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(filename='bibutil.log', filemode='w', level=logging.WARNING)
parser = argparse.ArgumentParser(description='Utilities for BibTex files.')
def valid_file(param):
base, ext = os.path.splitext(param)
if ext == '' or ext.lower() not in ('.bib'):
parser.error('Expect bibtex file (.bib)')
if not os.path.isfile(param):
parser.error('File not found')
return param
def main():
parser.add_argument('--dups', action='store_true', help='Find duplicates (fuzzy match)')
parser.add_argument('--html', action='store_true', help='Generate HTML (Bootstap flavoured)')
parser.add_argument('bibfile', type=valid_file, help='BibTex file')
args = parser.parse_args()
bibdb = None
with open(args.bibfile) as bibfile:
bibdb = bibtexparser.load(bibfile)
if args.dups :
bibutil.fuzzy_match.main(bibdb)
elif args.html :
bibutil.html.main(bibdb)
else:
print 'No action specified\n'
parser.print_help()
if __name__ == "__main__":
main()