[GRASS-user] some issues with python scripts

Carlos Grohmann carlos.grohmann at gmail.com
Sun Jan 16 17:28:28 EST 2011


Hello all.

I've been trying to convert some of my bash scripts to python, but
some issues appeared:

1 - it seems that http://grass.osgeo.org/programming6/pythonlib.html is offline

2 - dealing with maps names. if I use find_file, I end up with the
full name of the map (that is, map name plus mapset) in the
dictionary. The wx interface created by g.parser includes the mapset
in the map name, and all that goes as a string to find_file:

>>> import grass.script as grass

# this is what should happen
>>> elevmap = 'cass'
>>> find_elev = grass.find_file(elevmap, element = 'cell')
>>> find_elev
{'fullname': 'cass at brasil', 'mapset': 'brasil', 'name': 'cass',
'file': '/home/guano/grassdata/amsul_wgs84/brasil/cell/cass'}

# this is what actually happens when using the wx interface
>>> elevmap = 'cass at brasil'
>>> find_elev = grass.find_file(elevmap, element = 'cell')
>>> find_elev
{'fullname': 'cass at brasil', 'mapset': 'brasil', 'name': 'cass at brasil',
'file': '/home/guano/grassdata/amsul_wgs84/brasil/cell/cass'}
>>>


3 - temp files.
In my bash scripts I used temp files. I found out that using
g.tempfile() gives me a filename with a full path, which cannot be
used in r.mapcalc, for instance.
So I just used normal files that I delete in the end of the script. Is
there a better way?

4 - error handling + user break
In my bash scripts I have a few lines that deal with user break:

#######################################################################
# what to do in case of user break:
exitprocedure()
{
 g.message -e 'User break!'
 #delete any TMP files:
 g.remove rast=$TMP1,$TMP2,$TMP3,$TMP4 > /dev/null

}
# shell check for user break (signal list: trap -l)
trap "exitprocedure" 2 3 15

what would be an equivalent for python?


many thanks!

Carlos




-- 
Prof. Carlos Henrique Grohmann - Geologist D.Sc.
Institute of Geosciences - Univ. of São Paulo, Brazil
http://www.igc.usp.br/pessoais/guano
http://lattes.cnpq.br/5846052449613692
Linux User #89721
________________
Can’t stop the signal.


More information about the grass-user mailing list