[GRASS-SVN] r72454 - in grass-addons/grass7/imagery: . i.signature.copy

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 20 16:49:03 PDT 2018


Author: lucadelu
Date: 2018-03-20 16:49:03 -0700 (Tue, 20 Mar 2018)
New Revision: 72454

Added:
   grass-addons/grass7/imagery/i.signature.copy/
   grass-addons/grass7/imagery/i.signature.copy/Makefile
   grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.html
   grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.py
Log:
i.signature.copy: first version, for sajid birthday, see #3526

Added: grass-addons/grass7/imagery/i.signature.copy/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.signature.copy/Makefile	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.copy/Makefile	2018-03-20 23:49:03 UTC (rev 72454)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.signature.copy
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.html
===================================================================
--- grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.html	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.html	2018-03-20 23:49:03 UTC (rev 72454)
@@ -0,0 +1,12 @@
+<H2>DESCRIPTION</H2>
+<em>i.signature.copy</em> copies a signature file from a group/subgroup to another group/subgroup
+
+<H2>EXAMPLE</H2>
+<div div="code"><pre>
+i.signature.copy igroup=name isubgroup=subname isignature=test ogroup=name2 osubgroup=subname2 
+</pre></div>
+
+
+<H2>AUTHOR</H2>
+
+Luca Delucchi

Added: grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.py
===================================================================
--- grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.py	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.copy/i.signature.copy.py	2018-03-20 23:49:03 UTC (rev 72454)
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:	i.signature.copy
+# AUTHOR(S):	Luca Delucchi
+#
+# PURPOSE:	List signature file for a group/subgroup
+# COPYRIGHT:	(C) 2018 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%module
+#% description: List signature file for a group/subgroup
+#% keyword: imagery
+#% keyword: copy
+#% keyword: group
+#%end
+
+#%option G_OPT_I_GROUP
+#% key: igroup
+#% description: Input group for signature file to copy
+#% required : yes
+#%end
+
+#%option G_OPT_I_SUBGROUP 
+#% key: isubgroup
+#% description: Input subgroup for signature file to copy
+#% required : yes
+#%end
+
+#%option
+#% key: isignature
+#% type: string
+#% gisprompt: old,sig,sigfile
+#% label: Input signature file
+#% description: The name of the input signature file to copy
+#% required: yes
+#%end
+
+#%option
+#% key: ogroup
+#% type: string
+#% gisprompt: old,group,group
+#% label: Output group where copy the signature file
+#% required : yes
+#%end
+
+#%option 
+#% key: osubgroup
+#% type: string
+#% gisprompt: old,subgroup,subgroup
+#% description: Output subgroup where copy the signature file
+#% required : yes
+#%end
+
+#%option
+#% key: osignature
+#% type: string
+#% label: Output signature file
+#% description: The name of the output signature file
+#% required: no
+#%end
+
+import os
+import sys
+import shutil
+import grass.script as grass
+
+def main():
+    igroup = options['igroup']
+    isub = options['isubgroup']
+    isign = options['isignature']
+    ogroup = options['ogroup']
+    osub = options['osubgroup']
+    osign = options['osignature']
+    
+    #check if output signature is set
+    if not osign:
+        osign = isign
+
+    gisenv = grass.gisenv()
+    
+    # try to split input group and mapset
+    try:
+        name, mapset = igroup.split('@', 1)
+    except ValueError:
+        name = igroup
+        mapset = gisenv['MAPSET']
+    
+    ipath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'],
+                         mapset, name, 'subgroup', isub, isign)
+    if not os.path.exists(ipath):
+        grass.fatal(_("<{}> does not exist".format(ipath)))
+    
+    # try to split output group and mapset
+    try:
+        oname, omapset = ogroup.split('@', 1)
+    except ValueError:
+        oname = ogroup
+        omapset = gisenv['MAPSET']
+
+    opath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'],
+                         omapset, oname, 'subgroup', osub)
+    if not os.path.exists(opath):
+        grass.fatal(_("<{pa}> does not exist, do group <{gr}> and "
+                      "subgroup <{su}> exist?".format(pa=ipath, gr=ogroup,
+                                                      su=osub)))
+    else:
+        opath = os.path.join(opath, osign)
+        if os.path.exists(opath) and not grass.overwrite():
+            grass.fatal(_("ERROR: option <osignature>: <{}> exists. To "
+                          "overwrite, use the --overwrite flag".format(osign)))
+    # try to copy the signature file otherwise return an error
+    try:
+        shutil.copy2(ipath, opath)
+        return
+    except:
+        grass.fatal(_("ERROR: copying {inp} to {oup}".format(inp=ipath,
+                                                             oup=opath)))
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())
+
+    
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())



More information about the grass-commit mailing list