<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 22, 2018 at 10:57 AM Markus Metz <<a href="mailto:markus.metz.giswork@gmail.com">markus.metz.giswork@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">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" target="_blank">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" target="_blank">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></div></div></blockquote><div><br></div><div>That's all correct. There would have to be more to make it the same procedure as in grass.py, but eventually we need to do that.<br></div><div><br></div><div>What I meant to add it to grass.script.setup module where we should eventually put all the functions needed to setup a proper GRASS session (or in some other module, but setup seems to be something good enough for now and moving things around while keeping the API is easy in Python).<br></div><div> </div></div></div>