[GRASS-SVN] r72872 - sandbox/wenzeslaus/g.citation
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 21 18:40:04 PDT 2018
Author: wenzeslaus
Date: 2018-06-21 18:40:04 -0700 (Thu, 21 Jun 2018)
New Revision: 72872
Modified:
sandbox/wenzeslaus/g.citation/g.citation.html
sandbox/wenzeslaus/g.citation/g.citation.py
Log:
g.citation: add CFF as output format
Modified: sandbox/wenzeslaus/g.citation/g.citation.html
===================================================================
--- sandbox/wenzeslaus/g.citation/g.citation.html 2018-06-22 00:01:53 UTC (rev 72871)
+++ sandbox/wenzeslaus/g.citation/g.citation.html 2018-06-22 01:40:04 UTC (rev 72872)
@@ -3,6 +3,13 @@
<em>g.citation</em> - creates citation or metadata based on
documentation of a given module.
+<h3>Formats</h3>
+
+<h4>Citation File Format</h4>
+
+<a href="https://citation-file-format.github.io/">Citation File Format</a>
+(CFF)
+
<h2>NOTES</h2>
<h2>EXAMPLES</h2>
Modified: sandbox/wenzeslaus/g.citation/g.citation.py
===================================================================
--- sandbox/wenzeslaus/g.citation/g.citation.py 2018-06-22 00:01:53 UTC (rev 72871)
+++ sandbox/wenzeslaus/g.citation/g.citation.py 2018-06-22 01:40:04 UTC (rev 72872)
@@ -37,7 +37,7 @@
#% type: string
#% description: Citation format or style
#% options: bibtex,csl,datacite,dublincore,json,json-ld,narcxml,plain,dict,cff
-#% descriptions: bibtex;BibTeX;csl;cls;datacite;datacite;dublincore;dublincore;json;json;json-ld;json-ld;narcxml;narcxml;plain;Plain text;dict;Pretty printed Python dictionary;cff;Citation file
+#% descriptions: bibtex;BibTeX;csl;cls;datacite;datacite;dublincore;dublincore;json;json;json-ld;json-ld;narcxml;narcxml;plain;Plain text;dict;Pretty printed Python dictionary;cff;Citation File Format
#% answer: bibtex
#% required: yes
#%end
@@ -233,6 +233,44 @@
raise RuntimeError("The text does not contain source code URLs")
+def print_cff(citation):
+ """Create Citation File Format file from citation dictionary
+
+ >>> print_cff({'module': 'g.tst', 'authors': [{'name': 'Joe Doe'}], 'year': 2011})
+ cff-version: 1.0.3
+ message: "If you use this software, please cite it as below."
+ authors:
+ - family-names: Doe
+ given-names: Joe
+ title: "GRASS GIS: g.tst module"
+ version: TODO
+ date-released: 2011-01-01
+ license: GPL-2.0-or-later
+ """
+ print("cff-version: 1.0.3")
+ print("message: \"If you use this software, please cite it as below.\"")
+ print("authors:")
+ for author in citation['authors']:
+ # note: CFF 1.0.3 specifies mandatory family, mandatory given,
+ # optional particle (e.g. van), and optional suffix (e.g. III),
+ # best shot should be taken for names which don't include family
+ # or given or which have different order
+ # here we just split based on first space into given and family
+ given, family = author['name'].split(" ", 1)
+ print(" - family-names:", family)
+ print(" given-names:", given)
+ print("title: \"GRASS GIS: ", citation['module'], " module\"", sep="")
+ print("version:", "TODO")
+ # CFF 1.0.3 does not say expplicitely except for Date (so not any
+ # string), so assuming YAML timestamp
+ # (http://yaml.org/type/timestamp.html)
+ # now we have only the year, so using Jan 1
+ print("date-released: ", citation['year'], "-01-01", sep="")
+ # license string according to https://spdx.org/licenses/
+ # we know license of GRASS modules should be GPL>=2
+ print("license: GPL-2.0-or-later")
+
+
def print_bibtex(citation):
"""Create BibTeX entry from citation dictionary
@@ -282,6 +320,7 @@
# use print_citation()
_FORMAT_FUNCTION = {
'bibtex': print_bibtex,
+ 'cff': print_cff,
'plain': print_plain,
'dict': pprint,
}
@@ -292,7 +331,7 @@
try:
_FORMAT_FUNCTION[format](citation)
except KeyError:
- raise RuntimeError(_("Unsupported format or style"))
+ raise RuntimeError(_("Unsupported format or style: %s" % format))
def citation_for_module(name):
More information about the grass-commit
mailing list