Kaynağa Gözat

r.unpack: fix for fully qualified map names
various minor issues


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54236 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 12 yıl önce
ebeveyn
işleme
a862a9517c
1 değiştirilmiş dosya ile 14 ekleme ve 9 silme
  1. 14 9
      scripts/r.unpack/r.unpack.py

+ 14 - 9
scripts/r.unpack/r.unpack.py

@@ -5,7 +5,7 @@
 # AUTHOR(S):	Hamish Bowman, Otago University, New Zealand
 # AUTHOR(S):	Hamish Bowman, Otago University, New Zealand
 #               Converted to Python by Martin Landa <landa.martin gmail.com>
 #               Converted to Python by Martin Landa <landa.martin gmail.com>
 # PURPOSE:	Unpack up a raster map packed with r.pack
 # 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
 #		This program is free software under the GNU General
 #		Public License (>=v2). Read the file COPYING that
 #		Public License (>=v2). Read the file COPYING that
@@ -22,14 +22,17 @@
 #%option G_OPT_F_INPUT
 #%option G_OPT_F_INPUT
 #% description: Name of input pack file
 #% description: Name of input pack file
 #% gisprompt: old,file,bin_input
 #% gisprompt: old,file,bin_input
+#% key_desc: name.pack
 #%end
 #%end
 #%option G_OPT_R_OUTPUT
 #%option G_OPT_R_OUTPUT
 #% description: Name for output raster map (default: taken from input file internals)
 #% description: Name for output raster map (default: taken from input file internals)
 #% required: no
 #% required: no
+#% guisection: Output settings
 #%end
 #%end
 #%flag
 #%flag
 #% key: o
 #% key: o
 #% description: Override projection check (use current location's projection)
 #% description: Override projection check (use current location's projection)
+#% guisection: Output settings
 #%end
 #%end
 
 
 import os
 import os
@@ -52,7 +55,7 @@ def main():
     grass.debug('tmp_dir = %s' % tmp_dir)
     grass.debug('tmp_dir = %s' % tmp_dir)
     
     
     if not os.path.exists(infile):
     if not os.path.exists(infile):
-        grass.fatal(_("File <%s> not found" % infile))
+        grass.fatal(_("File <%s> not found") % infile)
     
     
     gisenv = grass.gisenv()
     gisenv = grass.gisenv()
     mset_dir = os.path.join(gisenv['GISDBASE'],
     mset_dir = os.path.join(gisenv['GISDBASE'],
@@ -70,21 +73,23 @@ def main():
     if options['output']:
     if options['output']:
         map_name = options['output']
         map_name = options['output']
     else:
     else:
-        map_name = data_name
+        map_name = data_name.split('@')[0]
     
     
     gfile = grass.find_file(name = map_name, element = 'cell',
     gfile = grass.find_file(name = map_name, element = 'cell',
                             mapset = '.')
                             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
     # extract data
     tar.extractall()
     tar.extractall()
     os.chdir(data_name)
     os.chdir(data_name)
     
     
     # check projection compatibility in a rather crappy way
     # 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']:
         if flags['o']:
             grass.warning(_("Projection information does not match. Proceeding..."))
             grass.warning(_("Projection information does not match. Proceeding..."))
         else:
         else:
@@ -105,7 +110,7 @@ def main():
         else:
         else:
             shutil.copyfile(element, os.path.join(mset_dir, element, map_name))
             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__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()