[GRASS-SVN] r62310 - in grass/trunk/scripts: r.unpack v.unpack

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 21 01:00:56 PDT 2014


Author: lucadelu
Date: 2014-10-21 01:00:56 -0700 (Tue, 21 Oct 2014)
New Revision: 62310

Modified:
   grass/trunk/scripts/r.unpack/r.unpack.py
   grass/trunk/scripts/v.unpack/v.unpack.py
Log:
r/v.unpack: check if the pack is the right type for that command (ticket #2455)

Modified: grass/trunk/scripts/r.unpack/r.unpack.py
===================================================================
--- grass/trunk/scripts/r.unpack/r.unpack.py	2014-10-21 01:34:01 UTC (rev 62309)
+++ grass/trunk/scripts/r.unpack/r.unpack.py	2014-10-21 08:00:56 UTC (rev 62310)
@@ -88,6 +88,14 @@
     tar.extractall()
     os.chdir(data_name)
 
+    if os.path.exists('cell'):
+        pass
+    elif os.path.exists('coor'):
+        grass.fatal(_("This GRASS GIS pack file contains vector data. Use "
+                      "v.unpack to unpack <%s>" % map_name))
+    else:
+        grass.fatal(_("Pack file unreadable"))
+
     # check projection compatibility in a rather crappy way
     diff_result_1 = diff_result_2 = None
     proj_info_file_1 = 'PROJ_INFO'

Modified: grass/trunk/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/trunk/scripts/v.unpack/v.unpack.py	2014-10-21 01:34:01 UTC (rev 62309)
+++ grass/trunk/scripts/v.unpack/v.unpack.py	2014-10-21 08:00:56 UTC (rev 62310)
@@ -4,7 +4,7 @@
 #
 # MODULE:       v.unpack
 # AUTHOR(S):    Luca Delucchi
-#               
+#
 # PURPOSE:      Unpack up a vector map packed with v.pack
 # COPYRIGHT:    (C) 2010-2013 by the GRASS Development Team
 #
@@ -96,18 +96,25 @@
 
     # extract data
     tar.extractall()
+    if os.path.exists(os.path.join(map_name, 'coor')):
+        pass
+    elif os.path.exists(os.path.join(map_name, 'cell')):
+        grass.fatal(_("This GRASS GIS pack file contains raster data. Use "
+                      "r.unpack to unpack <%s>" % map_name))
+    else:
+        grass.fatal(_("Pack file unreadable"))
 
     # check projection compatibility in a rather crappy way
     loc_proj = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')
     loc_proj_units = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')
 
     diff_result_1 = diff_result_2 = None
-    if not grass.compare_key_value_text_files(filename_a=os.path.join(tmp_dir,'PROJ_INFO'),
+    if not grass.compare_key_value_text_files(filename_a=os.path.join(tmp_dir, 'PROJ_INFO'),
                                               filename_b=loc_proj, proj=True):
         diff_result_1 = diff_files(os.path.join(tmp_dir, 'PROJ_INFO'),
                                          loc_proj)
 
-    if not grass.compare_key_value_text_files(filename_a=os.path.join(tmp_dir,'PROJ_UNITS'),
+    if not grass.compare_key_value_text_files(filename_a=os.path.join(tmp_dir, 'PROJ_UNITS'),
                                               filename_b=loc_proj_units,
                                               units=True):
         diff_result_2 = diff_files(os.path.join(tmp_dir, 'PROJ_UNITS'),
@@ -177,16 +184,16 @@
                                       from_table=from_table):
                 grass.fatal(_("Unable to copy table <%s> as table <%s>") % (from_table, to_table))
 
-            grass.verbose(_("Connect table <%s> to vector map <%s> at layer <%s>") % \
-                              (to_table, map_name, layer))
+            grass.verbose(_("Connect table <%s> to vector map <%s> at layer <%s>") %
+                           (to_table, map_name, layer))
 
             # and connect the new tables with the right layer
             if 0 != grass.run_command('v.db.connect', flags='o', quiet=True,
                                       driver=dbconn['driver'], database=todb,
                                       map=map_name, key=values[2],
                                       layer=layer, table=to_table):
-                grass.fatal(_("Unable to connect table <%s> to vector map <%s>") % \
-                                (to_table, map_name))
+                grass.fatal(_("Unable to connect table <%s> to vector map <%s>") %
+                             (to_table, map_name))
 
     grass.message(_("Vector map <%s> succesfully unpacked") % map_name)
 



More information about the grass-commit mailing list