importing new jython tools when running in a jython shell

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

importing new jython tools when running in a jython shell

Post by joleenf »

Jon,

We talked about his at the MUG meeting, but I need more guidance. Exactly how do I import the new scripting tools into a Jython shell if I am not running McV? I could copy the tools into an independent script, but if updates to the code occur, I will have to be diligent in copy the updates to the stand-alone version. I am worried that could cause inconsistency especially if any of my automated scripts are shared with other groups in the building. Ideally, a direct import of your code would be best, if not, I can use the alternative.

Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

Sorry for the delayed reply…I've been trying to test this over the weekend. In its current state, I absolutely won't guarantee that everything will work (but you might be surprised), though I'd definitely like to hear about anything that breaks. My intent is to get McV to the point where you could simply run "import mcidasv" and have everything work as expected--but we're definitely not there yet. :(

I've been running the attached script like so (the respectJavaAccessibility thing is important):

Code: Select all

jython -Dpython.security.respectJavaAccessibility=false -i mcvinit.py


With mcvinit.py (and $PWD!) being in some directory where McV was installed. If you want to run from some other directory, you will have to change the following line in mcvinit.py:

Code: Select all

# change $PWD to the directory containing the McV JARs.
_mcv_classpath_to_syspath('$PWD')


Feel free to modify the subsequent imports and whatnot…and questions are always welcome!
Attachments
mcvinit.py
(4.1 KiB) Downloaded 504 times
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I am having no trouble starting up a jython shell this way and interactively using the scripting commands. I am having troubles when I try to test a background run. I don't know how to exit the shell once it is run and I don't know how to enter the commands so that they execute after mcvinit is run. I think I might be on the wrong for this case anyway. Right now I am trying to

start the jyhton interpreter and run listADDEImages
use the times returned to loop:
start McV
getADDEImage
make image pretty, annotate etc.
save image
exit

This is convoluted mainly because I will call a script which calls mcvinit and listADDEImages, which will then attempt to start McV (I am not even sure that is possible). I am wondering if there is a better approach.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I decided not to go this route for now. I did find out that if I just add the desired jython commands to the end of mcvinit.py and add an exit(), I can run in background.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I am working on this again. I needed to update my scripts on a liunix machine and decided to update to the getADDEImage and listADDEImage calls while I was working on other portions of the code. First, I encountered the problem that the from <package> import ( module, module, module) format did not work. I changed those calls to

from <package> import mod1, mod2, mod3,\
mod4, mod5, etc

removing the trailing comma from the end of the grouping in mcvinit.py

Next, I have encountered an error which I did not see when I was previously attempting to work with this code.

*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/sysout-over-slf4j-1.0.2.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/jython.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/ncIdv.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/local-idv.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/local-visad.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/visad.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/idv.jar'
*sys-package-mgr*: processing modified jar, '/home/joleenf/McIDAS-V-System/mcidasv.jar'
Traceback (innermost last):
File "mcvinit2.py", line 78, in ?
File "/home/joleenf/McIDAS-V-System/mcidasv.jar/edu/wisc/ssec/mcidasv/resources/python/see.py", line 43, in ?
ImportError: no module named textwrap



Suggestions? Should I just remove the import see package? I might have many more questions along the way, but I will tackle those as I encounter them.

Thanks,
Joleen
Last edited by joleenf on Wed Feb 19, 2014 7:39 pm, edited 1 time in total.
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Strange…what happens if you place the following lines before the "from see import see" line?

Code: Select all

import sys
print sys.version
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

I don't know if this will help, but I've attached an updated mcvinit.py that should work better with the McV nightly build. The only real differences are the versions of the various JAR files (and I added the IDV's "external.jar").
Attachments
mcvinit.py
(4.42 KiB) Downloaded 487 times
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

The same error occurs in the new version of mcvinit. I also had to change the format of the multiple modules import to

Code: Select all

from background import activeDisplay, allActions, allColorTables, allDisplays, allFontNames,\
    allLayerTypes, allProjections, allWindows, boomstick, collectGarbage,\
    colorTableNames, firstDisplay, firstWindow, getColorTable, getProjection,\
    managedDataSource, pause, performAction, projectionNames, removeAllData,\
    removeAllLayers, setViewSize, _MappedAreaImageFlatField, writeImageAtIndex


otherwise the error is

(no code object) at line 0
File "mcvinit3.py", line 86
from background import (


That is after the import of the see package so I am not sure that would cause a problem. The version of sys is 2.2.1

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I am trying to get this working so that I can start updating my scripts and am stuck. I am working in a jython interactive shell. I have run mcvinit.py. I check sys.modules.keys() and it seems that everything imports until "from see import see." If I try to skip that and import the decorators.deprecated module:

Code: Select all

 from decorators import depreceated
the error is

Traceback (innermost last):
File "<console>", line 1, in ?
File "/home/joleenf/McIDAS-V-System/mcidasv.jar/edu/wisc/ssec/mcidasv/resources/python/utilities/decorators.py", line 29
@wraps(func)


After that, the import of the mcvadde modules, which I need will not work. I don't think I need see, but probably need the decorators.

Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

I'm really sorry for not noticing this earlier, but that version of Jython (2.2.1) is pretty old (2007-10-14). Assuming you're executing McV by running "jython -Dpython.security.respectJavaAccessibility=false -i mcvinit.py", you may need to upgrade the version of Jython you're using. A quick way to test the Jython version is to run "jython -V".

If it's a hassle to upgrade the distribution's version of Jython you may want to try using an installer from jython.org and installing into something like $HOME/jython/<JYTHON_VERSION>. Here's what I ran to get Jython 2.5.3 (which is a little newer than McV's 2.5.2, but should be fine):

Code: Select all

cd /tmp

wget http://search.maven.org/remotecontent\?filepath\=org/python/jython-installer/2.5.3/jython-installer-2.5.3.jar -O jython-installer-2.5.3.jar

java -jar jython-installer-2.5.3.jar -s -d $HOME/jython/2.5.3 -t standard -v

$HOME/jython/2.5.3/jython -V


And then you'd just place "$HOME/jython/2.5.3" at the beginning of $PATH to get "jython -V" responding with "Jython 2.5.3".

If you'd prefer to use 2.5.2, just replace the previous wget and java commands with:

Code: Select all

wget http://sourceforge.net/projects/jython/files/jython/2.5.2/jython_installer-2.5.2.jar/download -O jython-installer-2.5.2.jar

java -jar jython-installer-2.5.2.jar -s -d $HOME/jython/2.5.2 -t standard -v


(and modify $PATH to use "$HOME/jython/2.5.2")
Post Reply