-
Notifications
You must be signed in to change notification settings - Fork 0
/
citebib
executable file
·67 lines (55 loc) · 2.35 KB
/
citebib
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>
#
# Author: Francois Boulogne <fboulogne at sciunto dot org>, 2012
import argparse
from libcitebib import info
from libcitebib import __version__ as version
from libcitebib.main import main
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=info.SHORT_DESCRIPTION,
epilog='')
parser.add_argument('--version', action='version', version=version)
parser.add_argument('--latex', help='LateX type output', action='store_true')
parser.add_argument('-c', metavar='CONFIG', required=False, help='Configuration file with bibtex paths')
parser.add_argument('-b', metavar='BIBTEX', nargs='*', required=False, help='Bibtex file(s)')
parser.add_argument('-t', metavar='TEX', nargs='+', required=True, help='Tex file(s)')
parser.add_argument('-o', metavar='OUTPUT', required=False, help='Output (default: stdout)')
args = parser.parse_args()
bibfiles = args.b
texfiles = args.t
from libcitebib.config import check_default_config
check_default_config()
from libcitebib.importer import get_bibtex_entries, get_citations
#Load the tex
citations = get_citations(texfiles)
from libcitebib.config import ConfigBibtex
if bibfiles is None:
if args.c is not None:
import os.path
location, name = os.path.split(args.c)
bib = ConfigBibtex(name, location)
else:
bib = ConfigBibtex()
bibfiles = bib.get_bibtex_paths()
if args.latex:
format = 'latex'
else:
format = 'bibtex'
if args.o == None:
main(bibfiles, citations, format)
else:
with open(args.o, 'w') as f:
main(bibfiles, citations, format, f)