[GRASS-dev] [GRASS GIS] #2284: Keep pressing Ctrl+C in command line
Huidae Cho
grass4u at gmail.com
Mon May 12 21:06:16 PDT 2014
I just tested with your code above and it works great! No delay between
enters and no keyboard interrupt exceptions. If prompt.py is just for bash
and it's causing issues, I'd like to replace it with grass_prompt.
On Mon, May 12, 2014 at 6:56 PM, Huidae Cho <grass4u at gmail.com> wrote:
> Ok, Let me understand it. So the keyboard interrupted exception is coming
> from prompt.py, not from grass.py. If I replace prompt.py with prompt.sh,
> I'm out of python completely and not facing performance hit either?
>
> I thought as long as grass.py launches bash with whatever PROMPT_COMMAND
> either being prompt.py or prompt.sh, I'm inside a python process and cannot
> avoid keyboard interuption exceptions and slow performance.
>
> Huidae
> On May 12, 2014 6:37 PM, "Glynn Clements" <glynn at gclements.plus.com>
> wrote:
>
>>
>> Huidae Cho wrote:
>>
>> > Would I miss any functionalities by using prompt.sh?
>>
>> No.
>>
>> > I mean other than portability between OSs,
>>
>> prompt.py doesn't provide that. The only way in which the script is
>> executed is by setting the bash variable PROMPT_COMMAND. If set, bash
>> treats its value as a command to execute prior to displaying the
>> primary prompt ($PS1).
>>
>> If you're using bash, you can use either prompt.sh or prompt.py (or
>> something of your own devising, or nothing). If you aren't using bash,
>> neither of those scripts are of any use to you.
>>
>> > does prompt.py provide other benefits? If there's
>> > nothing to lose in Unix by falling back to prompt.sh, I'd like to bring
>> it
>> > into 7 and let the user choose. Maybe if the user is in Unix, there is
>> no
>> > reason at all to use prompt.py?
>>
>> I'm not sure that we need a choice. Actually, I'm not sure that we
>> even need a separate script (in any language). $PROMPT_COMMAND can be
>> any bash command; it doesn't have to be an external program. We could
>> just insert the appropriate code as a bash function into the custom
>> <mapset>/.bashrc file generated by the startup script.
>>
>> IOW, in lib/init/grass.py, replace
>>
>> f.write("PROMPT_COMMAND=\"'%s'\"\n" % os.path.join(gisbase, 'etc',
>> 'prompt.py'))
>>
>> with
>>
>> f.write("""
>> grass_prompt () {
>> LOCATION="`g.gisenv GISDBASE`/`g.gisenv LOCATION_NAME`/`g.gisenv MAPSET`"
>> if test -d "$LOCATION/grid3/G3D_MASK" && test -f "$LOCATION/cell/MASK" ;
>> then
>> echo [Raster and Volume MASKs present]
>> elif test -f "$LOCATION/cell/MASK" ; then
>> echo [Raster MASK present]
>> elif test -d "$LOCATION/grid3/G3D_MASK" ; then
>> echo [Volume MASK present]
>> fi
>> }
>> PROMPT_COMMAND=grass_prompt
>> """)
>>
>> --
>> Glynn Clements <glynn at gclements.plus.com>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140513/f7f816ff/attachment.html>
More information about the grass-dev
mailing list