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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 14 06:56:53 PDT 2013


Author: martinl
Date: 2013-07-14 06:56:53 -0700 (Sun, 14 Jul 2013)
New Revision: 57117

Modified:
   grass/trunk/scripts/v.pack/v.pack.py
Log:
v.pack: use temp dir for packaging, fix on Windows

Modified: grass/trunk/scripts/v.pack/v.pack.py
===================================================================
--- grass/trunk/scripts/v.pack/v.pack.py	2013-07-14 13:30:45 UTC (rev 57116)
+++ grass/trunk/scripts/v.pack/v.pack.py	2013-07-14 13:56:53 UTC (rev 57117)
@@ -6,7 +6,7 @@
 # AUTHOR(S):    Luca Delucchi, Fondazione E. Mach (Italy)
 #
 # PURPOSE:      Pack up a vector map, collect vector map elements => gzip
-# COPYRIGHT:    (C) 2011 by the GRASS Development Team
+# COPYRIGHT:    (C) 2011-2013 by the GRASS Development Team
 #
 #               This program is free software under the GNU General
 #               Public License (>=v2). Read the file COPYING that
@@ -18,13 +18,9 @@
 #% description: Packs up a vector map and support files for copying.
 #% keywords: vector, export, copying
 #%end
-#%option
-#% key: input
-#% type: string
-#% gisprompt: old,vector,vector
-#% description: Name of vector map to pack up
-#% key_desc: name
-#% required : yes
+#%option G_OPT_V_INPUT
+#% label: Name of vector map to pack up
+#% description:
 #%end
 #%option G_OPT_F_OUTPUT
 #% description: Name for output file (default is <input>.pack)
@@ -47,12 +43,12 @@
     infile = options['input']
     compression_off = flags['c']
     
-    # check if vector map exist
+    # check if vector map exists
     gfile = grass.find_file(infile, element = 'vector')
     if not gfile['name']:
         grass.fatal(_("Vector map <%s> not found") % infile)
     
-    # check if input vector map is in native format
+    # check if input vector map is in the native format
     if vector.vector_info(gfile['fullname'])['format'] != 'native':
         grass.fatal(_("Unable to pack vector map <%s>. Only native format supported.") % \
                         gfile['fullname'])
@@ -73,48 +69,44 @@
             grass.warning(_("Pack file <%s> already exists and will be overwritten") % outfile)
             grass.try_remove(outfile)
         else:
-            grass.fatal(_("option <output>: <%s> exists.") % outfile)
+            grass.fatal(_("option <%s>: <%s> exists.") % ("output", 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()
+    basedir = grass.tempdir()
 
+    # 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(gfile['file'], infile)
+    
     # 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 in sqlite database
+        sqlitedb = os.path.join(basedir, 'db.sqlite')
         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'])
+            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'])
+        tar.add(sqlitedb, os.path.join(infile, 'db.sqlite'))
     
-    # 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)
-
     # add to the tar file the PROJ files to check when unpack file    
     gisenv = grass.gisenv()
     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)
-    if db_vect and sqlitedb:
-        os.remove(sqlitedb)
-    
-    grass.message(_("Pack file <%s> created") % os.path.join(olddir, outfile))
+    grass.message(_("Pack file <%s> created") % os.path.join(os.getcwd(), outfile))
             
 if __name__ == "__main__":
     options, flags = grass.parser()



More information about the grass-commit mailing list