commands from menus and database table not working

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

commands from menus and database table not working

Jachym Cepicky
hi,

after some weeks, I'm back from the middle of nowhere and I tried some
new features of your wx gui.

It looks good, however, no commands are working now:

1 - start the gui
        wxgrass &
2 - Select Raster-> Reports and statistics -> Report basic file
information

3 - Fill the form

4 - Hint "Run" button:

Result:

Traceback (most recent call last):
  File "/usr/src/gis/grass/addons/gui/gui_modules/menuform.py", line
619, in OnRun
    self.goutput.runCmd(cmd)
  File "/usr/src/gis/grass/addons/gui/gui_modules/wxgui_utils.py", line
922, in runCmd
    self.cmd_output.write("$ " + command + "\n")
TypeError: cannot concatenate 'str' and 'list' objects

Why:

method getCmd() of grassTask() class (gui_modules/menform.py, line 215)
returns not command string (e.g. "r.info elevation.dem"), but already
command list (e.g. ["r.info", "map=elevation.dem"]).

This is in conflict with rest of the code, where ever cmd.split(" ") is
called (e.g. wxgui.py line 410 or gui_modules/wxgui_utils.py, line 868).

So, what to do? Fix getCmd(), so it returns string or go through whole
code and try to fix all cmd.split() calls?

Jachym
--
Jachym Cepicky
e-mail: [hidden email]
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub


_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Reply | Threaded
Open this post in threaded view
|

Re: commands from menus and database table not working

Michael Barton
Jachym,

Yet another casualty of the switch from command strings to command lists.
Glynn made a change here that will be better for all in the end. He tried to
catch instances of commands as strings and convert them to lists, but didn't
get them all (there were a lot of places). But we've almost got it done.
Specific comments below.


On 5/21/07 3:14 AM, "Jachym Cepicky" <[hidden email]> wrote:

> hi,
>
> after some weeks, I'm back from the middle of nowhere and I tried some
> new features of your wx gui.
>
> It looks good, however, no commands are working now:
>
> 1 - start the gui
> wxgrass &
> 2 - Select Raster-> Reports and statistics -> Report basic file
> information
>
> 3 - Fill the form
>
> 4 - Hint "Run" button:
>
> Result:
>
> Traceback (most recent call last):
>   File "/usr/src/gis/grass/addons/gui/gui_modules/menuform.py", line
> 619, in OnRun
>     self.goutput.runCmd(cmd)
>   File "/usr/src/gis/grass/addons/gui/gui_modules/wxgui_utils.py", line
> 922, in runCmd
>     self.cmd_output.write("$ " + command + "\n")
> TypeError: cannot concatenate 'str' and 'list' objects
>
> Why:

The problem is not command but "$ " and "\n". They is a strings. Change to

['$ '] + command + ['\n']


>
> method getCmd() of grassTask() class (gui_modules/menform.py, line 215)
> returns not command string (e.g. "r.info elevation.dem"), but already
> command list (e.g. ["r.info", "map=elevation.dem"]).
>
> This is in conflict with rest of the code, where ever cmd.split(" ") is
> called (e.g. wxgui.py line 410 or gui_modules/wxgui_utils.py, line 868).

cmd.split(" ") is potentially problematic and we should avoid it. For
example, <some command> map="My map" will end up as

['<command>', 'map=My', 'map'].

Or <command> query="attribute1>5 and attribute2<15"

['<command>', 'query=attribute>5', 'and', 'attribute2<15']

>
> So, what to do? Fix getCmd(), so it returns string or go through whole
> code and try to fix all cmd.split() calls?

The latter. We've already got most of them, but there are a few left
apparently.

Michael

>
> Jachym  

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton


_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Reply | Threaded
Open this post in threaded view
|

Re: commands from menus and database table not working

Glynn Clements

Michael Barton wrote:

> >     self.cmd_output.write("$ " + command + "\n")
> > TypeError: cannot concatenate 'str' and 'list' objects
> >
> > Why:
>
> The problem is not command but "$ " and "\n". They is a strings. Change to
>
> ['$ '] + command + ['\n']

That will produce a list; does write() accept a list?

But the default string conversion performed by %s probably isn't what
you want. From the leading "$", I'm guessing that you want output in
shell syntax, which is going to need some form of quoting.

OTOH, you could just use Python syntax. Generating Bourne-shell syntax
is arguably wrong for something that's supposed to be cross-platform.

