mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
Removed jython script framework
This commit is contained in:
@@ -1,72 +0,0 @@
|
|||||||
package org.parabot.core.lib.jython;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.parabot.core.Core;
|
|
||||||
import org.parabot.core.Directories;
|
|
||||||
import org.parabot.core.build.BuildPath;
|
|
||||||
import org.parabot.core.lib.Library;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Jython util class
|
|
||||||
*
|
|
||||||
* @author Everel
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Jython extends Library {
|
|
||||||
private static boolean valid;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
if (!hasJar()) {
|
|
||||||
System.err.println("Failed to load jython... [jar missing]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Core.verbose("Adding jyton jar file to build path: "
|
|
||||||
+ getJarFileURL().getPath());
|
|
||||||
BuildPath.add(getJarFileURL());
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("org.python.Version");
|
|
||||||
valid = true;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
System.err
|
|
||||||
.println("Failed to add jython to build path, or incorrupt download");
|
|
||||||
}
|
|
||||||
|
|
||||||
Core.verbose("Jython initialized.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAdded() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getJarFile() {
|
|
||||||
return new File(Directories.getCachePath(), "jython.jar");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URL getDownloadLink() {
|
|
||||||
try {
|
|
||||||
return new URL("http://bot.parabot.org/libs/jython.jar");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLibraryName() {
|
|
||||||
return "Jython";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isValid() {
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package org.parabot.core.parsers.scripts;
|
|
||||||
|
|
||||||
import org.parabot.core.Directories;
|
|
||||||
import org.parabot.core.desc.ScriptDescription;
|
|
||||||
import org.parabot.environment.scripts.Category;
|
|
||||||
import org.parabot.environment.scripts.LocalScriptExecuter;
|
|
||||||
import org.parabot.environment.scripts.framework.PythonScript;
|
|
||||||
import org.python.core.PyObject;
|
|
||||||
import org.python.util.PythonInterpreter;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses python scripts
|
|
||||||
*
|
|
||||||
* @author Everel
|
|
||||||
*/
|
|
||||||
public class LocalPythonScripts extends ScriptParser {
|
|
||||||
private static final FilenameFilter PYTHON_SCRIPT_FILTER = new FilenameFilter() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith(".py");
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private PythonInterpreter interpreter;
|
|
||||||
|
|
||||||
public LocalPythonScripts() {
|
|
||||||
this.interpreter = new PythonInterpreter();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name - local var name
|
|
||||||
* @return script instance
|
|
||||||
*/
|
|
||||||
public PythonScript getScript(String name) {
|
|
||||||
PyObject clazz = interpreter.get(name);
|
|
||||||
if (clazz.toString().startsWith("<class '__main__.")) {
|
|
||||||
final PyObject instanceClass = clazz.__call__();
|
|
||||||
final Object javaInstance = instanceClass
|
|
||||||
.__tojava__(PythonScript.class);
|
|
||||||
if (javaInstance instanceof PythonScript) {
|
|
||||||
return (PythonScript) javaInstance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
for (final File scriptFile : Directories.getScriptSourcesPath()
|
|
||||||
.listFiles(PYTHON_SCRIPT_FILTER)) {
|
|
||||||
try {
|
|
||||||
interpreter.execfile(new FileInputStream(scriptFile));
|
|
||||||
final String name = interpreter.get("__scriptname__")
|
|
||||||
.asString();
|
|
||||||
final String author = interpreter.get("__author__").asString();
|
|
||||||
final Category cat = (Category) interpreter.get("__category__")
|
|
||||||
.__tojava__(Category.class);
|
|
||||||
final double version = interpreter.get("__version__")
|
|
||||||
.asDouble();
|
|
||||||
final String description = interpreter.get("__description__")
|
|
||||||
.asString();
|
|
||||||
final String[] servers = (String[]) interpreter.get(
|
|
||||||
"__servers__").__tojava__(String[].class);
|
|
||||||
|
|
||||||
Object ob;
|
|
||||||
|
|
||||||
String vip = "no";
|
|
||||||
if ((ob = interpreter.get("__vip__")) != null) {
|
|
||||||
final String isVip = ob.toString();
|
|
||||||
vip = isVip.equals("True") ? "yes" : "no";
|
|
||||||
}
|
|
||||||
|
|
||||||
String prem = "no";
|
|
||||||
if ((ob = interpreter.get("__premium__")) != null) {
|
|
||||||
final String isPrem = ob.toString();
|
|
||||||
prem = isPrem.equals("True") ? "yes" : "no";
|
|
||||||
}
|
|
||||||
|
|
||||||
final ScriptDescription desc = new ScriptDescription(name,
|
|
||||||
author, cat.toString(), version, description, servers, vip, prem);
|
|
||||||
for (final PyObject o : interpreter.getLocals().asIterable()) {
|
|
||||||
PythonScript script = getScript(o.asString());
|
|
||||||
if (script != null) {
|
|
||||||
SCRIPT_CACHE.put(desc, new LocalScriptExecuter(script));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interpreter.cleanup();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.desc.ScriptDescription;
|
import org.parabot.core.desc.ScriptDescription;
|
||||||
import org.parabot.core.lib.jython.Jython;
|
|
||||||
import org.parabot.environment.scripts.ScriptExecuter;
|
import org.parabot.environment.scripts.ScriptExecuter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,15 +25,9 @@ public abstract class ScriptParser {
|
|||||||
final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>();
|
final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>();
|
||||||
if (Core.inLoadLocal()) {
|
if (Core.inLoadLocal()) {
|
||||||
parsers.add(new LocalJavaScripts());
|
parsers.add(new LocalJavaScripts());
|
||||||
if (Jython.isValid()) {
|
|
||||||
parsers.add(new LocalPythonScripts());
|
|
||||||
}
|
|
||||||
parsers.add(new SDNScripts());
|
parsers.add(new SDNScripts());
|
||||||
} else if (Core.inDebugMode()) {
|
} else if (Core.inDebugMode()) {
|
||||||
parsers.add(new LocalJavaScripts());
|
parsers.add(new LocalJavaScripts());
|
||||||
if (Jython.isValid()) {
|
|
||||||
parsers.add(new LocalPythonScripts());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
parsers.add(new SDNScripts());
|
parsers.add(new SDNScripts());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.parabot.core.Core;
|
|||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
import org.parabot.core.lib.Library;
|
import org.parabot.core.lib.Library;
|
||||||
import org.parabot.core.lib.javafx.JavaFX;
|
import org.parabot.core.lib.javafx.JavaFX;
|
||||||
import org.parabot.core.lib.jython.Jython;
|
|
||||||
import org.parabot.core.parsers.servers.ServerParser;
|
import org.parabot.core.parsers.servers.ServerParser;
|
||||||
import org.parabot.core.ui.components.VerboseLoader;
|
import org.parabot.core.ui.components.VerboseLoader;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
@@ -29,7 +28,6 @@ public class Environment {
|
|||||||
public static void load(final ServerDescription desc) {
|
public static void load(final ServerDescription desc) {
|
||||||
|
|
||||||
LinkedList<Library> libs = new LinkedList<Library>();
|
LinkedList<Library> libs = new LinkedList<Library>();
|
||||||
libs.add(new Jython());
|
|
||||||
libs.add(new JavaFX());
|
libs.add(new JavaFX());
|
||||||
|
|
||||||
for(Library lib : libs) {
|
for(Library lib : libs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user