feat(cmd import): exclude bibtex fields if specified
This commit is contained in:
parent
5a10a5631b
commit
b9c65bda39
@ -40,7 +40,7 @@ def parser(subparsers, conf):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def many_from_path(ui, bibpath, ignore=False):
|
def many_from_path(ui, bibpath, bibfield_excludes=[], ignore=False):
|
||||||
"""Extract list of papers found in bibliographic files in path.
|
"""Extract list of papers found in bibliographic files in path.
|
||||||
|
|
||||||
The behavior is to:
|
The behavior is to:
|
||||||
@ -62,7 +62,13 @@ def many_from_path(ui, bibpath, ignore=False):
|
|||||||
biblist = []
|
biblist = []
|
||||||
for filepath in all_files:
|
for filepath in all_files:
|
||||||
try:
|
try:
|
||||||
biblist.append(coder.decode_bibdata(read_text_file(filepath)))
|
bibentry = coder.decode_bibdata(read_text_file(filepath))
|
||||||
|
# exclude bibtex fields if specified
|
||||||
|
for item in bibentry.values():
|
||||||
|
for field in bibfield_excludes:
|
||||||
|
if field in item:
|
||||||
|
del item[field]
|
||||||
|
biblist.append(bibentry)
|
||||||
except coder.BibDecodingError:
|
except coder.BibDecodingError:
|
||||||
error = "Could not parse bibtex at {}.".format(filepath)
|
error = "Could not parse bibtex at {}.".format(filepath)
|
||||||
if ignore:
|
if ignore:
|
||||||
@ -100,7 +106,9 @@ def command(conf, args):
|
|||||||
|
|
||||||
rp = repo.Repository(conf)
|
rp = repo.Repository(conf)
|
||||||
# Extract papers from bib
|
# Extract papers from bib
|
||||||
papers = many_from_path(ui, bibpath, ignore=args.ignore_malformed)
|
papers = many_from_path(ui, bibpath,
|
||||||
|
bibfield_excludes=conf['main']['bibtex_field_excludes'],
|
||||||
|
ignore=args.ignore_malformed)
|
||||||
keys = args.keys or papers.keys()
|
keys = args.keys or papers.keys()
|
||||||
for k in keys:
|
for k in keys:
|
||||||
p = papers[k]
|
p = papers[k]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user