[GRASS-SVN] r72921 - sandbox/wenzeslaus/g.citation
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 28 17:57:51 PDT 2018
Author: wenzeslaus
Date: 2018-06-28 17:57:51 -0700 (Thu, 28 Jun 2018)
New Revision: 72921
Modified:
sandbox/wenzeslaus/g.citation/g.citation.py
Log:
g.citation: add Chicago style for footnotes (uses names as they are)
Modified: sandbox/wenzeslaus/g.citation/g.citation.py
===================================================================
--- sandbox/wenzeslaus/g.citation/g.citation.py 2018-06-28 23:37:08 UTC (rev 72920)
+++ sandbox/wenzeslaus/g.citation/g.citation.py 2018-06-29 00:57:51 UTC (rev 72921)
@@ -36,8 +36,8 @@
#% key: format
#% type: string
#% description: Citation format or style
-#% options: bibtex,cff,json,pretty-json,dict,plain
-#% descriptions: bibtex;BibTeX;cff;Citation File Format;json;JSON;pretty-json;Pretty printed JSON;dict;Pretty printed Python dictionary;plain;Plain text
+#% options: bibtex,cff,json,pretty-json,chicago-footnote,dict,plain
+#% descriptions: bibtex;BibTeX;cff;Citation File Format;json;JSON;pretty-json;Pretty printed JSON;chicago-footnote;Chicago style for footnotes;dict;Pretty printed Python dictionary;plain;Plain text
#% answer: bibtex
#% required: yes
#%end
@@ -339,18 +339,33 @@
sort_keys=True))
+def print_chicago_footnote(citation):
+ num_authors = len(citation['authors'])
+ authors_text = ""
+ for i, author in enumerate(citation['authors']):
+ authors_text += author['name']
+ if i < num_authors - 2:
+ authors_text += ", "
+ elif i < num_authors - 1:
+ # likely with comma but unclear for footnote style
+ authors_text += ", and "
+ title = "GRASSS GIS module {}".format(citation['module'])
+ print("{authors_text}, {title} ({grass-version}), computer software"
+ " ({year}).".format(
+ authors_text=authors_text, title=title, **citation))
+
+
def print_plain(citation):
"""Create citation from dictionary as plain text
>>> print_plain({'module': 'g.tst', 'authors': [{'name': 'Joe Doe'}]})
- GRASSS GIS module g.tst
+ GRASS GIS module g.tst
Joe Doe
"""
- print("GRASSS GIS module", citation['module'])
+ print("GRASS GIS module", citation['module'])
num_authors = len(citation['authors'])
authors_text = ""
for i, author in enumerate(citation['authors']):
- author_name = [ ]
authors_text += author['name']
# TODO: not defined if we need institute etc. or not, perhaps
# use default dict
@@ -370,6 +385,7 @@
'cff': print_cff,
'json': print_json,
'pretty-json': print_pretty_json,
+ 'chicago-footnote': print_chicago_footnote,
'plain': print_plain,
'dict': lambda d: pprint(dict(d)), # only plain dict pretty prints
}
@@ -377,10 +393,12 @@
def print_citation(citation, format):
"""Create citation from dictionary in a given format"""
+ # only catch the specific dict access, don't call the function
try:
- _FORMAT_FUNCTION[format](citation)
+ function = _FORMAT_FUNCTION[format]
except KeyError:
raise RuntimeError(_("Unsupported format or style: %s" % format))
+ function(citation)
def citation_for_module(name):
@@ -392,10 +410,14 @@
text = open(path).read()
+ g_version = gs.parse_command("g.version", flags="g")
+
# using default empty value, this way we use just if d['k']
# to check presence and non-emptiness at the same time
citation = defaultdict(str)
citation['module'] = name
+ citation['grass-version'] = g_version['version']
+ citation['grass-build-date'] = g_version['build_date']
citation['authors'] = get_authors_from_documentation(text)
citation['year'] = get_year_from_documentation(text)
code_url, code_history_url = get_code_urls_from_documentation(text)
More information about the grass-commit
mailing list