|
From: <Ar...@us...> - 2009-09-20 16:43:24
|
Revision: 4483
http://phex.svn.sourceforge.net/phex/?rev=4483&view=rev
Author: ArneBab
Date: 2009-09-20 16:43:17 +0000 (Sun, 20 Sep 2009)
Log Message:
-----------
Added a basic jython interpreter as commandline interface. You can get it by using the commandline argument --console.
Modified Paths:
--------------
phex/trunk/pom.xml
phex/trunk/src/main/java/phex/Main.java
phex/trunk/src/main/resources/META-INF/MANIFEST.MF
Added Paths:
-----------
phex/trunk/src/main/java/phex/utils/JythonInterpreter.java
Modified: phex/trunk/pom.xml
===================================================================
--- phex/trunk/pom.xml 2009-09-20 16:23:36 UTC (rev 4482)
+++ phex/trunk/pom.xml 2009-09-20 16:43:17 UTC (rev 4483)
@@ -36,6 +36,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.python</groupId>
+ <artifactId>jython</artifactId>
+ <version>2.5.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>com.jgoodies</groupId>
<artifactId>forms</artifactId>
<version>1.2.1</version>
@@ -502,4 +508,4 @@
<url>scp://web.sourceforge.net/home/groups/p/ph/phex/htdocs/mavenrepository</url>
</repository>
</distributionManagement>
-</project>
\ No newline at end of file
+</project>
Modified: phex/trunk/src/main/java/phex/Main.java
===================================================================
--- phex/trunk/src/main/java/phex/Main.java 2009-09-20 16:23:36 UTC (rev 4482)
+++ phex/trunk/src/main/java/phex/Main.java 2009-09-20 16:43:17 UTC (rev 4483)
@@ -49,7 +49,9 @@
import phex.utils.Localizer;
import phex.utils.SystemProperties;
+import phex.utils.JythonInterpreter;
+
public class Main
{
private static SplashScreen splashScreen;
@@ -80,6 +82,7 @@
String magmaFile = null;
String rssFile = null;
String argument;
+ Boolean startConsole = false;
while ( (argument = readArgument( iterator ) ) != null )
{
@@ -104,6 +107,10 @@
{
rssFile = readArgument(iterator);
}
+ else if (argument.equalsIgnoreCase("--console"))
+ {
+ startConsole = true;
+ }
}
LogUtils.initializeLogging();
@@ -193,6 +200,18 @@
// unhandled application exception... exit
System.exit( 1 );
}
+
+ /**
+ * Trying to use a jython interpreter as powerful command line interface.
+ * This blocks, so it has to be at the end.
+ */
+ if (startConsole)
+ {
+ JythonInterpreter jython;
+ jython = new JythonInterpreter();
+ jython.startConsole();
+ }
+
}
private static void showSplash( )
Added: phex/trunk/src/main/java/phex/utils/JythonInterpreter.java
===================================================================
--- phex/trunk/src/main/java/phex/utils/JythonInterpreter.java (rev 0)
+++ phex/trunk/src/main/java/phex/utils/JythonInterpreter.java 2009-09-20 16:43:17 UTC (rev 4483)
@@ -0,0 +1,41 @@
+// Embedding a jython interpreter.
+
+package phex.utils;
+
+import org.python.util.InteractiveConsole;
+import java.util.Properties;
+import java.io.*;
+
+public class JythonInterpreter {
+ protected InteractiveConsole interp;
+
+ public JythonInterpreter() {
+ if (System.getProperty("python.home") == null) {
+ System.setProperty("python.home", "");
+ }
+ InteractiveConsole.initialize(System.getProperties(),
+ null, new String[0]);
+ interp = new InteractiveConsole();
+ }
+
+ public static void main(String[] args) {
+ JythonInterpreter con = new JythonInterpreter();
+ con.startConsole();
+ }
+
+ public void startConsole() {
+ // System.out.println("Hello");
+ // offer a servent object for controlling Phex
+ interp.push("from phex.servent import Servent");
+ interp.push("servent = Servent.getInstance()");
+ // get a way to shut down
+ interp.push("from phex.net.server import OIOServer");
+ interp.push("server = OIOServer( servent )");
+ // interp.push("from phex.gui.actions import ExitPhexAction");
+ // interp.push("ex = ExitPhexAction()");
+ // interp.push("shutdown = ex.shutdown")
+ // interp.push("shutdown = server.shutdown");
+ // Now start the interactive console
+ interp.interact("Hello from console. Call dir() for available commands.", null);
+ }
+}
Modified: phex/trunk/src/main/resources/META-INF/MANIFEST.MF
===================================================================
--- phex/trunk/src/main/resources/META-INF/MANIFEST.MF 2009-09-20 16:23:36 UTC (rev 4482)
+++ phex/trunk/src/main/resources/META-INF/MANIFEST.MF 2009-09-20 16:43:17 UTC (rev 4483)
@@ -4,5 +4,5 @@
Class-Path: ../lang/ ../ext/ commons-collections-3.2.jar commons-httpclient-3.0.1.jar
forms-1.2.1.jar looks-2.2.1.jar mrjadapter-1.1.jar logback-classic-0.9.14.jar
logback-core-0.9.14.jar slf4j-api-1.5.6.jar jcl-over-slf4j-1.5.6.jar xSocket-2.4.1.jar
- bcprov-jdk15-140.jar bcpg-jdk15-140.jar
+ bcprov-jdk15-140.jar bcpg-jdk15-140.jar jython-2.5.0.jar
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|