Importing appropriate classes from the Py Script

This commit is contained in:
sidheshenator 2015-03-09 11:14:17 -04:00
parent dd6d665ce6
commit d4cc1384c0
2 changed files with 7 additions and 6 deletions

View File

@ -290,9 +290,8 @@ public class IngestJobSettings {
try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(settingsFile.getAbsolutePath()))) {
settings = (IngestModuleIngestJobSettings) in.readObject();
} catch(NullPointerException ex){
try {
try (PythonObjectInputStream in = new PythonObjectInputStream(new FileInputStream(settingsFile.getAbsolutePath()))) {
// Reading serialized Jython module settings using NbObjectInputStream.readObject throws a NullPointerException
PythonObjectInputStream in = new PythonObjectInputStream(new FileInputStream(settingsFile.getAbsolutePath()));
settings = (IngestModuleIngestJobSettings) in.readObject();
} catch( IOException | ClassNotFoundException exception) {
String warning = NbBundle.getMessage(IngestJobSettings.class, "IngestJobSettings.moduleSettingsLoad.warning", factory.getModuleDisplayName(), this.context); //NON-NLS
@ -320,9 +319,10 @@ public class IngestJobSettings {
*/
private String getModuleSettingsFilePath(IngestModuleFactory factory) {
String fileName = factory.getClass().getCanonicalName() + IngestJobSettings.MODULE_SETTINGS_FILE_EXT;
//Check if it's a python module class.
// Check if it's a python module class.
// In case of python module class, remove the <instance number> from the fileName.
if(fileName.startsWith("org.python.proxies."))
fileName = fileName.replaceAll("[$][\\d]+.settings", ".settings");
fileName = fileName.replaceAll("[$][\\d]+.settings$", "\\$.settings");
Path path = Paths.get(this.moduleSettingsFolderPath, fileName);
return path.toAbsolutePath().toString();
}

View File

@ -112,9 +112,10 @@ public final class JythonModuleLoader {
// Execute the script and create an instance of the desired class.
interpreter.execfile(script.getAbsolutePath());
// Importing the appropriate class from the Py Script which contains multiple classes.
interpreter.exec("from " + script.getName().replaceAll(".py", "") + " import " + className);
interpreter.exec("obj = " + className + "()"); //NON-NLS
// Returns an INSTANCE of interfaceClass. Causes problem.
T obj = interpreter.get("obj", interfaceClass); //NON-NLS
// Remove the directory where the Python script resides from the Python