[GRASS-dev] Re: [GRASS-user] Error when importing data in Windows with Python Script

[CC to grass-dev]

Luis Lisboa wrote:

> > I'm running a Python script in WinGRASS6.4 but when I insert as the input
> > C:\Data\L5216065_06520070405_B70.TIF
> >
> > inside Python Script, the input is:
> > C:DataL5216065_06520070405_B10.TIF
> >
> > I realized that, if I, by-hand, i change the \ by / it runs ok.
> >
> > is it possible to have an automatic process to change this instead of
> having
> > the users doing this by-hand?
>
> How are you running the script? If you run it via bash, any
> backslashes will be interpreted before the script is executed. There
> isn't anything the script can do about this.

I'm running via WxGUI's modules. I use the browse button to find the file
and it automatically places the path tot the file. Is this via Bash?

No, but wxGUI's "command prompt" is using shlex.split(), which mimics
a typical Unix shell:

  >>> shlex.split(r'C:\Data\L5216065_06520070405_B70.TIF')
  ['C:DataL5216065_06520070405_B70.TIF']

I suspect that it should have "posix = False" on Windows:

  >>> shlex.split(r'C:\Data\L5216065_06520070405_B70.TIF', posix = False)
  ['C:\\Data\\L5216065_06520070405_B70.TIF']

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

Hello Glynn

About this, What can i do to fix this? Or isn’t anything I can do?
Thanks
Luis

On Fri, Oct 15, 2010 at 6:08 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

[CC to grass-dev]

Luis Lisboa wrote:

I’m running a Python script in WinGRASS6.4 but when I insert as the input
C:\Data\L5216065_06520070405_B70.TIF

inside Python Script, the input is:
C:DataL5216065_06520070405_B10.TIF

I realized that, if I, by-hand, i change the \ by / it runs ok.

is it possible to have an automatic process to change this instead of
having
the users doing this by-hand?

How are you running the script? If you run it via bash, any
backslashes will be interpreted before the script is executed. There
isn’t anything the script can do about this.

I’m running via WxGUI’s modules. I use the browse button to find the file
and it automatically places the path tot the file. Is this via Bash?

No, but wxGUI’s “command prompt” is using shlex.split(), which mimics
a typical Unix shell:

shlex.split(r’C:\Data\L5216065_06520070405_B70.TIF’)
[‘C:DataL5216065_06520070405_B70.TIF’]

I suspect that it should have “posix = False” on Windows:

shlex.split(r’C:\Data\L5216065_06520070405_B70.TIF’, posix = False)
[‘C:\Data\L5216065_06520070405_B70.TIF’]

Glynn Clements <glynn@gclements.plus.com>

Luis Lisboa wrote:

> No, but wxGUI's "command prompt" is using shlex.split(), which mimics
> a typical Unix shell:
>
> >>> shlex.split(r'C:\Data\L5216065_06520070405_B70.TIF')
> ['C:DataL5216065_06520070405_B70.TIF']
>
> I suspect that it should have "posix = False" on Windows:
>
> >>> shlex.split(r'C:\Data\L5216065_06520070405_B70.TIF', posix =
> False)
> ['C:\\Data\\L5216065_06520070405_B70.TIF']

About this, What can i do to fix this? Or isn't anything I can do?

I suggest filing a bug report via http://trac.osgeo.org/grass/

In terms of a fix ... in gui_modules/utils.py, add:

  import shlex

  def split(s):
      return shlex.split(s, posix = (sys.platform != "win32"))

The tricky part is deciding which occurrences of shlex.split() should
be replaced. It's possible that some of them need to retain the POSIX
syntax conventions (where a backslash quotes the following character).
I suspect that those in prompt.py should be changed, but I'm not sure
about the others.

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

Ok at utils.py at line 21 I placed:
import shlex
and at the bottom of the file (linhe 424) I placed

def split(s):
return shlex.split(s, posix = (sys.platform != “win32”))

And I still got this error. Did I did something wrong?

On Mon, Oct 18, 2010 at 2:24 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Luis Lisboa wrote:

No, but wxGUI’s “command prompt” is using shlex.split(), which mimics
a typical Unix shell:

shlex.split(r’C:\Data\L5216065_06520070405_B70.TIF’)
[‘C:DataL5216065_06520070405_B70.TIF’]

I suspect that it should have “posix = False” on Windows:

shlex.split(r’C:\Data\L5216065_06520070405_B70.TIF’, posix =
False)
[‘C:\Data\L5216065_06520070405_B70.TIF’]

About this, What can i do to fix this? Or isn’t anything I can do?

I suggest filing a bug report via http://trac.osgeo.org/grass/

In terms of a fix … in gui_modules/utils.py, add:

import shlex

def split(s):
return shlex.split(s, posix = (sys.platform != “win32”))

The tricky part is deciding which occurrences of shlex.split() should
be replaced. It’s possible that some of them need to retain the POSIX
syntax conventions (where a backslash quotes the following character).
I suspect that those in prompt.py should be changed, but I’m not sure
about the others.

Glynn Clements <glynn@gclements.plus.com>

Luis Lisboa wrote:

Ok at utils.py at line 21 I placed:
import shlex
and at the bottom of the file (linhe 424) I placed
def split(s):
    return shlex.split(s, posix = (sys.platform != "win32"))

And I still got this error. Did I did something wrong?

It isn't sufficient to add the function; you have to change (some of)
the existing shlex.split() calls to use utils.split() instead.

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

