[GRASS-SVN] r71051 - in grass/branches/releasebranch_7_2/scripts: r.unpack v.unpack

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 7 10:25:18 PDT 2017


Author: martinl
Date: 2017-05-07 10:25:18 -0700 (Sun, 07 May 2017)
New Revision: 71051

Modified:
   grass/branches/releasebranch_7_2/scripts/r.unpack/r.unpack.py
   grass/branches/releasebranch_7_2/scripts/v.unpack/v.unpack.py
Log:
[NEWS] r.|v.unpack: new flag (-p) added to print projection info and exit
       (merge r70974 from trunk)


Modified: grass/branches/releasebranch_7_2/scripts/r.unpack/r.unpack.py
===================================================================
--- grass/branches/releasebranch_7_2/scripts/r.unpack/r.unpack.py	2017-05-07 17:06:44 UTC (rev 71050)
+++ grass/branches/releasebranch_7_2/scripts/r.unpack/r.unpack.py	2017-05-07 17:25:18 UTC (rev 71051)
@@ -5,7 +5,7 @@
 # AUTHOR(S):	Hamish Bowman, Otago University, New Zealand
 #               Converted to Python by Martin Landa <landa.martin gmail.com>
 # PURPOSE:	Unpack up a raster map packed with r.pack
-# COPYRIGHT:	(C) 2004-2008, 2010-2012 by the GRASS Development Team
+# COPYRIGHT:	(C) 2010-2017 by the GRASS Development Team
 #
 #		This program is free software under the GNU General
 #		Public License (>=v2). Read the file COPYING that
@@ -34,6 +34,11 @@
 #% description: Assume that the dataset has same projection as the current location
 #% guisection: Output settings
 #%end
+#%flag
+#% key: p
+#% label: Print projection information of input pack file and exit
+#% guisection: Print
+#%end
 
 import os
 import sys
@@ -72,6 +77,18 @@
     except:
         grass.fatal(_("Pack file unreadable"))
 
+    if flags['p']:
+        # print proj info and exit
+        try:
+            for fname in ['PROJ_INFO', 'PROJ_UNITS']:
+                f = tar.extractfile('{}/{}'.format(data_name, fname))
+                sys.stdout.write(f.read())
+        except KeyError:
+            grass.fatal(_("Pack file unreadable: file '{}' missing".format(fname)))
+        tar.close()
+
+        return 0
+
     if options['output']:
         map_name = options['output']
     else:
@@ -87,6 +104,7 @@
 
     # extract data
     tar.extractall()
+    tar.close()
     os.chdir(data_name)
 
     if os.path.exists('cell'):

Modified: grass/branches/releasebranch_7_2/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/branches/releasebranch_7_2/scripts/v.unpack/v.unpack.py	2017-05-07 17:06:44 UTC (rev 71050)
+++ grass/branches/releasebranch_7_2/scripts/v.unpack/v.unpack.py	2017-05-07 17:25:18 UTC (rev 71051)
@@ -6,7 +6,7 @@
 # AUTHOR(S):    Luca Delucchi
 #
 # PURPOSE:      Unpack up a vector map packed with v.pack
-# COPYRIGHT:    (C) 2010-2013 by the GRASS Development Team
+# COPYRIGHT:    (C) 2010-2017 by the GRASS Development Team
 #
 #               This program is free software under the GNU General
 #               Public License (>=v2). Read the file COPYING that
@@ -36,7 +36,13 @@
 #% description: Assume that the dataset has same projection as the current location
 #% guisection: Output settings
 #%end
+#%flag
+#% key: p
+#% label: Print projection information of input pack file and exit
+#% guisection: Print
+#%end
 
+
 import os
 import sys
 import shutil
@@ -75,6 +81,18 @@
     except:
         grass.fatal(_("Pack file unreadable"))
 
+    if flags['p']:
+        # print proj info and exit
+        try:
+            for fname in ['PROJ_INFO', 'PROJ_UNITS']:
+                f = tar.extractfile(fname)
+                sys.stdout.write(f.read())
+        except KeyError:
+            grass.fatal(_("Pack file unreadable: file '{}' missing".format(fname)))
+        tar.close()
+
+        return 0
+
     # set the output name
     if options['output']:
         map_name = options['output']
@@ -101,6 +119,7 @@
 
     # extract data
     tar.extractall()
+    tar.close()
     if os.path.exists(os.path.join(data_name, 'coor')):
         pass
     elif os.path.exists(os.path.join(data_name, 'cell')):



More information about the grass-commit mailing list