1 52 53 package freemarker.ext.ant; 54 55 import java.io.*; 56 import java.util.Iterator ; 57 import java.util.Map ; 58 59 import org.apache.tools.ant.BuildException; 60 import org.python.util.PythonInterpreter; 61 62 65 public class UnlinkedJythonOperationsImpl implements UnlinkedJythonOperations { 66 67 public void execute(String script, Map vars) throws BuildException { 68 PythonInterpreter pi = createInterpreter(vars); 69 pi.exec(script); 70 } 71 72 public void execute(File file, Map vars) throws BuildException { 73 PythonInterpreter pi = createInterpreter(vars); 74 try { 75 pi.execfile(file.getCanonicalPath()); 76 } catch (IOException e) { 77 throw new BuildException(e); 78 } 79 } 80 81 private PythonInterpreter createInterpreter(Map vars) { 82 PythonInterpreter pi = new PythonInterpreter(); 83 Iterator it = vars.entrySet().iterator(); 84 while (it.hasNext()) { 85 Map.Entry ent = (Map.Entry ) it.next(); 86 pi.set((String ) ent.getKey(), ent.getValue()); 87 } 88 return pi; 89 } 90 91 } 92 | Popular Tags |