From: <bc...@wo...> - 2001-01-24 11:37:40
|
[Chris Atkins] >I am embedding jython in my code. How would I pass the -D options to the >InteractiveConsole? [finn] > Take a look at 6.2 in the faq: > > http://jython.sourceforge.net/cgi-bin/faqw.py?req=all#6.2 > > You can set python.security.respectJavaAccessibility in the same way. It > most be done before creating any python objects, including the creation > of the interpreter. [back to Chris] >In my java code I do the following: > java.util.Properties props = System.getProperties(); >add properties for other tools with names which do not conflict with python > PySystemState.initialize(pyProps, null, s_scriptArgs); Is pyProps a typo? I guess you mean props. >I start up my app with >PYFLAGS="-Dpython.home=$JPYTHONDIR -Dpython.path=$JPYTHONPATH -D >python.cachedir=$JPYTHONCACHEDIR" > >java -classpath . $PYFLAGS MyClass args > >This should have place the python properties in both the system properties >and set them on the interactive console. According to the rules, it should >have picked up the $PYFLAGS over the registry No. The rules on the registry.html says Jython properties > registry files > System.properties. i.e. the registry files will typically be searched before the System.properties. >since set on the PySystemState. That makes no difference. The org.python.util.jython class also calls initialize with: PySystemState.initialize(System.getProperties(), opts.properties, opts.argv); where opts.properties contains the -D options found as argument to jython class (aka Jython properties). >It instead used what is in the registry. Right. In your examples, the value for jython properties is null (meaning empty) so the registry files is searched first. Only if nothing is found there is the System.properties searched. >I changed my code to do the following: > > java.util.Properties pyProps = new java.util.Properties(); > pyProps.setProperty("python.security.respectJavaAccessibility", "0"); > if (s_scriptArgs == null) s_scriptArgs = new String[0]; > PySystemState.initialize(pyProps, null, s_scriptArgs); I guess this will do most of what you're after: java.util.Properties pyProps = new java.util.Properties(); # Insert selected (or maybe all?) System.properties into # jython properties. String s = System.getProperty("python.home"); if (s != null) pyProps.setProperty("python.home", s); s = System.getProperty("python.path"); if (s != null) pyProps.setProperty("python.path", s); s = System.getProperty("python.cachedir"); if (s != null) pyProps.setProperty("python.cachedir", s); # Set some application properties. pyProps.setProperty("python.security.respectJavaAccessibility", "0"); PySystemState.initialize(System.getProperties(), pyProps, s_scriptArgs); >Can you explain this? I hope the above helps. All in all, I think the property lookup mechanism as mostly Ok. Perhaps we should have a way of changing the lookup priority since I guess you would rather use: Jython properties > System.properties > registry files OTOH we shouldn't make it more complicated for novices. The only real drawback I know off, is the use of the -D command line option for jython properties. This is commonly used by the java command as well and that can be confusing. regards, finn |