[GRASS-SVN] r55566 - grass/trunk/scripts/v.pack

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 28 09:42:46 PDT 2013


Author: martinl
Date: 2013-03-28 09:42:46 -0700 (Thu, 28 Mar 2013)
New Revision: 55566

Modified:
   grass/trunk/scripts/v.pack/v.pack.py
Log:
v.pack: only native format supported
        cosmetics


Modified: grass/trunk/scripts/v.pack/v.pack.py
===================================================================
--- grass/trunk/scripts/v.pack/v.pack.py	2013-03-27 21:42:23 UTC (rev 55565)
+++ grass/trunk/scripts/v.pack/v.pack.py	2013-03-28 16:42:46 UTC (rev 55566)
@@ -46,61 +46,74 @@
 def main():
     infile = options['input']
     compression_off = flags['c']
-    #search if file exist
+    
+    # check if vector map exist
     gfile = grass.find_file(infile, element = 'vector')
     if not gfile['name']:
         grass.fatal(_("Vector map <%s> not found") % infile)
-    #split the name if there is the mapset name
+    
+    # check if input vector map is in native format
+    if vector.vector_info(gfile['fullname'])['format'] != 'native':
+        grass.fatal(_("Unable to pack vector map <%s>. Only native format supported.") % \
+                        gfile['fullname'])
+    
+    # split the name if there is the mapset name
     if infile.find('@'):
-        infile = infile.split('@')[0]    
-    #output name
+        infile = infile.split('@')[0]
+    
+    # output name
     if options['output']:
         outfile = options['output']
     else:
         outfile = infile + '.pack'
-    #check if exists the output file
+    
+    # check if exists the output file
     if os.path.exists(outfile):
         if os.getenv('GRASS_OVERWRITE'):
             grass.warning(_("Pack file <%s> already exists and will be overwritten") % outfile)
             grass.try_remove(outfile)
         else:
             grass.fatal(_("option <output>: <%s> exists.") % outfile)
+    
+    # prepare for packing
     grass.verbose(_("Packing <%s>...") % (gfile['fullname']))
     basedir = os.path.sep.join(gfile['file'].split(os.path.sep)[:-2])
     olddir  = os.getcwd()
-    #check if exist a db connection for the vector 
+
+    # check if exist a db connection for the vector 
     db_vect = vector.vector_db(gfile['fullname'])
-
-    #db not exist and skip the db copy
     sqlitedb = None
     if not db_vect:
         grass.verbose(_('There is not database connected with vector map <%s>') % gfile['fullname'])
     else:
-        # for each layer connection save a table
+        # for each layer connection save a table in sqlite database
         for i, dbconn in db_vect.iteritems():
             sqlitedb = os.path.join(basedir, 'vector', infile, 'db.sqlite') 
             cptable = grass.run_command('db.copy', from_driver = dbconn['driver'], 
-                      from_database = dbconn['database'], from_table =  dbconn['table'], 
-                      to_driver = 'sqlite', to_database = sqlitedb, 
-                      to_table = dbconn['table'])
-        
+                                        from_database = dbconn['database'], from_table =  dbconn['table'], 
+                                        to_driver = 'sqlite', to_database = sqlitedb, 
+                                        to_table = dbconn['table'])
+    
     # write tar file, optional compression 
     if compression_off:
         tar = tarfile.open(name = outfile, mode = 'w:')
     else:
         tar = tarfile.open(name = outfile, mode = 'w:gz')
-    tar.add(os.path.join(basedir,'vector',infile),infile)
+    tar.add(os.path.join(basedir,'vector', infile), infile)
+
+    # add to the tar file the PROJ files to check when unpack file    
     gisenv = grass.gisenv()
-    #add to the tar file the PROJ files to check when unpack file
     for support in ['INFO', 'UNITS']:
         path = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'],
                             'PERMANENT', 'PROJ_' + support)
         if os.path.exists(path):
-          tar.add(path,os.path.join(infile,'PROJ_' + support))
+            tar.add(path,os.path.join(infile,'PROJ_' + support))
     tar.close()
-    #remove the db from the vector directory #ONLY THE DB FOR THE COPY NOT DB OF GRASS
+    
+    # remove the db from the vector directory (ONLY THE DB FOR THE COPY NOT DB OF GRASS)
     if db_vect and sqlitedb:
         os.remove(sqlitedb)
+    
     grass.message(_("Pack file <%s> created") % os.path.join(olddir, outfile))
             
 if __name__ == "__main__":



More information about the grass-commit mailing list