Browse Source

v.pack: only native format supported
cosmetics


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

Martin Landa 12 years ago
parent
commit
38ba59785d
1 changed files with 30 additions and 17 deletions
  1. 30 17
      scripts/v.pack/v.pack.py

+ 30 - 17
scripts/v.pack/v.pack.py

@@ -46,61 +46,74 @@ from grass.script import vector as vector
 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 
-    db_vect = vector.vector_db(gfile['fullname'])
 
-    #db not exist and skip the db copy
+    # check if exist a db connection for the vector 
+    db_vect = vector.vector_db(gfile['fullname'])
     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__":