Subversion Repositories SmartDukaan

Rev

Rev 451 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
58 naveen 1
/**
2
 * 
3
 */
4
package in.shop2020.util;
5
 
344 rajveer 6
import java.util.Properties;
7
 
58 naveen 8
import org.python.util.PythonInterpreter;
9
 
10
/**
70 naveen 11
 * Wrapper around work done by Jython scripts
12
 * 
58 naveen 13
 * @author naveen
14
 *
15
 */
16
public class JythonWrapper {
17
 
344 rajveer 18
	static{
19
		Properties preProps = System.getProperties();
20
		Properties postProps = new Properties();
21
		//props.setProperty("python.home","PYTHONPATH");  
451 rajveer 22
		postProps.setProperty("python.path",Utils.JYTHON_SRC_PATH+"/comparisonrules:"+Utils.JYTHON_SRC_PATH+"/irdatarules:"+Utils.JYTHON_SRC_PATH+"/irmetadatarules:"+Utils.JYTHON_SRC_PATH+"/common:"+Utils.JYTHON_SRC_PATH+"/normalizationrules"+":/home/rajveer/31July/PyProj/src"+":/usr/local/lib/python2.6/dist-packages"+":/usr/lib/python2.6"+":/usr/bin/python2.6"+":/usr/include/python2.6");
344 rajveer 23
		PythonInterpreter.initialize(preProps,postProps,new String[0]);
24
	}
25
 
58 naveen 26
	/**
63 naveen 27
	 * Private Python interpreter instance
58 naveen 28
	 */
70 naveen 29
	protected PythonInterpreter py = null;
30
 
58 naveen 31
 
32
	/**
70 naveen 33
	 * Initialises PythonInterpreter instance 
58 naveen 34
	 */
63 naveen 35
	public void initialize() {
36
		if(this.py == null) {
37
			this.py = new PythonInterpreter();
344 rajveer 38
 
63 naveen 39
		}
40
	}
41
 
42
	/**
70 naveen 43
	 * Resets current PythonInterpreter instance
63 naveen 44
	 */
70 naveen 45
	public void reset() {
46
		this.py = null;
63 naveen 47
	}
48
 
49
	/**
58 naveen 50
	 * Executes Jython script given absolute path
51
	 * 
52
	 * @param filename
53
	 */
54
	public void exec(String filename) {
70 naveen 55
		this.initialize();
58 naveen 56
 
57
		this.py.execfile(filename);
58
	}
59
}