[GRASS-SVN] r72924 - sandbox/wenzeslaus/g.citation

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 28 18:17:23 PDT 2018


Author: wenzeslaus
Date: 2018-06-28 18:17:23 -0700 (Thu, 28 Jun 2018)
New Revision: 72924

Modified:
   sandbox/wenzeslaus/g.citation/g.citation.py
Log:
g.citation: flag to add GRASS to references in CFF

Modified: sandbox/wenzeslaus/g.citation/g.citation.py
===================================================================
--- sandbox/wenzeslaus/g.citation/g.citation.py	2018-06-29 01:05:30 UTC (rev 72923)
+++ sandbox/wenzeslaus/g.citation/g.citation.py	2018-06-29 01:17:23 UTC (rev 72924)
@@ -51,10 +51,16 @@
 
 #%flag
 #% key: a
-#% description: Provide citation for all modules
+#% description: Provide citations for all modules
 #%end
 
 #%flag
+#% key: d
+#% label: Add GRASS GIS as dependency to citation
+#% description: Add GRASS GIS as dependency, reference, or additional citation to the citation of a module if applicable for the format (currently only CFF)
+#%end
+
+#%flag
 #% key: s
 #% description: Skip errors, provide warning only
 #%end
@@ -327,6 +333,38 @@
         print("keywords:")
         for keyword in citation['keywords']:
             print("  -", keyword)
+    if citation.get('references', None):
+        print("references:")
+        for reference in citation['references']:
+            # making sure scope, type, and title are first
+            if reference.get('scope', None):
+                print("  - scope:", reference['scope'])
+                print("    type:", reference['type'])
+            else:
+                print("  - type:", reference['type'])
+            print("    title:", reference['title'])
+            for key, value in reference.iteritems():
+                if key in ['scope', 'type', 'title']:
+                    continue  # already handled
+                # TODO: add general serialization to YAML
+                elif key == 'authors':
+                    print("    authors:")
+                    for author in value:
+                        # special order for the name of entity
+                        if 'name' in author:
+                            print("      - name: {name}".format(**author))
+                        elif 'family-names' in author:
+                            print("      - family-names: {family-names}".format(**author))
+                        for akey, avalue in author.iteritems():
+                            if akey == 'name':
+                                continue
+                            print("        {akey}: {avalue}".format(**locals()))
+                elif key == 'keywords':
+                    print("    keywords:")
+                    for keyword in value:
+                        print("      - {keyword}".format(**locals()))
+                else:
+                    print("    {key}: {value}".format(**locals()))
 
 
 def print_bibtex(citation):
@@ -431,7 +469,36 @@
     function(citation)
 
 
-def citation_for_module(name):
+def grass_cff_reference(grass_version, scope=None):
+    """Reference/citation for GRASS GIS based on CFF (close to CFF)
+
+    The parameter grass_version is a g.version dictionary or equivalent.
+
+    Returns dictionary with keys of CFF reference (key).
+    """
+    citation = {}
+    if scope:
+        citation['scope'] = scope
+    citation['type'] = 'software'
+    # the team as an entity
+    citation['authors'] = [
+        {'name': "The GRASS Development Team",
+         'website': "http://grass.osgeo.org/"}
+        ]
+    citation['title'] = "GRASS GIS {version}".format(**grass_version)
+    citation['version'] = grass_version['version']
+    # approximation
+    citation['date-released'] = grass_version['build_date']
+    citation['year'] = grass_version['date']
+    citation['keywords'] = [
+        "GIS", "geospatial analysis", "remote sensing",
+        "image processing"
+        ]
+    citation['license'] = 'GPL-2.0-or-later'
+    return citation
+
+
+def citation_for_module(name, add_grass=False):
     """Provide dictionary of citation values for a module"""
     path = documentation_filename(name)
 
@@ -454,6 +521,12 @@
     citation['code-url'] = code_url
     citation['url-code-history'] = code_history_url
 
+    if add_grass:
+        scope = "Use the following to cite the whole GRASS GIS"
+        citation['references'] = [
+            grass_cff_reference(g_version, scope=scope)
+        ]
+
     return citation
 
 
@@ -479,7 +552,7 @@
 
     for name in names:
         try:
-            citation = citation_for_module(name)
+            citation = citation_for_module(name, add_grass=flags['d'])
             print_citation(citation, output_format)
         except RuntimeError as error:
             message = _("Module {name}: {error}".format(**locals()))



More information about the grass-commit mailing list