> > method getCmd() of grassTask() class (gui_modules/menform.py, line 215)
> > returns not command string (e.g. "r.info elevation.dem"), but already
> > command list (e.g. ["r.info", "map=elevation.dem"]).
> >
> > This is in conflict with rest of the code, where ever cmd.split(" ") is
> > called (e.g. wxgui.py line 410 or gui_modules/wxgui_utils.py, line 868).
>
> cmd.split(" ") is potentially problematic and we should avoid it. For
> example, <some command> map="My map" will end up as
>
> ['<command>', 'map=My', 'map'].

It doesn't matter for maps, as spaces aren't valid in map names. But
it matters for arbitrary text (titles, etc), filenames, SQL "where"
clauses etc.

> Or <command> query="attribute1>5 and attribute2<15"
>
> ['<command>', 'query=attribute>5', 'and', 'attribute2<15']
>
> >
> > So, what to do? Fix getCmd(), so it returns string or go through whole
> > code and try to fix all cmd.split() calls?
>
> The latter. We've already got most of them, but there are a few left
> apparently.

What is the purpose of getCmd()? If it's meant to return the command
in a form that can be executed within wxgui, it should return a list.

If it's simply a string to show to the user, the format isn't
critical. OTOH, if it's going to be saved to a script, it needs to be
in the appropriate syntax (sh, csh, cmd.exe, etc).

The main point is that, if you have a function which returns a command
as a string, you need to be absolutely crystal clear on what syntax is
used. If it's Bourne-shell syntax, don't try to execute it via cmd.exe
(and vice-versa). If it's just "human-readable string", don't try to
execute it at all.

Depending upon what you want to do, you might need multiple functions
to return commands in different formats. In that case, I would suggest
having class methods always return commands as lists, and have
separate utility functions for converting such lists to strings.

--
Glynn Clements <[hidden email]>

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Reply | Threaded
Open this post in threaded view
|

Re: commands from menus and database table not working

Daniel Calvelo
Hi all.

grassTask is list-ready. In menuform.py, the grassTask.getCmd() is
meant to return a list. We discussed this a few months ago. The
quick'n'dirty way of maing this into a command string is to

" ".join( getCmd() )

This is used in e.g. building the statusbar "current command string",
and used to be also in the OnCopy() event handler. wxgui.py and
wxgui_utils.py should be changed to accomodate a list and call
getCmd() directly instead of the join snippet or equivalent.

Daniel.

On 5/21/07, Glynn Clements <[hidden email]> wrote:

>
> Michael Barton wrote:
>
> > >     self.cmd_output.write("$ " + command + "\n")
> > > TypeError: cannot concatenate 'str' and 'list' objects
> > >
> > > Why:
> >
> > The problem is not command but "$ " and "\n". They is a strings. Change to
> >
> > ['$ '] + command + ['\n']
>
> That will produce a list; does write() accept a list?
>
> But the default string conversion performed by %s probably isn't what
> you want. From the leading "$", I'm guessing that you want output in
> shell syntax, which is going to need some form of quoting.
>
> OTOH, you could just use Python syntax. Generating Bourne-shell syntax
> is arguably wrong for something that's supposed to be cross-platform.
>
> > > method getCmd() of grassTask() class (gui_modules/menform.py, line 215)
> > > returns not command string (e.g. "r.info elevation.dem"), but already
> > > command list (e.g. ["r.info", "map=elevation.dem"]).
> > >
> > > This is in conflict with rest of the code, where ever cmd.split(" ") is
> > > called (e.g. wxgui.py line 410 or gui_modules/wxgui_utils.py, line 868).
> >
> > cmd.split(" ") is potentially problematic and we should avoid it. For
> > example, <some command> map="My map" will end up as
> >
> > ['<command>', 'map=My', 'map'].
>
> It doesn't matter for maps, as spaces aren't valid in map names. But
> it matters for arbitrary text (titles, etc), filenames, SQL "where"
> clauses etc.
>
> > Or <command> query="attribute1>5 and attribute2<15"
> >
> > ['<command>', 'query=attribute>5', 'and', 'attribute2<15']
> >
> > >
> > > So, what to do? Fix getCmd(), so it returns string or go through whole
> > > code and try to fix all cmd.split() calls?
> >
> > The latter. We've already got most of them, but there are a few left
> > apparently.
>
> What is the purpose of getCmd()? If it's meant to return the command
> in a form that can be executed within wxgui, it should return a list.
>
> If it's simply a string to show to the user, the format isn't
> critical. OTOH, if it's going to be saved to a script, it needs to be
> in the appropriate syntax (sh, csh, cmd.exe, etc).
>
> The main point is that, if you have a function which returns a command
> as a string, you need to be absolutely crystal clear on what syntax is
> used. If it's Bourne-shell syntax, don't try to execute it via cmd.exe
> (and vice-versa). If it's just "human-readable string", don't try to
> execute it at all.
>
> Depending upon what you want to do, you might need multiple functions
> to return commands in different formats. In that case, I would suggest
> having class methods always return commands as lists, and have
> separate utility functions for converting such lists to strings.
>
> --
> Glynn Clements <[hidden email]>
>
> _______________________________________________
> grassgui mailing list
> [hidden email]
> http://grass.itc.it/mailman/listinfo/grassgui
>


