<div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br>On Thu, Nov 22, 2018 at 3:31 PM Vaclav Petras <<a href="mailto:wenzeslaus@gmail.com">wenzeslaus@gmail.com</a>> wrote:<br>><br>><br>><br>> On Wed, Nov 21, 2018 at 2:12 PM Martin Landa <<a href="mailto:landa.martin@gmail.com">landa.martin@gmail.com</a>> wrote:<br>>><br>>> Hi,<br>>><br>>> st 21. 11. 2018 v 20:05 odesílatel <<a href="mailto:svn_grass@osgeo.org">svn_grass@osgeo.org</a>> napsal:<br>>> > +        # clean the sqlite db<br>>> > +        from grass.script import db as gdb<br>>> > +        from grass.script import core as gcore<br>>> > +        conn = gdb.db_connection()<br>>> > +        if conn and conn['driver'] == 'sqlite':<br>>> > +           # check if db exists<br>>> > +           gisenv = gcore.gisenv()<br>>> > +           database = conn['database']<br>>> > +           database = database.replace('$GISDBASE', gisenv['GISDBASE'])<br>>> > +           database = database.replace('$LOCATION_NAME', gisenv['LOCATION_NAME'])<br>>> > +           database = database.replace('$MAPSET', gisenv['MAPSET'])<br>>> > +           if os.path.exists(database):<br>>> > +               message(_("Cleaning up sqlite database ..."))<br>>> > +               gcore.start_command('db.execute', sql = 'VACUUM')<br>>><br>>> a small note, the added code could be probably moved to new a fn eg.<br>>> clean_db(), Ma<br>><br>><br><div>> Yes, ideally to grass.script.setup.</div><div><br></div><div>But this is only initializing a GRASS session, without any mechanism to terminate a session. Basic usage in the documentation:</div><div><br></div><div>        # ... use GRASS modules here<br>        # remove the session's gisrc file to end the session<br>        os.remove(gisrc)<br></div><div><br></div><div>maybe a new fn to terminate a session is needed? This fn could clean temp files like clean_temp() in grass.py and also clean any default sqlite db when terminating the grass session.</div><div><br></div><div>Markus M<br></div>>  </div></div></div>