[GRASS-user] script by bash to Python

Hello
1)
I use grass63 with wxpython and I do not know how to use some scripts that I
have in bash. The graphical interface opens but when I try to launch the
script I get the following error:
GRASS 6.3.0 (gb2):~ > v.topo_5
$ v.topo_5 percorso=/home/gab/prova.shp nome_vett=foglio num=3 campo=foglio
Traceback (most recent call last):
  File "/usr/lib/grass/etc/wxpython/gui_modules/menuform.py", line 763, in
OnRun
    self.goutput.RunCmd(cmd)
  File "/usr/lib/grass/etc/wxpython/gui_modules/goutput.py", line 209, in
RunCmd
    generalCmd = subprocess.Popen(cmdlist,
NameError: global name 'subprocess' is not defined

If I run the script with grass -tcltk works well.

2)
In this regard, as I do reopen grass with wxpython? The first few times I
feel I get "The LOCATION" gab "does not exist. Please create first".

Thank you very much
--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p18292175.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Hi,

2008/7/5 Gabriele N. <gis.gn@libero.it>:

I use grass63 with wxpython and I do not know how to use some scripts that I
have in bash. The graphical interface opens but when I try to launch the
script I get the following error:
GRASS 6.3.0 (gb2):~ > v.topo_5
$ v.topo_5 percorso=/home/gab/prova.shp nome_vett=foglio num=3 campo=foglio
Traceback (most recent call last):
File "/usr/lib/grass/etc/wxpython/gui_modules/menuform.py", line 763, in
OnRun
   self.goutput.RunCmd(cmd)
