[GRASS-SVN] r50290 - grass/trunk/lib/python/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 19 06:30:51 EST 2012
Author: huhabla
Date: 2012-01-19 03:30:51 -0800 (Thu, 19 Jan 2012)
New Revision: 50290
Modified:
grass/trunk/lib/python/temporal/core.py
Log:
New TGIS database settings handling implemented
Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py 2012-01-19 08:42:56 UTC (rev 50289)
+++ grass/trunk/lib/python/temporal/core.py 2012-01-19 11:30:51 UTC (rev 50290)
@@ -27,53 +27,43 @@
###############################################################################
-def get_temporal_sqlite3_default_path(grassenv):
- dbpath = os.path.join(grassenv["GISDBASE"], grassenv["LOCATION_NAME"])
- dbpath = os.path.join(dbpath, "PERMANENT")
- return dbpath
-
-def get_temporal_sqlite3_default_dbname(grassenv):
- return "tgis.db"
-
# The chosen DBMI backend can be defined on runtime
# Check the grass environment before import
-grassenv = core.gisenv()
-if grassenv.has_key("TDBMI"):
- if grassenv["TDBMI"] == "sqlite3":
+core.run_command("t.connect", flags="c")
+kv = core.parse_command("t.connect", flags="pg")
+if kv.has_key("driver"):
+ if kv["driver"] == "sqlite":
import sqlite3 as dbmi
- elif grassenv["TDBMI"] == "psycopg2":
+ elif kv["driver"] == "pg":
import psycopg2 as dbmi
# Needed for dictionary like cursors
import psycopg2.extras
else:
- core.fatal(_("Unable to initialize the temporal DBMI interface: %s. \nPlease set g.gisenv set=\"TDBMI=sqlite3\" or g.gisenv set=\"TDBMI=psycopg2\"") % grassenv["TDBMI"])
+ core.fatal(_("Unable to initialize the temporal DBMI interface. Use t.connect to specify the driver and the database string"))
else:
# Use the default sqlite variable
+ core.run_command("t.connect", flags="d")
import sqlite3 as dbmi
- # We do not set the path due to issues with the grass build system
- #core.run_command("g.gisenv", set="TDBMI=sqlite3")
- #core.run_command("g.gisenv", set="TDBMI_INIT=%s" % get_temporal_sqlite3_default_dbname(grassenv))
###############################################################################
def get_temporal_dbmi_init_string():
+ kv = core.parse_command("t.connect", flags="pg")
grassenv = core.gisenv()
if dbmi.__name__ == "sqlite3":
- if grassenv.has_key("TDBMI_INIT"):
-
- string = grassenv["TDBMI_INIT"]
-
- # In case no path is present in the sqlite3 database string, we attach the default path
- if string.find("/") < 0 or string.find("\\") < 0:
- return os.path.join(get_temporal_sqlite3_default_path(grassenv), string)
-
- return grassenv["TDBMI_INIT"]
+ if kv.has_key("database"):
+ string = kv["database"]
+ string = string.replace("$GISDBASE", grassenv["GISDBASE"])
+ string = string.replace("$LOCATION_NAME", grassenv["LOCATION_NAME"])
+ return string
else:
- return os.path.join(get_temporal_sqlite3_default_path(grassenv), get_temporal_sqlite3_default_dbname(grassenv))
+ core.fatal(_("Unable to initialize the temporal GIS DBMI interface. Use t.connect to specify the driver and the database string"))
elif dbmi.__name__ == "psycopg2":
- if grassenv.has_key("TDBMI_INIT"):
- return grassenv["TDBMI_INIT"]
+ if kv.has_key("database"):
+ string = kv["database"]
+ return string
else:
+ core.fatal(_("Unable to initialize the temporal GIS DBMI interface. Use t.connect to specify the driver and the database string"))
return "dbname=grass_test user=soeren password=abcdefgh"
###############################################################################
More information about the grass-commit
mailing list