[GRASS-dev] [GRASS-SVN] r73692 - grass/trunk/lib/init

Hi,

st 21. 11. 2018 v 20:05 odesílatel <svn_grass@osgeo.org> napsal:

+ # clean the sqlite db
+ 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):
+ message(_("Cleaning up sqlite database ..."))
+ gcore.start_command('db.execute', sql = 'VACUUM')

a small note, the added code could be probably moved to new a fn eg.
clean_db(), Ma

--
Martin Landa
http://geo.fsv.cvut.cz/gwiki/Landa
http://gismentors.cz/mentors/landa

On Wed, Nov 21, 2018 at 2:12 PM Martin Landa <landa.martin@gmail.com> wrote:

Hi,

st 21. 11. 2018 v 20:05 odesílatel <svn_grass@osgeo.org> napsal:

  • clean the sqlite db

  • 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):
  • message(_(“Cleaning up sqlite database …”))
  • gcore.start_command(‘db.execute’, sql = ‘VACUUM’)

a small note, the added code could be probably moved to new a fn eg.
clean_db(), Ma

Yes, ideally to grass.script.setup.

On Thu, Nov 22, 2018 at 3:31 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Wed, Nov 21, 2018 at 2:12 PM Martin Landa <landa.martin@gmail.com> wrote:

Hi,

st 21. 11. 2018 v 20:05 odesílatel <svn_grass@osgeo.org> napsal:

  • clean the sqlite db

  • 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):
  • message(_(“Cleaning up sqlite database …”))
  • gcore.start_command(‘db.execute’, sql = ‘VACUUM’)

a small note, the added code could be probably moved to new a fn eg.
clean_db(), Ma

Yes, ideally to grass.script.setup.

But this is only initializing a GRASS session, without any mechanism to terminate a session. Basic usage in the documentation:

… use GRASS modules here

remove the session’s gisrc file to end the session

os.remove(gisrc)

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.

Markus M

On Thu, Nov 22, 2018 at 10:57 AM Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Nov 22, 2018 at 3:31 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Wed, Nov 21, 2018 at 2:12 PM Martin Landa <landa.martin@gmail.com> wrote:

Hi,

st 21. 11. 2018 v 20:05 odesílatel <svn_grass@osgeo.org> napsal:

  • clean the sqlite db

  • 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):
  • message(_(“Cleaning up sqlite database …”))
  • gcore.start_command(‘db.execute’, sql = ‘VACUUM’)

a small note, the added code could be probably moved to new a fn eg.
clean_db(), Ma

Yes, ideally to grass.script.setup.

But this is only initializing a GRASS session, without any mechanism to terminate a session. Basic usage in the documentation:

… use GRASS modules here

remove the session’s gisrc file to end the session

os.remove(gisrc)

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.

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.

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).

On Thu, Nov 22, 2018 at 11:33 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Thu, Nov 22, 2018 at 10:57 AM Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Nov 22, 2018 at 3:31 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Wed, Nov 21, 2018 at 2:12 PM Martin Landa <landa.martin@gmail.com> wrote:

Hi,

st 21. 11. 2018 v 20:05 odesílatel <svn_grass@osgeo.org> napsal:

  • clean the sqlite db

  • 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):
  • message(_(“Cleaning up sqlite database …”))
  • gcore.start_command(‘db.execute’, sql = ‘VACUUM’)

a small note, the added code could be probably moved to new a fn eg.
clean_db(), Ma

Yes, ideally to grass.script.setup.

But this is only initializing a GRASS session, without any mechanism to terminate a session. Basic usage in the documentation:

… use GRASS modules here

remove the session’s gisrc file to end the session

os.remove(gisrc)

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.

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.

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).

ok, the db cleanup is now (r73704) a function in grass.script.setup

On Sat, Nov 24, 2018 at 5:54 AM Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Nov 22, 2018 at 11:33 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

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.

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).

ok, the db cleanup is now (r73704) a function in grass.script.setup

Great! Thanks. I tried to clean grass.py as much as possible, so I hope it’s possible to make changes there.

On Sat, Nov 24, 2018 at 9:58 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Sat, Nov 24, 2018 at 5:54 AM Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Nov 22, 2018 at 11:33 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

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.

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).

ok, the db cleanup is now (r73704) a function in grass.script.setup

Great! Thanks. I tried to clean grass.py as much as possible, so I hope it’s possible to make changes there.

Unfortunately, just running:

$ grass77 --tmp-location XY --exec g.region -p


Execution of <g.region -p> finished.
Traceback (most recent call last):
File “./bin.x86_64-pc-linux-gnu/grass77”, line 2260, in
main()
File “./bin.x86_64-pc-linux-gnu/grass77”, line 2208, in main
clean_all(params.tmp_location)
TypeError: clean_all() takes no arguments (1 given)

$ svnversion

73707M

On Sun, Nov 25, 2018 at 4:06 AM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Sat, Nov 24, 2018 at 9:58 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Sat, Nov 24, 2018 at 5:54 AM Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Nov 22, 2018 at 11:33 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

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.

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).

ok, the db cleanup is now (r73704) a function in grass.script.setup

Great! Thanks. I tried to clean grass.py as much as possible, so I hope it’s possible to make changes there.

Unfortunately, just running:

$ grass77 --tmp-location XY --exec g.region -p

Execution of <g.region -p> finished.
Traceback (most recent call last):
File “./bin.x86_64-pc-linux-gnu/grass77”, line 2260, in
main()
File “./bin.x86_64-pc-linux-gnu/grass77”, line 2208, in main
clean_all(params.tmp_location)
TypeError: clean_all() takes no arguments (1 given)

oops, fixed in r73708

Markus M

$ svnversion
73707M