[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion PythonShell.java,1.5,1.6
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-16 15:33:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26116/src/org/python/pydev/editor/codecompletion Modified Files: PythonShell.java Log Message: Making refactoring. Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PythonShell.java 15 Sep 2004 17:36:09 -0000 1.5 --- PythonShell.java 16 Sep 2004 15:33:33 -0000 1.6 *************** *** 15,18 **** --- 15,19 ---- import org.eclipse.core.runtime.CoreException; + import org.python.pydev.editor.actions.refactoring.PyRefactorAction.Operation; import org.python.pydev.plugin.SocketUtil; *************** *** 34,38 **** * */ ! public static PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); --- 35,39 ---- * */ ! public synchronized static PythonShell getServerShell() throws IOException, CoreException { if(pytonShell == null){ pytonShell = new PythonShell(); *************** *** 121,127 **** * can talk with the server. * * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt() throws IOException{ try { --- 122,129 ---- * can talk with the server. * + * @param milisSleep: time to wait after creating the process. * @throws IOException is some error happens creating the sockets - the process is terminated. */ ! public void startIt(int milisSleep) throws IOException{ try { *************** *** 137,141 **** while(!connected && attempts < 20){ attempts += 1; ! sleepALittle(); try { socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port --- 139,143 ---- while(!connected && attempts < 20){ attempts += 1; ! sleepALittle(milisSleep); try { socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port *************** *** 144,148 **** connected = true; } catch (IOException e1) { ! e1.printStackTrace(); } } --- 146,150 ---- connected = true; } catch (IOException e1) { ! //e1.printStackTrace(); } } *************** *** 153,167 **** } process = null; ! e.printStackTrace(); throw e; } } /** ! * @return s string with the contents read. * @throws IOException */ ! public String read() throws IOException { String str = ""; --- 155,187 ---- } process = null; ! //e.printStackTrace(); throw e; } } + + /** + * This method creates the python server process and starts the sockets, so that we + * can talk with the server. + * + * @throws IOException is some error happens creating the sockets - the process is terminated. + */ + public void startIt() throws IOException{ + this.startIt(25); + } + private void communicateWork(String desc, Operation operation){ + if(operation != null){ + operation.monitor.setTaskName(desc); + operation.monitor.worked(1); + } + } + /** ! * @param operation ! * @return * @throws IOException */ ! public String read(Operation operation) throws IOException { String str = ""; *************** *** 170,192 **** byte[] b = new byte[PythonShell.BUFFER_SIZE]; - // System.out.println("WILL READ"); this.socketToRead.getInputStream().read(b); - // System.out.println("READ"); String s = new String(b); if(s.indexOf("@@PROCESSING_END@@") != -1){ //each time we get a processing message, reset j to 0. s = s.replaceAll("@@PROCESSING_END@@", ""); j = 0; ! // System.out.println("Processing msg received."); } s = s.replaceAll((char)0+"",""); //python sends this char as payload. - System.out.println("RECEIVED:"+s); str += s; if(str.indexOf("END@@") != -1){ - // System.out.println("WILL BREAK"); break; }else{ - // System.out.println("WILL SLEEP"); j++; sleepALittle(10); --- 190,223 ---- byte[] b = new byte[PythonShell.BUFFER_SIZE]; this.socketToRead.getInputStream().read(b); String s = new String(b); + if(s.indexOf("@@PROCESSING_END@@") != -1){ //each time we get a processing message, reset j to 0. s = s.replaceAll("@@PROCESSING_END@@", ""); j = 0; ! communicateWork("Processing...", operation); ! } ! ! ! if(s.indexOf("@@PROCESSING:") != -1){ //each time we get a processing message, reset j to 0. ! s = s.replaceAll("@@PROCESSING:", ""); ! s = s.replaceAll("END@@", ""); ! j = 0; ! if(s.trim().equals("") == false){ ! communicateWork("Processing: "+s, operation); ! }else{ ! communicateWork("Processing...", operation); ! } ! s = ""; } + + s = s.replaceAll((char)0+"",""); //python sends this char as payload. str += s; if(str.indexOf("END@@") != -1){ break; }else{ j++; sleepALittle(10); *************** *** 194,211 **** } - // System.out.println("OUT"); //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ - try { return str.substring(0, str.lastIndexOf("END@@")); } catch (RuntimeException e) { ! System.out.println("ERROR WIT STRING:"+str); e.printStackTrace(); return ""; } } --- 225,249 ---- } //remove @@COMPLETIONS str = str.replaceFirst("@@COMPLETIONS",""); //remove END@@ try { return str.substring(0, str.lastIndexOf("END@@")); } catch (RuntimeException e) { ! System.out.println("ERROR WITH STRING:"+str); e.printStackTrace(); return ""; } } + + + /** + * @return s string with the contents read. + * @throws IOException + */ + public String read() throws IOException { + return read(null); + } *************** *** 393,395 **** --- 431,434 ---- + } \ No newline at end of file |