<div dir="ltr">Hi,<div><br></div><div>you can look how Layer manager launches scripts:</div><div><a href="https://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/lmgr/frame.py#L841">https://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/lmgr/frame.py#L841</a>, I think it requires setting the GRASS_ADDON_PATH</div><div><br></div><div>I remember this problem, maybe it's in parser. There might be a ticket already, but I am not sure. If you can't find anything related, please create a ticket.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 13, 2015 at 9:33 AM, Michel Wortmann <span dir="ltr"><<a href="mailto:wortmann@pik-potsdam.de" target="_blank">wortmann@pik-potsdam.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
Hi Stefan,<br>
I have been meaning to implement something like this too and got
your example to work with the additional step of setting the
environment variable GRASS_ADDON_PATH (and under unix setting the
permissions). Here is my example just parsing the first mapset it
finds:<br>
<br>
<tt>import os, tempfile, stat</tt><tt><br>
</tt><tt>import grass.script as grass</tt><tt><br>
</tt><tt><br>
</tt><tt>module = 'subbasins.py'</tt><tt><br>
</tt><tt><br>
</tt><tt>if __name__=='__main__':</tt><span class=""><tt><br>
</tt><tt> answer = grass.mapsets(search_path = True)</tt><tt><br>
</tt></span><tt> available_mapsets = grass.mapsets()</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> script=file(module,'r').read()</tt><span class=""><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> with tempfile.NamedTemporaryFile(delete = False) as s:</tt><tt><br>
</tt><tt> s.write('''#!/usr/bin/env python</tt><tt><br>
</tt><tt># -*- coding: utf-8 -*-</tt><tt><br>
</tt><tt><br>
</tt></span><tt>{script}</tt><tt><br>
</tt><tt><br>
</tt><tt>#%Option</tt><tt><br>
</tt><tt>#% key:{option}</tt><tt><br>
</tt><tt>#%end</tt><tt><br>
</tt><tt><br>
</tt><tt>'''.format(script=script,option=available_mapsets[0].lower()))</tt><span class=""><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> startcmd = 'python '+<a href="http://s.name" target="_blank">s.name</a></tt><tt><br>
</tt><tt> # set env variable</tt><tt><br>
</tt></span><tt> aoev='GRASS_ADDON_PATH'</tt><tt><br>
</tt><tt> tmpdir = os.path.basename(<a href="http://s.name" target="_blank">s.name</a>)</tt><tt><br>
</tt><tt> if aoev in os.environ:</tt><tt><br>
</tt><tt> os.environ[aoev]=[tmpdir]+os.environ[aoev]</tt><tt><br>
</tt><tt> else:</tt><tt><br>
</tt><tt> os.environ[aoev]=[tmpdir]</tt><span class=""><tt><br>
</tt><tt> # set permissions</tt><tt><br>
</tt><tt> os.chmod(<a href="http://s.name" target="_blank">s.name</a>, os.stat(<a href="http://s.name" target="_blank">s.name</a>).st_mode |
stat.S_IEXEC)</tt><tt><br>
</tt><tt> # start module</tt><tt><br>
</tt><tt> os.system(startcmd)</tt><tt><br>
</tt><tt> os.remove(<a href="http://s.name" target="_blank">s.name</a>)</tt><br>
<br></span>
Let me know if this works under Windows too.<span class=""><font color="#888888"><br>
Michel</font></span><span class=""><br>
<br>
<div>On 10/12/2015 12:55 PM, Blumentrath,
Stefan wrote:<br>
</div>
</span><blockquote type="cite"><div><div class="h5">
<div>
<p class="MsoNormal"><span style="color:rgb(31,73,125)">Hi again,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Now
I found out that the parser section in the inner python
script was not formated properly.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">However,
when I now call the inner script with ‘--ui’ I get an error:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Unable
to fetch interface description for command ‘tmpjksdfjiol’<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Details:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Try
to set up GRASS_ADDON_PATH or GRASS_ADDON_BASE variable.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">It
was neither possible to run the script using
grass.run_command() (on Windows).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Cheers<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US">Stefan<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125)" lang="EN-US"><u></u> <u></u></span></p>
<div>
<div style="border-style:solid none none;border-top-color:rgb(225,225,225);border-top-width:1pt;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US">
grass-dev [<a href="mailto:grass-dev-bounces@lists.osgeo.org" target="_blank">mailto:grass-dev-bounces@lists.osgeo.org</a>]
<b>On Behalf Of </b>Blumentrath, Stefan<br>
<b>Sent:</b> 12. oktober 2015 11:36<br>
<b>To:</b> GRASS developers list
(<a href="mailto:grass-dev@lists.osgeo.org" target="_blank">grass-dev@lists.osgeo.org</a>)
<a href="mailto:grass-dev@lists.osgeo.org" target="_blank"><grass-dev@lists.osgeo.org></a><br>
<b>Subject:</b> [GRASS-dev] Using a dynamic text in
module header for parser<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span lang="EN-US">I would like to fill:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">#% options:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">and<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">#% answer<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">in a parser option for a
python script dynamically. In particular I want to have
tickboxes for available mapsets in the module GUI…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Meaning something like
this (but less complex / not interactive):<u></u><u></u></span></p>
<p class="MsoNormal"><a href="http://permalink.gmane.org/gmane.comp.gis.grass.gui/667" target="_blank"><span lang="EN-US">http://permalink.gmane.org/gmane.comp.gis.grass.gui/667</span></a><span lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">My amateur programming
skills do unfortunately not allow me to really understand
how to accomplish what Glynn describes in the post above…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I tried to generate and
run a temporary python script from within my script like
this:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">def main():<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> answer =
grass.mapsets(search_path = True)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> available_mapsets =
str(grass.mapsets())<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> with
tempfile.NamedTemporaryFile(delete = False) as s:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> s.write('''
#!/usr/bin/env python<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"># -*- coding: utf-8 -*-<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"># Here comes the full
module with header for the parser<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">#% options: ''' +
str(','.join(available_mapsets))<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">’’’)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> startcmd = 'python '
+ <a href="http://s.name" target="_blank">s.name</a><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> os.system(startcmd)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> os.remove(<a href="http://s.name" target="_blank">s.name</a>)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">But that way the GUI
never starts, when I call the outer script from GRASS and it
seems that option never get parsed…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Any hints how to
proceed?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks for helping in
advance.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Stefan<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><span class=""><pre>_______________________________________________
grass-dev mailing list
<a href="mailto:grass-dev@lists.osgeo.org" target="_blank">grass-dev@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-dev</a></pre>
</span></blockquote>
<br>
</div>
<br>_______________________________________________<br>
grass-dev mailing list<br>
<a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br></blockquote></div><br></div></div></div>