[GRASS-SVN] r57121 - grass/trunk/scripts/v.unpack
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jul 14 08:58:29 PDT 2013
Author: martinl
Date: 2013-07-14 08:58:29 -0700 (Sun, 14 Jul 2013)
New Revision: 57121
Modified:
grass/trunk/scripts/v.unpack/v.unpack.py
Log:
v.unpack: fix on MS Windows
Modified: grass/trunk/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/trunk/scripts/v.unpack/v.unpack.py 2013-07-14 15:07:02 UTC (rev 57120)
+++ grass/trunk/scripts/v.unpack/v.unpack.py 2013-07-14 15:58:29 UTC (rev 57121)
@@ -6,7 +6,7 @@
# AUTHOR(S): Luca Delucchi
#
# PURPOSE: Unpack up a vector map packed with v.pack
-# COPYRIGHT: (C) 2004-2008, 2010 by the GRASS Development Team
+# COPYRIGHT: (C) 2010-2013 by the GRASS Development Team
#
# This program is free software under the GNU General
# Public License (>=v2). Read the file COPYING that
@@ -15,7 +15,7 @@
#############################################################################
#%module
-#% description: Unpacks a vector map packed with r.pack.
+#% description: Unpacks a vector map packed with v.pack.
#% keywords: vector, import, copying
#%end
#%option G_OPT_F_INPUT
@@ -23,12 +23,9 @@
#% description: Name of input pack file
#% required : yes
#%end
-#%option
-#% key: output
-#% type: string
-#% gisprompt: new,vector,vector
-#% description: Name for output vector map (default: taken from input file internals)
-#% key_desc: name
+#%option G_OPT_V_OUTPUT
+#% label: Name for output vector map
+#% description: Default: taken from input file internals
#% required : no
#%end
#%flag
@@ -36,7 +33,6 @@
#% description: Override projection check (use current location's projection)
#%end
-
import os
import sys
import shutil
@@ -53,15 +49,15 @@
def main():
infile = options['input']
+ # check if the input file exists
+ if not os.path.exists(infile):
+ grass.fatal(_("File <%s> not found") % infile)
+
# create temporary directory
global tmp_dir
tmp_dir = grass.tempdir()
grass.debug('tmp_dir = %s' % tmp_dir)
- # check if the input file exists
- if not os.path.exists(infile):
- grass.fatal(_("File <%s> not found") % infile)
-
# copy the files to tmp dir
input_base = os.path.basename(infile)
shutil.copyfile(infile, os.path.join(tmp_dir, input_base))
@@ -102,31 +98,28 @@
# 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')
- if not grass.compare_key_value_text_files(os.path.join(data_name,'PROJ_INFO'), loc_proj) or \
- not grass.compare_key_value_text_files(os.path.join(data_name,'PROJ_UNITS'), loc_proj_units):
+ if not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_INFO'), loc_proj) or \
+ not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_UNITS'), loc_proj_units):
if flags['o']:
grass.warning(_("Projection information does not match. Proceeding..."))
else:
grass.fatal(_("Projection information does not match. Aborting."))
# new db
- fromdb = os.path.join(new_dir, 'db.sqlite')
+ fromdb = os.path.join(tmp_dir, 'db.sqlite')
# copy file
shutil.copytree(data_name, new_dir)
# exist fromdb
if os.path.exists(fromdb):
# the db connection in the output mapset
dbconn = grassdb.db_connection()
- if dbconn['database'].find('GISDBASE'):
- dbstr = os.path.sep.join(dbconn['database'].split(os.path.sep)[3:])
- todb = os.path.join(mset_dir, dbstr)
- else:
- todb = dbconn['database']
+ todb = dbconn['database']
# return all tables
- list_fromtable = grass.read_command('db.tables',driver='sqlite',database=fromdb)
- list_fromtable = list_fromtable.split('\n')
+ list_fromtable = grass.read_command('db.tables', driver = 'sqlite',
+ database = fromdb).splitlines()
+
# return the list of old connection for extract layer number and key
- dbln = open(os.path.join(new_dir,'dbln'),'r')
+ dbln = open(os.path.join(new_dir,'dbln'), 'r')
dbnlist = dbln.readlines()
dbln.close()
# check if dbf or sqlite directory exists
@@ -141,7 +134,7 @@
values = t.split('|')
else:
values = t.split(' ')
-
+
from_table = values[1]
layer = values[0].split('/')[0]
# we need to take care about the table name in case of several layer
@@ -149,33 +142,26 @@
to_table = "%s_%s"%(map_name, layer)
else:
to_table = from_table
-
+
grass.verbose(_("Coping table <%s> as table <%s>") % (from_table, to_table))
-
+
# copy the table in the default database
- ret = grass.run_command('db.copy', to_driver = dbconn['driver'],
- to_database = todb, to_table = to_table,
- from_driver = 'sqlite', from_database = fromdb,
- from_table = from_table)
- if ret != 0:
+ if 0 != grass.run_command('db.copy', to_driver = dbconn['driver'],
+ to_database = todb, to_table = to_table,
+ from_driver = 'sqlite', from_database = fromdb,
+ 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))
# and connect the new tables with the right layer
- ret = grass.run_command('v.db.connect', flags = "o",
- driver = dbconn['driver'], database = todb,
- map = map_name, key = values[2],
- layer = layer, table = to_table)
- if ret != 0:
- grass.fatal(_("Unable to connect table <%s> to vector map <%s>") % (to_table, map_name))
-
- # remove
- os.remove(os.path.join(new_dir, 'PROJ_INFO'))
- os.remove(os.path.join(new_dir, 'PROJ_UNITS'))
- if os.path.exists(fromdb):
- os.remove(os.path.join(new_dir, 'db.sqlite'))
+ 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.message(_("Vector map <%s> succesfully unpacked") % map_name)
More information about the grass-commit
mailing list