Hi Glynn
SOrry to bother you and the rest of the people. But when you say that it’sn’t enough, you mean that all shlex.split() shall be substituted by utils.split()? is that it?
Thanks
Luis

On Wed, Oct 20, 2010 at 2:05 AM, Glynn Clements <glynn@gclements.plus.com> wrote:

Luis Lisboa wrote:

Ok at utils.py at line 21 I placed:
import shlex
and at the bottom of the file (linhe 424) I placed
def split(s):
return shlex.split(s, posix = (sys.platform != “win32”))

And I still got this error. Did I did something wrong?

It isn’t sufficient to add the function; you have to change (some of)
the existing shlex.split() calls to use utils.split() instead.

Glynn Clements <glynn@gclements.plus.com>

Luis Lisboa wrote:

> > Ok at utils.py at line 21 I placed:
> > import shlex
> > and at the bottom of the file (linhe 424) I placed
> > def split(s):
> > return shlex.split(s, posix = (sys.platform != "win32"))
> >
> > And I still got this error. Did I did something wrong?
>
> It isn't sufficient to add the function; you have to change (some of)
> the existing shlex.split() calls to use utils.split() instead.

SOrry to bother you and the rest of the people. But when you say that
it'sn't enough, you mean that all shlex.split() shall be substituted
by utils.split()? is that it?

Yes.

Well, not all of them, but the ones which relate to the command
prompt. Others, e.g. parsing of commands from menudata.xml, shouldn't
depend upon the platform.

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

Glynn I decided re-start this issue…

A few emails ago you mentioned this:
I suspect that those in prompt.py should be changed, but I’m not sure
about the others.

I tried to find this file but there is no prompt.py. Is there any alternative filename?
Thanks
Luis

On Wed, Oct 20, 2010 at 4:29 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Luis Lisboa wrote:

Ok at utils.py at line 21 I placed:
import shlex
and at the bottom of the file (linhe 424) I placed
def split(s):
return shlex.split(s, posix = (sys.platform != “win32”))

And I still got this error. Did I did something wrong?

It isn’t sufficient to add the function; you have to change (some of)
the existing shlex.split() calls to use utils.split() instead.

SOrry to bother you and the rest of the people. But when you say that
it’sn’t enough, you mean that all shlex.split() shall be substituted
by utils.split()? is that it?

Yes.

Well, not all of them, but the ones which relate to the command
prompt. Others, e.g. parsing of commands from menudata.xml, shouldn’t
depend upon the platform.

Glynn Clements <glynn@gclements.plus.com>

Luis Lisboa wrote:

A few emails ago you mentioned this:

> I suspect that those in prompt.py should be changed, but I'm not sure
> about the others.

I tried to find this file but there is no prompt.py. Is there any
alternative filename?

It's not in 6.4.0, only in 6.4-SVN, 6.5 and 7.0. 6.4.0 doesn't use
shlex at all, so that isn't the issue.

I have no idea how (or where) the prompt is implemented in 6.4.0.

I can only suggest that you file a bug report and hope that someone[1]
who understands the GUI can find time to deal with it.

[1] Judging from the revision logs, I suspect that this means Martin.

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

Hi,.

2010/10/18 Glynn Clements <glynn@gclements.plus.com>:

   import shlex

   def split\(s\):
       return shlex\.split\(s, posix = \(sys\.platform \!= &quot;win32&quot;\)\)

we need to find less Python specific way. The 'posix' parameter has
been added in Python 2.6 [1]. OSGeo4W uses Python 2.5, so it will not
work.

Martin

[1] http://docs.python.org/library/shlex.html

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

2010/10/30 Martin Landa <landa.martin@gmail.com>:

we need to find less Python specific way. The 'posix' parameter has

s/specific way/version depended/

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

2010/10/30 Martin Landa <landa.martin@gmail.com>:

   import shlex

   def split\(s\):
       return shlex\.split\(s, posix = \(sys\.platform \!= &quot;win32&quot;\)\)

we need to find less Python specific way. The 'posix' parameter has
been added in Python 2.6 [1]. OSGeo4W uses Python 2.5, so it will not
work.

small workaroud in r44109 (try the next wingrass build). Martin

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

Hello Martin and GRASS community

I’m willing to integrate this “fix/work around” in my GRASS installation. I have customized my winGRASS6.4.1 (from early September) with some scripts and some changes in WxGUI. So, I would like to know what you have implemented/changed in the code in order to try to implement in my version. I just need to know what files you have changed/fixed and them using Diff, I can try to spot the differences

Thanks
Best regards
Luis

On Sat, Oct 30, 2010 at 6:10 PM, Martin Landa <landa.martin@gmail.com> wrote:

2010/10/30 Martin Landa <landa.martin@gmail.com>:

import shlex

def split(s):
return shlex.split(s, posix = (sys.platform != “win32”))

we need to find less Python specific way. The ‘posix’ parameter has
been added in Python 2.6 [1]. OSGeo4W uses Python 2.5, so it will not
work.

small workaroud in r44109 (try the next wingrass build). Martin


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

Hi,

2010/11/3 Luis Lisboa <luislisboa1975@gmail.com>:

and some changes in WxGUI. So, I would like to know what you have
implemented/changed in the code in order to try to implement in my version.
I just need to know what files you have changed/fixed and them using Diff, I
can try to spot the differences

it's http://trac.osgeo.org/grass/changeset/43911

Martin

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