File "/usr/lib/grass/etc/wxpython/gui_modules/goutput.py", line 209, in
RunCmd
   generalCmd = subprocess.Popen(cmdlist,
NameError: global name 'subprocess' is not defined

If I run the script with grass -tcltk works well.

Upgrading to grass64 (devbr6) should fix it.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi,

Upgrading to grass64 (devbr6) should fix it.

generally speaking, if you want to test wxGUI and report its bugs,
upgrade to grass64.svn is necessary (wxpython code in grass63 is quite
out-dated, just a few serious bugs fixes were backported for 6.3.1).

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi Martin.

I like that.

Thank you very much

Gabriele

Martin Landa-2 wrote:

Hi,

Upgrading to grass64 (devbr6) should fix it.

generally speaking, if you want to test wxGUI and report its bugs,
upgrade to grass64.svn is necessary (wxpython code in grass63 is quite
out-dated, just a few serious bugs fixes were backported for 6.3.1).

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p18295088.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Martin Landa-2 wrote:

Hi,

2008/7/5 Gabriele N. <gis.gn@libero.it>:

I use grass63 with wxpython and I do not know how to use some scripts
that I
have in bash. The graphical interface opens but when I try to launch the
script I get the following error:
GRASS 6.3.0 (gb2):~ > v.topo_5
$ v.topo_5 percorso=/home/gab/prova.shp nome_vett=foglio num=3
campo=foglio
Traceback (most recent call last):
File "/usr/lib/grass/etc/wxpython/gui_modules/menuform.py", line 763, in
OnRun
   self.goutput.RunCmd(cmd)
File "/usr/lib/grass/etc/wxpython/gui_modules/goutput.py", line 209, in
RunCmd
   generalCmd = subprocess.Popen(cmdlist,
NameError: global name 'subprocess' is not defined

If I run the script with grass -tcltk works well.

Upgrading to grass64 (devbr6) should fix it.

Martin

I speak again of this post. With grass64 svn the situation has improved.
Some scripts in bash run well and others do not.
But I do not understand what are the differences between a script that
works and a script that does not work. I do not see the differences.

Thanks
--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p19630269.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Gabriele N. wrote:

>> I use grass63 with wxpython and I do not know how to use some scripts
>> that I
>> have in bash. The graphical interface opens but when I try to launch the
>> script I get the following error:
>> GRASS 6.3.0 (gb2):~ > v.topo_5
>> $ v.topo_5 percorso=/home/gab/prova.shp nome_vett=foglio num=3
>> campo=foglio
>> Traceback (most recent call last):
>> File "/usr/lib/grass/etc/wxpython/gui_modules/menuform.py", line 763, in
>> OnRun
>> self.goutput.RunCmd(cmd)
>> File "/usr/lib/grass/etc/wxpython/gui_modules/goutput.py", line 209, in
>> RunCmd
>> generalCmd = subprocess.Popen(cmdlist,
>> NameError: global name 'subprocess' is not defined
>>
>> If I run the script with grass -tcltk works well.
>
> Upgrading to grass64 (devbr6) should fix it.
  
I speak again of this post. With grass64 svn the situation has improved.
Some scripts in bash run well and others do not.
But I do not understand what are the differences between a script that
works and a script that does not work. I do not see the differences.

The above error is due to a bug in 6.3.0. The bug is only triggered
when running a command which isn't recognised as a GRASS command.
Recognised commands are those corresponding to files in the bin,
scripts and etc/gui/scripts directories, with any .exe or .bat
extension removed.

It's also possible that individual scripts have bugs which are
specific to Windows. GRASS probably doesn't get a fraction of the
testing on Windows that it does on Linux and MacOSX.

--
Glynn Clements <glynn@gclements.plus.com>

Hy Glynn.
Ah ... I work on ubuntu 8.04.

But what could be the commands in the script that GRASS not 'recognize'?

Compared to version 63 with the 64 now run more scripts (always bash).
All the scripts still work well in tcltk.

?
Thanks
Gabriele

Glynn Clements wrote:

Gabriele N. wrote:

>> I use grass63 with wxpython and I do not know how to use some scripts
>> that I
>> have in bash. The graphical interface opens but when I try to launch
the
>> script I get the following error:
>> GRASS 6.3.0 (gb2):~ > v.topo_5
>> $ v.topo_5 percorso=/home/gab/prova.shp nome_vett=foglio num=3
>> campo=foglio
>> Traceback (most recent call last):
>> File "/usr/lib/grass/etc/wxpython/gui_modules/menuform.py", line 763,
in
>> OnRun
>> self.goutput.RunCmd(cmd)
>> File "/usr/lib/grass/etc/wxpython/gui_modules/goutput.py", line 209,
in
>> RunCmd
>> generalCmd = subprocess.Popen(cmdlist,
>> NameError: global name 'subprocess' is not defined
>>
>> If I run the script with grass -tcltk works well.
>
> Upgrading to grass64 (devbr6) should fix it.
  
I speak again of this post. With grass64 svn the situation has improved.
Some scripts in bash run well and others do not.
But I do not understand what are the differences between a script that
works and a script that does not work. I do not see the differences.

The above error is due to a bug in 6.3.0. The bug is only triggered
when running a command which isn't recognised as a GRASS command.
Recognised commands are those corresponding to files in the bin,
scripts and etc/gui/scripts directories, with any .exe or .bat
extension removed.

It's also possible that individual scripts have bugs which are
specific to Windows. GRASS probably doesn't get a fraction of the
testing on Windows that it does on Linux and MacOSX.

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p19637676.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Gabriele wrote:

I speak again of this post. With grass64 svn the situation has improved.
Some scripts in bash run well and others do not.

which ones work, which ones don't?
what does "others do not" run well mean? The same Python GUI error, or..?

But I do not understand what are the differences between a script that
works and a script that does not work. I do not see the differences.

need more details please.

Hamish

Hi.
All my scripts in bash work with tcltk.

Now, I take as example my 2 scripts: v.to.dem.sh and v.impact.sh.
With WxPython all the scripts were not working with grass 63. With Grass64,
instead, some scripts works (es v.impact.sh) and some other scripts does not
works (es.v.to.dem.sh). But I do not know what may be the characteristic
that makes v.impact.sh work and that does not work v.to.dem.sh.

I hope to have been clearer.

Thanks :slight_smile:

Gabriele

PS
The error is always the same. Here's an example:
GRASS 6.4.svn (gb2):~ > v.to.dem.sh
Traceback (most recent call last):
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py", line
1687, in <module>
    GrassGUIApp( grassTask( sys.argv[1] ) ).MainLoop()
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py", line
193, in __init__
    xml.sax.parseString( getInterfaceDescription( grassModule ) ,
processTask( self ) )
  File "/usr/lib/python2.5/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:21:73: not well-formed
(invalid token)
[Raster MASK present]
GRASS 6.4.svn (gb2):~ >

hamish_b wrote:

Gabriele wrote:

I speak again of this post. With grass64 svn the situation has improved.
Some scripts in bash run well and others do not.

which ones work, which ones don't?
what does "others do not" run well mean? The same Python GUI error, or..?

But I do not understand what are the differences between a script that
works and a script that does not work. I do not see the differences.

need more details please.

Hamish

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p19645026.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Gabriele N. wrote:

All my scripts in bash work with tcltk.

Now, I take as example my 2 scripts: v.to.dem.sh and v.impact.sh.
With WxPython all the scripts were not working with grass 63. With Grass64,
instead, some scripts works (es v.impact.sh) and some other scripts does not
works (es.v.to.dem.sh). But I do not know what may be the characteristic
that makes v.impact.sh work and that does not work v.to.dem.sh.

I hope to have been clearer.

Thanks :slight_smile:

Gabriele

PS
The error is always the same. Here's an example:
GRASS 6.4.svn (gb2):~ > v.to.dem.sh
Traceback (most recent call last):
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py", line 1687, in <module>
    GrassGUIApp( grassTask( sys.argv[1] ) ).MainLoop()
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py", line 193, in __init__
    xml.sax.parseString( getInterfaceDescription( grassModule ) , processTask( self ) )
  File "/usr/lib/python2.5/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:21:73: not well-formed
(invalid token)

This indicates the the output from

  v.to.dem.sh --interface-description

isn't valid XML.

This is likely to be caused by the contents of the option descriptions
at the top of the script (the #% lines).

Does one of the entries have <unknown> as its value? If so, which
field (gisprompt, label, etc) is it in?

I suspect that the code which generates the XML data isn't always
converting <, > and & to &lt;, &gt; and &amp; when it should.

You can work around the problem by using e.g. (unknown), but we should
really fix this in the code which generates the XML.

--
Glynn Clements <glynn@gclements.plus.com>

A step forward :slight_smile:
I think that the letters with the accent in the code create problems. I
replaced the letters " è " with " e ' " and now the script v.to.dem.sh work.
Still does not go well: give me an error message when I launch (picture
attached) and does not work the STOP button........ but gives a result in
output.

Unfortunately, doing the same with other scripts I did not have the same
effect. I try to understand what other anomalies can be.

Thank you. I communicate further progress.

Gabriele

http://www.nabble.com/file/p19657956/Screenshot-Error%2Bin%2Bcommand%2Bexecution.png
Screenshot-Error+in+command+execution.png

Glynn Clements wrote:

Gabriele N. wrote:

All my scripts in bash work with tcltk.

Now, I take as example my 2 scripts: v.to.dem.sh and v.impact.sh.
With WxPython all the scripts were not working with grass 63. With
Grass64,
instead, some scripts works (es v.impact.sh) and some other scripts does
not
works (es.v.to.dem.sh). But I do not know what may be the characteristic
that makes v.impact.sh work and that does not work v.to.dem.sh.

I hope to have been clearer.

Thanks :slight_smile:

Gabriele

PS
The error is always the same. Here's an example:
GRASS 6.4.svn (gb2):~ > v.to.dem.sh
Traceback (most recent call last):
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py",
line 1687, in <module>
    GrassGUIApp( grassTask( sys.argv[1] ) ).MainLoop()
  File "/usr/local/grass-6.4.svn/etc/wxpython/gui_modules/menuform.py",
line 193, in __init__
    xml.sax.parseString( getInterfaceDescription( grassModule ) ,
processTask( self ) )
  File "/usr/lib/python2.5/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:21:73: not well-formed
(invalid token)

This indicates the the output from

  v.to.dem.sh --interface-description

isn't valid XML.

This is likely to be caused by the contents of the option descriptions
at the top of the script (the #% lines).

Does one of the entries have <unknown> as its value? If so, which
field (gisprompt, label, etc) is it in?

I suspect that the code which generates the XML data isn't always
converting <, > and & to &lt;, &gt; and &amp; when it should.

You can work around the problem by using e.g. (unknown), but we should
really fix this in the code which generates the XML.

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
View this message in context: http://www.nabble.com/script-by-bash-to-Python-tp18292175p19657956.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Gabriele N. wrote:

A step forward :slight_smile:
I think that the letters with the accent in the code create problems. I
replaced the letters " è " with " e ' " and now the script v.to.dem.sh work.

Is the non-ASCII character embedded in the script, or is it being
translated via a message catalog? The embedded values should be
limited to ASCII; if you want localisation, add translations to the
message catalog.

[If you use the GRASS build system, the "script" target (from
Script.make) will extract the strings into the file
locale/scriptstrings/<script_name>_to_translate.c. From there, the
"pot" target in locale/Makefile will extract the strings when
generating the .pot files.]

For --interface-description, the value (translated or not) will be
copied verbatim into the XML output. The XML data is defined to use
the locale's encoding if langinfo.h was detected by configure, or
UTF-8 otherwise.

Needless to say, this requires that the string uses an encoding which
matches your locale. For translated strings, this should always be the
case, but for untranslated strings, anything which isn't ASCII will
fail if the locale's encoding doesn't match that used for the string.

Still does not go well: give me an error message when I launch (picture
attached) and does not work the STOP button........ but gives a result in
output.

One possibility is that the script is returning a non-zero exit code,
which the GUI considers an error. If you don't have an explicit "exit"
statement at the end of the script, it will return the exit code from
the last command.

--
Glynn Clements <glynn@gclements.plus.com>