[GRASS-SVN] r73703 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 24 02:51:08 PST 2018


Author: mmetz
Date: 2018-11-24 02:51:08 -0800 (Sat, 24 Nov 2018)
New Revision: 73703

Modified:
   grass/trunk/lib/python/script/setup.py
Log:
libpython: move clean_default_db() to setup

Modified: grass/trunk/lib/python/script/setup.py
===================================================================
--- grass/trunk/lib/python/script/setup.py	2018-11-24 10:11:32 UTC (rev 73702)
+++ grass/trunk/lib/python/script/setup.py	2018-11-24 10:51:08 UTC (rev 73703)
@@ -204,3 +204,23 @@
 
     os.environ['GISRC'] = write_gisrc(dbase, location, mapset)
     return os.environ['GISRC']
+
+
+# clean-up functions when terminating a GRASS session
+def clean_default_db():
+    # clean the default db if it is sqlite
+    from grass.script import db as gdb
+    from grass.script import core as gcore
+    conn = gdb.db_connection()
+    if conn and conn['driver'] == 'sqlite':
+	# check if db exists
+	gisenv = gcore.gisenv()
+	database = conn['database']
+	database = database.replace('$GISDBASE', gisenv['GISDBASE'])
+	database = database.replace('$LOCATION_NAME', gisenv['LOCATION_NAME'])
+	database = database.replace('$MAPSET', gisenv['MAPSET'])
+	if os.path.exists(database):
+	    gcore.message(_("Cleaning up sqlite database ..."))
+	    gcore.start_command('db.execute', sql = 'VACUUM')
+
+



More information about the grass-commit mailing list