[GRASS-dev] Force --v flag whenever -l is instructed

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env['GRASS_VERBOSE'] = '3'

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,--v
#%end

Regards, Nikos

* Moritz Lennert <moritz.lennert@ulb.ac.be> [2017-10-09 10:59:25 +0200]:

On 07/10/17 10:39, Nikos Alexandris wrote:

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env['GRASS_VERBOSE'] = '3'

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,--v
#%end

I don't think the -- flags are covered by the rules, so I think you have to do this in the code, i.e. something like this:

if flags['l']:
env['GRASS_VERBOSE'] = '3'

Merci Moritz,

I tested already (before asking)

env = os.environ.copy()
if list_only:
    env['GRASS_VERBOSE'] = '3'

but it does not work.

Aren't there other ways?

Thank you again, N

* Nikos Alexandris <nik@nikosalexandris.net> [2017-10-09 12:18:29 +0200]:

* Moritz Lennert <moritz.lennert@ulb.ac.be> [2017-10-09 10:59:25 +0200]:

On 07/10/17 10:39, Nikos Alexandris wrote:

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env['GRASS_VERBOSE'] = '3'

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,--v
#%end

I don't think the -- flags are covered by the rules, so I think you have to do this in the code, i.e. something like this:

if flags['l']:
env['GRASS_VERBOSE'] = '3'

Merci Moritz,

I tested already (before asking)

env = os.environ.copy()
if list_only:
  env['GRASS_VERBOSE'] = '3'

but it does not work.

Aren't there other ways?

Thank you again, N

I guess simply

GRASS_VERBOSE=3
export GRASS_VERBOSE

It works!

See https://grasswiki.osgeo.org/wiki/Scripting

N

On 09/10/17 12:49, Nikos Alexandris wrote:

* Nikos Alexandris <nik@nikosalexandris.net> [2017-10-09 12:18:29 +0200]:

* Moritz Lennert <moritz.lennert@ulb.ac.be> [2017-10-09 10:59:25 +0200]:

On 07/10/17 10:39, Nikos Alexandris wrote:

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env['GRASS_VERBOSE'] = '3'

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,--v
#%end

I don't think the -- flags are covered by the rules, so I think you
have to do this in the code, i.e. something like this:

if flags['l']:
  env['GRASS_VERBOSE'] = '3'

Merci Moritz,

I tested already (before asking)

env = os.environ.copy()
if list_only:
   env['GRASS_VERBOSE'] = '3'

but it does not work.

Yes, sorry, I just copied your line without thinking.

Aren't there other ways?

Thank you again, N

I guess simply

GRASS_VERBOSE=3
export GRASS_VERBOSE

It works!

Yes, but that's in a shell, not in Python, or ?

In Python, something like this should work IIRC:

import os
os.environ['GRASS_VERBOSE'] = '3'

Moritz

* Moritz Lennert <mlennert@club.worldonline.be> [2017-10-09 13:05:45 +0200]:

On 09/10/17 12:49, Nikos Alexandris wrote:

* Nikos Alexandris <nik@nikosalexandris.net> [2017-10-09 12:18:29 +0200]:

* Moritz Lennert <moritz.lennert@ulb.ac.be> [2017-10-09 10:59:25 +0200]:

On 07/10/17 10:39, Nikos Alexandris wrote:

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env['GRASS_VERBOSE'] = '3'

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,--v
#%end

I don't think the -- flags are covered by the rules, so I think you
have to do this in the code, i.e. something like this:

if flags['l']:
env['GRASS_VERBOSE'] = '3'

Merci Moritz,

I tested already (before asking)

env = os.environ.copy()
if list_only:
  env['GRASS_VERBOSE'] = '3'

but it does not work.

Yes, sorry, I just copied your line without thinking.

Aren't there other ways?

Thank you again, N

I guess simply

GRASS_VERBOSE=3
export GRASS_VERBOSE

It works!

Yes, but that's in a shell, not in Python, or ?

In Python, something like this should work IIRC:

import os
os.environ['GRASS_VERBOSE'] = '3'

But of course it works! Don't know why I got stuck with env instead
os.environ.

Thanks, Nikos

Nikos:

I tested already (before asking)

env = os.environ.copy()
if list_only:
env['GRASS_VERBOSE'] = '3'

but it does not work.

Moritz:

In Python, something like this should work IIRC:

import os
os.environ['GRASS_VERBOSE'] = '3'

But of course it works! Don't know why I got stuck with env instead
os.environ.

For the records, it's somewhat about the logic of the script I am
building. Yet also that, copy(), as used in the first example,
creates a shallow copy. Deep copy works, i.e.
`env=copy.deepcopy(os.environ)` or simply `env=os.environ`

Nikos

It shouldn’t, you copied the environment, you didn’t change the environment used. You would have to take the copied env and pass it to run_command, then it would work. Or of course, modify the actual environment, not the copied one. Hope this clarifies it a bit.

Anna

···

On Oct 9, 2017 3:17 AM, “Nikos Alexandris” <nik@nikosalexandris.net> wrote:

On 07/10/17 10:39, Nikos Alexandris wrote:

In a grassy script, how can I force verbosity, i.e. --v whenever a flag
-l is instructed? Which will lead to

env[‘GRASS_VERBOSE’] = ‘3’

?

i.some.module input=some_input -l

should be identical to

i.some.module input=some_input -l --v

The following is, of course, not working:

#%rules
#% requires_all: -l,–v
#%end

I don’t think the – flags are covered by the rules, so I think you have to do this in the code, i.e. something like this:

if flags[‘l’]:
env[‘GRASS_VERBOSE’] = ‘3’

Merci Moritz,

I tested already (before asking)

env = os.environ.copy()
if list_only:
env[‘GRASS_VERBOSE’] = ‘3’

but it does not work.

Aren’t there other ways?

Thank you again, N


grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev