[GRASS-dev] Scripting in Linux

Greetings all

I’m having a few Questions regarding Scripting developing and compilation for LINUX. I have “coded” a Script example, from GRASS book, and now I just want to try it. But it says “Command d.rast.region is not yet implemented”. Do I have to do something because it’s already in the right folder /usr/local/grass-6.4.0svn/scripts.

Thanks and sorry to bother you

Best regards,
Kim

Kim Besson wrote:

I'm having a few Questions regarding Scripting developing and compilation
for LINUX. I have "coded" a Script example, from GRASS book, and now I just
want to try it. But it says "Command d.rast.region is not yet implemented".
Do I have to do something because it's already in the right
folder /usr/local/grass-6.4.0svn/scripts.

The "not yet implemented" error occurs if you run unknown d.* commands
(any command beginning with "d.") from the GUI's interactive prompt.
Essentially, support for running d.* within the GUI is an ugly hack;
it "traps" a fixed set of known commands, but doesn't work for
anything else.

You should still be able to use the script from the shell, or by
adding a command layer within the GUI.

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

Kim wrote:

I'm having a few Questions regarding
Scripting developing and compilation for LINUX. I have
"coded" a Script example, from GRASS book, and now
I just want to try it. But it says "Command
d.rast.region is not yet implemented". Do I have to do
something because it's already in the right
folder /usr/local/grass-6.4.0svn/scripts.

add it with the "command layer" button. most d.* modules can not
control the GUI display window directly.

(but can from the terminal command line on UNIX/X11 with d.mon)

Hamish

Thanks. But regarding other scripts (r., v.) I just have to add them to the Scripts folder without doing anything else,right? (because in Windows it’s necessary to run make)
Regarding “add it with the “command layer” button.” what do you mean with this? Do add a button in Wxpython GUI menu (menudata.xml)?

Thanks
Kim

2010/1/26 Hamish <hamish_b@yahoo.com>

Kim wrote:

I’m having a few Questions regarding
Scripting developing and compilation for LINUX. I have
“coded” a Script example, from GRASS book, and now
I just want to try it. But it says “Command
d.rast.region is not yet implemented”. Do I have to do
something because it’s already in the right
folder /usr/local/grass-6.4.0svn/scripts.

add it with the “command layer” button. most d.* modules can not
control the GUI display window directly.

(but can from the terminal command line on UNIX/X11 with d.mon)

Hamish

Hello Mr. Clements

But, for instance, I have just made a NDVI script (i.ndvi) and I added the file to my script folder but I got the following error:

Traceback (most recent call last):
File “/usr/local/grass-6.4.0svn/etc/wxpython/wxgui.py”,
line 466, in OnRunCmd

self.goutput.RunCmd(cmd, switchPage=False)
File “/usr/local/grass-6.4.0svn/etc/wxpython/gui_modules/g
output.py”, line 352, in RunCmd

menuform.GUI().ParseCommand(cmdlist, parentframe=self)
File “/usr/local/grass-6.4.0svn/etc/wxpython/gui_modules/m
enuform.py”, line 1822, in ParseCommand

handler)
File “/usr/lib/python2.6/xml/sax/init.py”, line 49, in
parseString

parser.parse(inpsrc)
File “/usr/lib/python2.6/xml/sax/expatreader.py”, line
107, in parse

xmlreader.IncrementalParser.parse(self, source)
File “/usr/lib/python2.6/xml/sax/xmlreader.py”, line 123,
in parse

self.feed(buffer)
File “/usr/lib/python2.6/xml/sax/expatreader.py”, line
211, in feed

self._err_handler.fatalError(exc)
File “/usr/lib/python2.6/xml/sax/handler.py”, line 38, in
fatalError

raise exception
xml.sax._exceptions
.
SAXParseException
:
:5:3: not well-formed (invalid token)

Could you tell me what’s wrong? Am I suppose to do something else?

Best regards,
Kim

2010/1/25 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

I’m having a few Questions regarding Scripting developing and compilation
for LINUX. I have “coded” a Script example, from GRASS book, and now I just
want to try it. But it says “Command d.rast.region is not yet implemented”.
Do I have to do something because it’s already in the right
folder /usr/local/grass-6.4.0svn/scripts.

