Skip to content

Commit b35579c

Browse files
committed
Logging
1 parent 404053d commit b35579c

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

gitbib/gitbib.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ def _fetch_crossref(ident, doi):
5555
time.sleep(1)
5656
log.debug("Request for {} returned {}".format(url, r.status_code))
5757
if r.status_code != 200:
58-
log.error("Fetching {} with doi {} failed with code {}."
59-
.format(ident, doi, r.status_code))
6058
raise NoCrossref()
6159
data = r.json()['message']
6260
c = Crossref(doi=doi, data=data)
@@ -73,8 +71,6 @@ def _fetch_arxiv(ident, arxivid):
7371
time.sleep(1)
7472
log.debug("Request for {} returned {}".format(url, r.status_code))
7573
if r.status_code != 200:
76-
log.error("Fetching {} with arxivid {} failed with code {}."
77-
.format(ident, arxivid, r.status_code))
7874
raise NoArxiv()
7975

8076
# TODO: catch xml errors?
@@ -105,7 +101,7 @@ def cache(ident, my_meta, *, session, ulog):
105101
crossref = _fetch_crossref(ident, my_meta['doi'])
106102
session.add(crossref)
107103
except NoCrossref:
108-
ulog.warn("A doi was given for {}, but it's not on crossref!".format(ident))
104+
ulog.error("A doi was given for {}, but the crossref request failed!".format(ident))
109105

110106
arxiv = None
111107
if 'arxiv' in my_meta:
@@ -118,7 +114,7 @@ def cache(ident, my_meta, *, session, ulog):
118114
arxiv = _fetch_arxiv(ident, my_meta['arxiv'])
119115
session.add(arxiv)
120116
except NoArxiv:
121-
ulog.warn("An arxiv id was given for {}, but we couldn't get the data!".format(ident))
117+
ulog.error("An arxiv id was given for {}, but we couldn't get the data!".format(ident))
122118

123119
ret = {'none': my_meta}
124120
if crossref is not None:
@@ -405,16 +401,18 @@ def _replace2(ma):
405401
return "\n".join('<p class="card-text">{}</p>'.format(s) for s in splits)
406402

407403

408-
def to_bibtype(s):
404+
def bibtype(key, entries, ulog):
409405
type_mapping = {
410406
'journal-article': 'article',
411407
# TODO: More type mappings. Is there any dx.doi.org documentation for these?
412408
}
409+
s = entries[key].get('type', '')
413410
if s in type_mapping:
414411
return type_mapping[s]
415-
log.warn("Unmapped type {}".format(s))
416-
if s is None or str(s).strip() == "":
412+
if str(s).strip() == "":
413+
ulog.warn("No type specified for {}. Using `article`".format(key))
417414
return 'article'
415+
ulog.warn("Unknown type `{}` specified for {}".format(s,key))
418416
return str(s)
419417

420418

@@ -665,10 +663,10 @@ def render_by_input_filename(entries, input_fn, *, ulog):
665663

666664

667665
class Renderfunc:
668-
def __init__(self, fn, fext, list_of_idents, entries):
666+
def __init__(self, fn, fext, list_of_idents, entries, ulog):
669667
env = Environment(loader=PackageLoader('gitbib'))
670668
env.filters['latex_escape'] = latex_escape
671-
env.filters['to_bibtype'] = to_bibtype
669+
env.filters['bibtype'] = lambda k: bibtype(k, entries, ulog)
672670
env.filters['pretty_author_list'] = pretty_author_list
673671
env.filters['bibtex_author_list'] = bibtex_author_list
674672
env.filters['to_isodate'] = to_isodate
@@ -808,7 +806,7 @@ def renderers(self, out_formats, user_logger):
808806
if len(idents) > 0:
809807
for ofmt in out_formats:
810808
yield "{}.{}".format(fn, ofmt), self.out_render_formats[ofmt], Renderfunc(fn, ofmt, list_of_idents,
811-
self.entries)
809+
self.entries, ulog=ulog)
812810
else:
813811
ulog.warn("No entries matched the specification for {}".format(fn))
814812

gitbib/templates/template.bib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% for ident in idents -%}
77
{% set entry = entries[ident] -%}
88
9-
@{{ entry['type'] | to_bibtype }}{{ '{'+ident }},
9+
@{{ ident | bibtype }}{{ '{'+ident }},
1010
author = "{{entry['author'] | bibtex_author_list}}",
1111
title = "{{entry['title']}}",
1212
{% if entry['published-online'] -%}

0 commit comments

Comments
 (0)