[GRASS-SVN] r54236 - grass/trunk/scripts/r.unpack

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 7 12:22:18 PST 2012


Author: martinl
Date: 2012-12-07 12:22:17 -0800 (Fri, 07 Dec 2012)
New Revision: 54236

Modified:
   grass/trunk/scripts/r.unpack/r.unpack.py
Log:
r.unpack: fix for fully qualified map names
          various minor issues


Modified: grass/trunk/scripts/r.unpack/r.unpack.py
===================================================================
--- grass/trunk/scripts/r.unpack/r.unpack.py	2012-12-07 17:13:06 UTC (rev 54235)
+++ grass/trunk/scripts/r.unpack/r.unpack.py	2012-12-07 20:22:17 UTC (rev 54236)
@@ -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 by the GRASS Development Team
+# COPYRIGHT:	(C) 2004-2008, 2010-2012 by the GRASS Development Team
 #
 #		This program is free software under the GNU General
 #		Public License (>=v2). Read the file COPYING that
@@ -22,14 +22,17 @@
 #%option G_OPT_F_INPUT
 #% description: Name of input pack file
 #% gisprompt: old,file,bin_input
+#% key_desc: name.pack
 #%end
 #%option G_OPT_R_OUTPUT
 #% description: Name for output raster map (default: taken from input file internals)
 #% required: no
+#% guisection: Output settings
 #%end
 #%flag
 #% key: o
 #% description: Override projection check (use current location's projection)
+#% guisection: Output settings
 #%end
 
 import os
@@ -52,7 +55,7 @@
     grass.debug('tmp_dir = %s' % tmp_dir)
     
     if not os.path.exists(infile):
-        grass.fatal(_("File <%s> not found" % infile))
+        grass.fatal(_("File <%s> not found") % infile)
     
     gisenv = grass.gisenv()
     mset_dir = os.path.join(gisenv['GISDBASE'],
@@ -70,21 +73,23 @@
     if options['output']:
         map_name = options['output']
     else:
-        map_name = data_name
+        map_name = data_name.split('@')[0]
     
     gfile = grass.find_file(name = map_name, element = 'cell',
                             mapset = '.')
-    overwrite = os.getenv('GRASS_OVERWRITE')
-    if gfile['file'] and overwrite != '1':
-        grass.fatal(_("Raster map <%s> already exists") % map_name)
+    if gfile['file']:
+        if os.environ.get('GRASS_OVERWRITE', '0') != '1':
+            grass.fatal(_("Raster map <%s> already exists") % map_name)
+        else:
+            grass.warning(_("Raster map <%s> already exists and will be overwritten") % map_name)
     
     # extract data
     tar.extractall()
     os.chdir(data_name)
     
     # check projection compatibility in a rather crappy way
-    if not grass.compare_key_value_text_files('PROJ_INFO', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')) or\
-       not grass.compare_key_value_text_files('PROJ_UNITS', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')):
+    if not grass.compare_key_value_text_files('PROJ_INFO', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')) or \
+            not grass.compare_key_value_text_files('PROJ_UNITS', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')):
         if flags['o']:
             grass.warning(_("Projection information does not match. Proceeding..."))
         else:
@@ -105,7 +110,7 @@
         else:
             shutil.copyfile(element, os.path.join(mset_dir, element, map_name))
     
-    grass.verbose(_("Raster map saved to <%s>") % map_name)
+    grass.message(_("Raster map <%s> unpacked") % map_name)
     
 if __name__ == "__main__":
     options, flags = grass.parser()



More information about the grass-commit mailing list