The “not yet implemented” error occurs if you run unknown d.* commands
(any command beginning with “d.”) from the GUI’s interactive prompt.
Essentially, support for running d.* within the GUI is an ugly hack;
it “traps” a fixed set of known commands, but doesn’t work for
anything else.

You should still be able to use the script from the shell, or by
adding a command layer within the GUI.


Glynn Clements <glynn@gclements.plus.com>

Kim wrote:

Thanks. But regarding other scripts (r.*,
v.*) I just have to add them to the
Scripts folder without doing anything else,right?

sure, as long as they have their executable bit set and are in
the search path.

FWIW, I try to copy custom stuff into a dir outside the install
dir which is pointed to by the GRASS_ADDON_PATH environment
variable, that way I can replace & upgrade grass versions
without accidentally deleting all my custom scripts.
see the "variables" help page.

(because in Windows it's necessary to run make)

I'm not really familiar with adding scripts on Windows, sorry.

Regarding "add it with the "command layer" button." what do
you mean with this?

In the (wx)GIS Layer Manager window theres a button for it with
what looks like a tiny prompt (>_) just to the left of one
with a paperclip. In the TclTk GUI the button looks like a cross
between a cog and a flower.

Hamish

Kim Besson wrote:

But, for instance, I have just made a NDVI script (i.ndvi) and I added the
file to my script folder but I got the following error:

SAXParseException
:
<unknown>:5:3: not well-formed (invalid token)

Could you tell me what's wrong? Am I suppose to do something else?

Can you post the output from "i.ndvi --interface-description" ?

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

Kim Besson wrote:

Thanks. But regarding other scripts (r.*, v.*) I just have to add them to
the Scripts folder without doing anything else,right? (because in Windows
it's necessary to run make)

On Windows, each shell script in $GISBASE/scripts needs a
corresponding batch file in $GISBASE/bin (to work around the fact that
Windows doesn't understand "#!/bin/sh").

These batch files are generated automatically when "make"ing a script.
You can create one manually by copying and modifying one of the
existing batch files.

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

Yeah sure…
The following was printed in TERMINAL:

(python:2176): Gtk-CRITICAL **: gtk_widget_event: assertion `WIDGET_REALIZED_FOR_EVENT (widget, event)’ failed

And at the command output it was:

<?xml version="1.0" encoding="ANSI_X3.4-1968"?> NDVI Calculus DW-E, raster, imagery, vegetation raster input map (Near Infrared) raster input map (Red) raster output NDVI map Allow output files to overwrite existing files Verbose module output Quiet module output (Tue Jan 26 15:38:40 2010) Command finished (0 sec)

This gives us any light?

2010/1/26 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

But, for instance, I have just made a NDVI script (i.ndvi) and I added the
file to my script folder but I got the following error:

SAXParseException
:
:5:3: not well-formed (invalid token)

Could you tell me what’s wrong? Am I suppose to do something else?

Can you post the output from “i.ndvi --interface-description” ?

Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

And at the command output it was:
<?xml version="1.0" encoding="ANSI_X3.4-1968"?>
<!DOCTYPE task SYSTEM "grass-interface.dtd">
<task name="i.ndvi">

[snip]

I don't see anything wrong with that.

Does your script work from the command line? Does it work when run
with the --ui switch?

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

Hello Clements
Ok. I have tested what Antonio sent to the mailing list and the problem is that one: I used special characters in the Module/Option description.

So, it seems that I cannot use those special characters.
My question is: If I want to add a text line in *.po files, regarding a description in a Script, in wich .po file I have to add an extra line?
And how can I tell if it’s a UTF-8 or a ISO-8859-
file?

Thank you so much
Kim

2010/1/26 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

And at the command output it was:

<?xml version="1.0" encoding="ANSI_X3.4-1968"?>

[snip]

I don’t see anything wrong with that.

Does your script work from the command line? Does it work when run
with the --ui switch?

Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

Ok. I have tested what Antonio sent to the mailing list and the problem is
that one: I used special characters in the Module/Option description.

So, it seems that I cannot use those special characters.
My question is: If I want to add a text line in *.po files, regarding a
description in a Script, in wich *.po file I have to add an extra line?

For scripts, the translation is performed by g.parser, which uses the
"grassmods" file.

And how can I tell if it's a UTF-8 or a ISO-8859-* file?

At the top of the file, there should be a line like:

  "Content-Type: text/plain; charset=ISO-8859-15\n"

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

This might have something to do with a few messages related with i.tasscap translation.

Ok (I have tested this at my WinGRASS installation due to limit access to my LINUX machine):
1- I downloaded grassmods_es.po file (the first language where I want to have my NDVI calculator available). Other will be Brazilian and of course English (already available in the Script code).
2- Just like Glynn said, At the po file header is some information: “Content-Type: text/plain; charset=ISO-8859-1\n”
3- At grassmods.mo the following was there:

#: …/locale/scriptstrings/i.tasscap_to_translate.c:1
msgid “Tasseled Cap (Kauth Thomas) transformation for LANDSAT-TM data”
msgstr “Transformación Tasseled Cap (Kauth Thomas) para datos LANDSAT-TM”
4- using po Editor I created mo files and renamed and put them in location/es/LC_Messages

4- I added the following to my Init.bat

set LANGUAGE=es_ES
set LANG=es_ES
set LC_ALL=es_ES
5- I Started GRASS and realize that:

  • GUI is in spanish (bueno :slight_smile: buttons, text in status bar in the bottom; menu
  • But i.tasscap and neither other scripts are translated even If I have them in my mo file.
    6- I decided to compare the type of files I mean, wxpython_es.po that is working againts grassmods_es.po that isn’t.
    Conclusions: The one that is working is UTF-8 and Content-Transfer-Encoding: 8bit\n and the other one is charset=ISO-8859-1.

Is this the problem? If it’s how can we contour this problem, I mean use special characters? (I also experiment with De and it also didnt’ work).

Thank you

Kim

Kim Besson wrote:

Ok. I have tested what Antonio sent to the mailing list and the problem is
that one: I used special characters in the Module/Option description.

So, it seems that I cannot use those special characters.
My question is: If I want to add a text line in *.po files, regarding a
description in a Script, in wich *.po file I have to add an extra line?

For scripts, the translation is performed by g.parser, which uses the
“grassmods” file.

And how can I tell if it’s a UTF-8 or a ISO-8859-* file?

At the top of the file, there should be a line like:

“Content-Type: text/plain; charset=ISO-8859-15\n”

Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

This might have something to do with a few messages related with i.tasscap
translation.

Ok (I have tested this at my WinGRASS installation due to limit access to my
LINUX machine):
1- I downloaded grassmods_es.po file (the first language where I want to
have my NDVI calculator available). Other will be Brazilian and of course
English (already available in the Script code).
2- Just like Glynn said, At the po file header is some
information: "Content-Type: text/plain; charset=ISO-8859-1\n"
3- At grassmods.mo the following was there:
#: ../locale/scriptstrings/i.tasscap_to_translate.c:1
msgid "Tasseled Cap (Kauth Thomas) transformation for LANDSAT-TM data"
msgstr "Transformación Tasseled Cap (Kauth Thomas) para datos LANDSAT-TM"
4- using po Editor I created mo files and renamed and put them in
location/es/LC_Messages
4- I added the following to my Init.bat
set LANGUAGE=es_ES
set LANG=es_ES
set LC_ALL=es_ES
5- I Started GRASS and realize that:
- GUI is in spanish (bueno :slight_smile: buttons, text in status bar in the bottom;
menu
- But i.tasscap and neither other scripts are translated even If I have them
in my mo file.
6- I decided to compare the type of files I mean, wxpython_es.po that is
working againts grassmods_es.po that isn't.

Ensure that GRASS was configured with the --with-nls flag, otherwise
it won't use translations. The wxPython GUI will use translations
regardless of how GRASS was configured.

Conclusions: The one that is working is UTF-8
and Content-Transfer-Encoding: 8bit\n and the other one
is charset=ISO-8859-1.

Is this the problem? If it's how can we contour this problem, I mean use
special characters? (I also experiment with De and it also didnt' work).

The encoding of the .po file isn't "visible" to the code which uses
the translations. The .mo file will always contain UTF-8 text, but
this is automatically converted to the locale's encoding when the
translation is retrieved.

In 6.4, there is (or was?) a known bug with the GUI and non-UTF-8
locales: the GUI converts the text from the locale's encoding to
UTF-8, but leaves the original encoding in the XML header, which can
confuse the XML parser. But this depends upon the locale's encoding,
not the encoding of the .po file.

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

On Wed, Jan 27, 2010 at 6:47 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:
...

In 6.4, there is (or was?)

Was. It has been solved 25 Jan 2010 in SVN.

a known bug with the GUI and non-UTF-8
locales: the GUI converts the text from the locale's encoding to
UTF-8, but leaves the original encoding in the XML header, which can
confuse the XML parser. But this depends upon the locale's encoding,
not the encoding of the .po file.

Please update to latest 6.4.svn from SVN if not done already to exclude
that you locally have the already solved bug.

Markus

Hello all

Ok I have configured and compiled with -nls with the latest SVN6.4 snapshot. I defined LANG and LANGUAGE in init.sh.
my grasswxpy seems to be working but I thing my grassmods is not being read since no script/module is being translated.

I got the following warning in my terminal window:

(process:2783): Gdk-WARNING **: locale not supported by C library

(process:2783): Gtk-WARNING **: Locale not supported by C library.
Using the fallback ‘C’ locale.

Do anyone knows what might be happening?

Thank you so much
Kim

2010/1/27 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

This might have something to do with a few messages related with i.tasscap
translation.

Ok (I have tested this at my WinGRASS installation due to limit access to my
LINUX machine):
1- I downloaded grassmods_es.po file (the first language where I want to
have my NDVI calculator available). Other will be Brazilian and of course
English (already available in the Script code).
2- Just like Glynn said, At the po file header is some
information: “Content-Type: text/plain; charset=ISO-8859-1\n”
3- At grassmods.mo the following was there:
#: …/locale/scriptstrings/i.tasscap_to_translate.c:1
msgid “Tasseled Cap (Kauth Thomas) transformation for LANDSAT-TM data”
msgstr “Transformación Tasseled Cap (Kauth Thomas) para datos LANDSAT-TM”
4- using po Editor I created mo files and renamed and put them in
location/es/LC_Messages
4- I added the following to my Init.bat
set LANGUAGE=es_ES
set LANG=es_ES
set LC_ALL=es_ES
5- I Started GRASS and realize that:

  • GUI is in spanish (bueno :slight_smile: buttons, text in status bar in the bottom;
    menu
  • But i.tasscap and neither other scripts are translated even If I have them
    in my mo file.
    6- I decided to compare the type of files I mean, wxpython_es.po that is
    working againts grassmods_es.po that isn’t.

Ensure that GRASS was configured with the --with-nls flag, otherwise
it won’t use translations. The wxPython GUI will use translations
regardless of how GRASS was configured.

Conclusions: The one that is working is UTF-8
and Content-Transfer-Encoding: 8bit\n and the other one
is charset=ISO-8859-1.

Is this the problem? If it’s how can we contour this problem, I mean use
special characters? (I also experiment with De and it also didnt’ work).

The encoding of the .po file isn’t “visible” to the code which uses
the translations. The .mo file will always contain UTF-8 text, but
this is automatically converted to the locale’s encoding when the
translation is retrieved.

In 6.4, there is (or was?) a known bug with the GUI and non-UTF-8
locales: the GUI converts the text from the locale’s encoding to
UTF-8, but leaves the original encoding in the XML header, which can
confuse the XML parser. But this depends upon the locale’s encoding,
not the encoding of the .po file.

Glynn Clements <glynn@gclements.plus.com>

Ok Regarding this email, according to an email from Glynn, I sould have this folder /usr/share/i18n/locales in order to run Language packages.
But I do have… Any thoughts about this?

2010/1/28 Kim Besson <kimbesson1981@gmail.com>

Hello all

Ok I have configured and compiled with -nls with the latest SVN6.4 snapshot. I defined LANG and LANGUAGE in init.sh.
my grasswxpy seems to be working but I thing my grassmods is not being read since no script/module is being translated.

I got the following warning in my terminal window:

(process:2783): Gdk-WARNING **: locale not supported by C library

(process:2783): Gtk-WARNING **: Locale not supported by C library.
Using the fallback ‘C’ locale.

Do anyone knows what might be happening?

Thank you so much
Kim

2010/1/27 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

This might have something to do with a few messages related with i.tasscap
translation.

Ok (I have tested this at my WinGRASS installation due to limit access to my
LINUX machine):
1- I downloaded grassmods_es.po file (the first language where I want to
have my NDVI calculator available). Other will be Brazilian and of course
English (already available in the Script code).
2- Just like Glynn said, At the po file header is some
information: “Content-Type: text/plain; charset=ISO-8859-1\n”
3- At grassmods.mo the following was there:
#: …/locale/scriptstrings/i.tasscap_to_translate.c:1
msgid “Tasseled Cap (Kauth Thomas) transformation for LANDSAT-TM data”
msgstr “Transformación Tasseled Cap (Kauth Thomas) para datos LANDSAT-TM”
4- using po Editor I created mo files and renamed and put them in
location/es/LC_Messages
4- I added the following to my Init.bat
set LANGUAGE=es_ES
set LANG=es_ES
set LC_ALL=es_ES
5- I Started GRASS and realize that:

  • GUI is in spanish (bueno :slight_smile: buttons, text in status bar in the bottom;
    menu
  • But i.tasscap and neither other scripts are translated even If I have them
    in my mo file.
    6- I decided to compare the type of files I mean, wxpython_es.po that is
    working againts grassmods_es.po that isn’t.

Ensure that GRASS was configured with the --with-nls flag, otherwise
it won’t use translations. The wxPython GUI will use translations
regardless of how GRASS was configured.

Conclusions: The one that is working is UTF-8
and Content-Transfer-Encoding: 8bit\n and the other one
is charset=ISO-8859-1.

Is this the problem? If it’s how can we contour this problem, I mean use
special characters? (I also experiment with De and it also didnt’ work).

The encoding of the .po file isn’t “visible” to the code which uses
the translations. The .mo file will always contain UTF-8 text, but
this is automatically converted to the locale’s encoding when the
translation is retrieved.

In 6.4, there is (or was?) a known bug with the GUI and non-UTF-8
locales: the GUI converts the text from the locale’s encoding to
UTF-8, but leaves the original encoding in the XML header, which can
confuse the XML parser. But this depends upon the locale’s encoding,
not the encoding of the .po file.

Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

Ok Regarding this email, according to an email from Glynn, I sould have this
folder /usr/share/i18n/locales in order to run Language packages.
But I do have... Any thoughts about this?

You may also need to compile them (some distributions compile all
locales automatically, others require that specific locales are
enabled). Try "localedef --list-archive".

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

Ok I try that command and nothing seems to happen.

Then I tried GRASS with DE language package and only wxGUI was translated.

What am I missing? Because it should be just fine… Or what should I have to do to debug this issue?

2010/1/29 Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

Ok Regarding this email, according to an email from Glynn, I sould have this
folder /usr/share/i18n/locales in order to run Language packages.
But I do have… Any thoughts about this?

You may also need to compile them (some distributions compile all
locales automatically, others require that specific locales are
enabled). Try “localedef --list-archive”.

Glynn Clements <glynn@gclements.plus.com>

Kim Besson wrote:

Ok I try that command and nothing seems to happen.

Then I tried GRASS with DE language package and only wxGUI was translated.

This normally indicates that GRASS was built without NLS.

What am I missing? Because it should be just fine... Or what should I have
to do to debug this issue?

1. Are you sure that NLS is enabled? I mention this because configure
silently ignores unknown (e.g. mis-spelled) configure switches.

Check for:

  #i18N
  HAVE_NLS = 1

in Platform.make and :

  /* define if libintl.h exists */
  #define HAVE_LIBINTL_H 1
  
  /* define if iconv.h exists */
  #define HAVE_ICONV_H 1
  
  /* define if NLS requested */
  #define USE_NLS 1

in config.h.

Also check for:

         U bindtextdomain
and:
         U dgettext

in the output from:

  nm -D dist.i686-pc-linux-gnu/lib/libgrass_gis.so

and:
         U G_gettext

in the output from:

  nm -D dist.i686-pc-linux-gnu/bin/g.parser

2. Have you re-created the .mo file after modifying the .po file? This
is done with:

  make -C locale mo

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