[GRASS-dev] grass7 addon python script - finishes in normal and --verbose mode, but not in --quiet mode

Anna Petrášová kratochanna at gmail.com
Fri Nov 14 06:47:33 PST 2014


On Fri, Nov 14, 2014 at 6:37 AM, Moritz Lennert <
mlennert at club.worldonline.be> wrote:

> On 14/11/14 10:25, Helmut Kudrnovsky wrote:
>
>> Anna Petrášová wrote
>>
>>>
>>>> but in --quiet mode it fails with:
>>>>
>>>> v.fixed.segmentpoints --quiet vector=iselflipped at myricaria cat=1
>>>> dir=C:\tmp\grassscript distance=25000
>>>> Traceback (most recent call last):
>>>>    File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons/scr
>>>> ipts/v.fixed.segmentpoints.py", line 226, in
>>>>
>>> <module>
>>>
>>>>      sys.exit(main())
>>>>    File "C:\Users\myricaria\AppData\Roaming\GRASS7\addons/scr
>>>> ipts/v.fixed.segmentpoints.py", line 100, in main
>>>>      vector_line_length =
>>>> float(tmp.split('\n')[1].split('|')[1])
>>>> IndexError: list index out of range
>>>> (Thu Nov 13 21:40:08 2014) Befehl ausgeführt (2 Sek)
>>>>
>>>> any idea?
>>>>
>>>>
>>> Could you try to print tmp with and without quiet?
>>>
>>
>> http://trac.osgeo.org/grass/browser/grass-addons/grass7/
>> vector/v.fixed.segmentpoints/v.fixed.segmentpoints.py#L102
>>
>> 102         # Read length
>> 103         tmp = grass.read_command('v.to.db', map = voutline,
>> 104                                          type = 'line',
>> 105                                          layer = 1,
>> 106                                          qlayer = 1,
>> 107                                          option = 'length',
>> 108                                          units = 'meters',
>> 109                                          column = 'vlength',
>> 110                                          flags = 'p')
>> 111         vector_line_length = float(tmp.split('\n')[1].split('|')[1])
>> 112
>> 113         # Print vector line length
>> 114         grass.message( "Vector line length in meter:" )
>> 115         grass.message( vector_line_length )
>> 116         grass.message( "----" )
>>
>> it's just to get the length of the vector line for further calculations:
>>
>> in normal and verbose mode:
>>
>> ----
>> Lese Objekte...
>> Vector line length in meter:
>> 58858.3366368
>> ----
>>
>> as Moritz points out, it seems quiet mode suppresses the access to the
>> output of grass.read_command; his solution/workaround with GRASS_VERBOSE
>> env
>> variable seems not to work here on my side.
>>
>>
> I'm afraid that --quiet supersedes any settings in the code, but am not
> sure.


So how about  setting quiet=False when calling v.to.db? Anyway I don't
think quiet causes read_command to be completely silent, just run

grass.read_command('r.info', map='elevation', flags='g', quiet=True)

and it gives output as expected.

>
>
> Moritz
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20141114/0173e61e/attachment-0001.html>


More information about the grass-dev mailing list