--
-- Daniel Calvelo Aros

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Reply | Threaded
Open this post in threaded view
|

Re: commands from menus and database table not working

Michael Barton
That's excellent. Should I update and try it?

Any thoughts on my locked up r.profile command??

Cheers
Michael


On 5/22/07 1:02 PM, "Daniel Calvelo" <[hidden email]> wrote:

> Hi all.
>
> grassTask is list-ready. In menuform.py, the grassTask.getCmd() is
> meant to return a list. We discussed this a few months ago. The
> quick'n'dirty way of maing this into a command string is to
>
> " ".join( getCmd() )
>
> This is used in e.g. building the statusbar "current command string",
> and used to be also in the OnCopy() event handler. wxgui.py and
> wxgui_utils.py should be changed to accomodate a list and call
> getCmd() directly instead of the join snippet or equivalent.
>
> Daniel.
>
> On 5/21/07, Glynn Clements <[hidden email]> wrote:
>>
>> Michael Barton wrote:
>>
>>>>     self.cmd_output.write("$ " + command + "\n")
>>>> TypeError: cannot concatenate 'str' and 'list' objects
>>>>
>>>> Why:
>>>
>>> The problem is not command but "$ " and "\n". They is a strings. Change to
>>>
>>> ['$ '] + command + ['\n']
>>
>> That will produce a list; does write() accept a list?
>>
>> But the default string conversion performed by %s probably isn't what
>> you want. From the leading "$", I'm guessing that you want output in
>> shell syntax, which is going to need some form of quoting.
>>
>> OTOH, you could just use Python syntax. Generating Bourne-shell syntax
>> is arguably wrong for something that's supposed to be cross-platform.
>>
>>>> method getCmd() of grassTask() class (gui_modules/menform.py, line 215)
>>>> returns not command string (e.g. "r.info elevation.dem"), but already
>>>> command list (e.g. ["r.info", "map=elevation.dem"]).
>>>>
>>>> This is in conflict with rest of the code, where ever cmd.split(" ") is
>>>> called (e.g. wxgui.py line 410 or gui_modules/wxgui_utils.py, line 868).
>>>
>>> cmd.split(" ") is potentially problematic and we should avoid it. For
>>> example, <some command> map="My map" will end up as
>>>
>>> ['<command>', 'map=My', 'map'].
>>
>> It doesn't matter for maps, as spaces aren't valid in map names. But
>> it matters for arbitrary text (titles, etc), filenames, SQL "where"
>> clauses etc.
>>
>>> Or <command> query="attribute1>5 and attribute2<15"
>>>
>>> ['<command>', 'query=attribute>5', 'and', 'attribute2<15']
>>>
>>>>
>>>> So, what to do? Fix getCmd(), so it returns string or go through whole
>>>> code and try to fix all cmd.split() calls?
>>>
>>> The latter. We've already got most of them, but there are a few left
>>> apparently.
>>
>> What is the purpose of getCmd()? If it's meant to return the command
>> in a form that can be executed within wxgui, it should return a list.
>>
>> If it's simply a string to show to the user, the format isn't
>> critical. OTOH, if it's going to be saved to a script, it needs to be
>> in the appropriate syntax (sh, csh, cmd.exe, etc).
>>
>> The main point is that, if you have a function which returns a command
>> as a string, you need to be absolutely crystal clear on what syntax is
>> used. If it's Bourne-shell syntax, don't try to execute it via cmd.exe
>> (and vice-versa). If it's just "human-readable string", don't try to
>> execute it at all.
>>
>> Depending upon what you want to do, you might need multiple functions
>> to return commands in different formats. In that case, I would suggest
>> having class methods always return commands as lists, and have
>> separate utility functions for converting such lists to strings.
>>
>> --
>> Glynn Clements <[hidden email]>
>>
>> _______________________________________________
>> grassgui mailing list
>> [hidden email]
>> http://grass.itc.it/mailman/listinfo/grassgui
>>
>

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton


_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui