[kepler-dev] PythonScript actor

Dan Higgins higgins at nceas.ucsb.edu
Wed Mar 12 19:43:33 PDT 2008


    Thanks for figuring this out! I completely missed the 'standalone 
version' option of the jar file!



Christopher Brooks wrote:
> Hi Dan,
> I had a look at this and the news is good!
> When you install Jython, you can create a standalone
> jython.jar which includes the cached versions of the
> jar files and it looks like it includes the files
> necessary to run the code below.
> I created $PTII/ptolemy/actor/lib/python/test/auto/PythonReadFile.xml
> that uses your sample code.
> The original Jython 2.2.1 jython.jar that I was using
> would not work, I got a message about
> ImportError: no module named javaos
> When I reinstalled Jython by choosing the "Standalone" option, this
> create a new jython.jar that then permitted the model to work.
> I checked in that jython.jar into $PTII/lib.
> One issue is that the jython.jar might have a cache of certain jar
> files or be otherwise hardwired to my particular set up.
> I modified configure.in so that it looks for jython in the path
> and uses that directory if it is found and then checks for --with-jython.
> I also modified $PTII/bin/ptinvoke.in to add -Dpython.home.
> _Christopher
> Christopher Brooks wrote:
>> Hi Dan,
>> There are some examples in $PTII/ptolemy/actor/lib/python/test/auto
>> Other than that, I don't know of anything.
>> It could easily be that we have to set the python.home property.
>> This would make Jython less useful because it would make deployment
>> difficult because deployment would require installing the Jython
>> directory.  The proper solution for the the Jython developers is
>> to ship one jar file that contains the files in the python.home
>> directory.  The other problem with Jython is that the jar cache
>> wants to write on the disk. 
>> I can look at modifying $PTII/bin/vergil so that it includes
>> the python.home hack.  Or, perhaps the Jython actors should
>> be smart enough to set this themselves by looking for the jython.jar
>> file in the classpath? 
>> BTW - the PythonScript actor can change, I don't think there is
>> much use of it, so evolving it to something more useful seems
>> appropriate.
>> _Christopher
>> --------
>>     Hi Christopher,
>>             I have been playing with the PythonScript actor in 
>> Kepler/PTII (as     part of an effort to learn Python/Jython). I am 
>> familiar with the     examples in $PTII/ptolemy/actors/lib/python/ 
>> and the Python actors works     fine with those examples in Kepler 
>> and PTII. Are there any more examples     of Python scripts in PTII?
>>             One reason I ask is that I was trying to get the script 
>> below to     work in Kepler and PTII and I run into several errors, 
>> athough it works     OK when executed directly with the jython 
>> command line interpreter. (The     problem is with importing the os 
>> module and in finding the file named on     the the input port)
>>             import os
>>     from ptolemy.data import IntToken
>>     class Main :
>>       "Number of lines"
>>       def fire(self) :
>>         if not self.input.hasToken(0) :
>>           return
>>         t = self.input.get(0)
>>         fs = t.toString()
>>         # Note the fs includes quotes at both ends that must be 
>> removed !
>>         print fs[1:len(fs)-1]
>>         file = open(fs[1:len(fs)-1],'r')
>>         lines = file.readlines();
>>         cnt = len(lines)
>>         cwd = os.getcwd()
>>         st = IntToken(cnt)
>>         self.output.broadcast(st)
>>         Now, I CAN get the above script to work OK when I add the 
>> following to     the Kepler java startup command
>>         -Dpython.home=/Users/higgins/jython2.2.1
>>         i.e. when I create a new property 'python.home = <path to my 
>> jython home     directory>
>>         I guess I am just questioning the setup for the PythonScript 
>> actor in     Kepler and PTII. Setting python.home does seem to work 
>> OK when one has a     jython installation but I haven't figured out 
>> how to set up jython     within Kepler for more complicated scripts. 
>> In any case, it looks like     just adding jython.jar to the 
>> classpath is not sufficient for some scripts.
>>         Dan Higgins
>> --------
>> _______________________________________________
>> Kepler-dev mailing list
>> Kepler-dev at ecoinformatics.org
>> http://mercury.nceas.ucsb.edu/ecoinformatics/mailman/listinfo/kepler-dev

More information about the Kepler-dev mailing list