<div dir="ltr"><div>Hi Vaclav,<br><br></div>sorry for the delay but in the last day I was off-line.<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 17, 2017 at 5:36 PM, Vaclav Petras <span dir="ltr"><<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On Mon, Jul 17, 2017 at 12:36 AM, Pietro <span dir="ltr"><<a href="mailto:peter.zamb@gmail.com" target="_blank">peter.zamb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-m_3599744528868547718gmail-">On Fri, Jul 14, 2017 at 6:00 PM, Vaclav Petras <span dir="ltr"><<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>This is exactly what I had in my mind when doing the last major changes in the grass.py file. <br></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I generally like the layout you suggested. It seems to me that choosing a good name for the whole module will be a bit tricky. </div></blockquote></span><div><br>This is intended as a proof of concept to see the feasibility.<br></div><div>I've try to found a better name but didn't come up to my mind...<br></div><div>Perhaps: <span style="font-family:monospace,monospace">session</span> instead of <span style="font-family:monospace,monospace">init</span>?<br><br></div><div>My final objective is to be able to do something like:<br></div></div></div></div></div></blockquote><div><br></div></span><div>That makes sense. In fact, that's very similar to a file I drafted some time ago splitting the data initialization and runtime in grass.script.setup and adding Session (see the attached file). Another example, for a different case, is here:<br><br><a href="https://github.com/wenzeslaus/g.remote/blob/master/grasssession.py" target="_blank">https://github.com/wenzeslaus/<wbr>g.remote/blob/master/<wbr>grasssession.py</a></div></div></div></div></blockquote><div><br></div><div>Nice module, I was not aware of it!<br></div><div>However I think that the purpose is slightly different. The grassession aims is to generate the session remotely, here I would like to setup a local session. It is true that I should be able to just connect through ssh to the localhost... but it seems to me not the right way. So I've sketch a possible implementation just to see how it could work, see:<br><br><a href="https://git.osgeo.org/gogs/zarch/grass/commit/b9cb69a1d7381924b0c2229ba43f21b1b7473c72">https://git.osgeo.org/gogs/zarch/grass/commit/b9cb69a1d7381924b0c2229ba43f21b1b7473c72</a><br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br><span style="font-family:monospace,monospace"></span></div><span class="gmail-"><div><span style="font-family:monospace,monospace"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace"><b># Perhaps in GRASS8 we will be able to skip this! ;-)</b><br></span></div><div><span style="font-family:monospace,monospace">sys.append(os.environ.get('GIS<wbr>BASE', '/home/pietro/my/gisbase'))<br></span></div></div></div></div></div></blockquote><div><br></div></span><div>Added to the list, but how to do it remains unclear (many different discussions in Trac and ML):<br></div><div><br><a href="https://trac.osgeo.org/grass/wiki/Grass8Planning" target="_blank">https://trac.osgeo.org/grass/<wbr>wiki/Grass8Planning</a></div></div></div></div></blockquote><div><br></div><div>Thank you<br></div><div> <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">from grass.init import Session<br><br></span></div><div><span style="font-family:monospace,monospace"># with statement<br></span></div><div><span style="font-family:monospace,monospace">with Session('mygisdbase/location/m<wbr>apset') as session:<br></span></div><div><span style="font-family:monospace,monospace">    # do my stuff here<br>```</span><br></div><div> <br></div></div></div></div></div></blockquote><div><br></div></span><div>Unfortunately, here is where the trouble begins. The above leads to the following:<br><br></div><div>with Session as session:<br></div><div>    session.run_command(...)<br><br></div><div>which fits with API which already exists for Ruby:<br><br><a href="https://github.com/jgoizueta/grassgis/" target="_blank">https://github.com/jgoizueta/<wbr>grassgis/</a><br></div><div>






<p>
GrassGis.session configuration do+<br>    <a href="http://r.info" target="_blank">r.info</a> 'slope'<br>    g.region '-p'<br>
end
</p>



</div><div>The trouble is that session (at least in Python) needs to depend on the rest of the library because it is the interface for the rest (on demand imports may help here).<br></div></div></div></div></blockquote><div><br></div><div>Sorry I'm not sure that I get your point here, what do you mean?<br>The following code is running at the moment on my machine:<br><br></div><div><span style="font-family:monospace,monospace">```python<br>import os<br>import sys<br><br>MAPSET = '/home/pietro/docdat/gis/nc_basic_spm_grass7/user1/'<br>GISBASE = '/home/pietro/docdat/src/gis/ggrass/dist.x86_64-pc-linux-gnu/'<br><br></span></div><div><span style="font-family:monospace,monospace"># set the path<br></span></div><div><span style="font-family:monospace,monospace">sys.path.append(os.path.join(os.environ.get('GISBASE', GISBASE),<br>                             'etc', 'python'))<br><br></span></div><div><span style="font-family:monospace,monospace"># import the python GRASS libraries<br></span></div><div><span style="font-family:monospace,monospace">from grass.script.core import run_command<br>from session import Session<br><br><br>with Session(MAPSET) as session:<br>    run_command('r.slope.aspect', elevation='elevation',<br>                slope='slope', aspect='aspect',<br>                overwrite=True)</span><span style="font-family:monospace,monospace"><br>```</span><br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>So perhaps having grass.init or grass.setup with the low level functions and then a separate grass.session with a nice interface which may depend on all other modules may be a better way. (Although having each function from the library as a method of Session calls for more thinking about grass.session.Session.</div></div></div></div></blockquote><div><br></div><div>I was thinking to add this Session class definition inside init/session.py to then try to refactor the main function in parser.py:<br><br><a href="https://git.osgeo.org/gogs/zarch/grass/src/grass_session/lib/python/init/parser.py#L189">https://git.osgeo.org/gogs/zarch/grass/src/grass_session/lib/python/init/parser.py#L189</a><br><br></div><div>to start a session and then execute all the rest of the functions to start/use the grass shell/gui.<br></div><div> <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra">Just to be clear: I definitively think this should be done. I'm just not sure what is the right way.<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></div></div></blockquote><div><br></div><div>I'm not sure too! This is why I'm trying to sketch some code drafting to understand what is feasible and how should this organized.<br></div><div>Thank you for taking time to review the code/changes and to give me feedback.<br><br></div><div>Cheers<br><br></div><div>Pietro<br></div><div><br></div></div></div></div>