Turned plugins into inherited classes, began rewriting them
This commit is contained in:
parent
77cb4f6b27
commit
9c86ab0ba3
|
@ -1,4 +1,4 @@
|
|||
# This is the base tools package
|
||||
# It contains various tools needed by the base layer of ocarina2
|
||||
|
||||
__all__ = ["file", "map", "message", "needle", "proc", "signal", "xm"]
|
||||
__all__ = ["file", "map", "message", "needle", "plugin", "proc", "signal", "xm"]
|
|
@ -0,0 +1,55 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 20, 2010 6:38:42 PM$"
|
||||
|
||||
from message import write
|
||||
import inspect
|
||||
import os
|
||||
|
||||
|
||||
|
||||
class Plugin:
|
||||
def __init__(self):
|
||||
self.name = "plugin"
|
||||
self.help = "No help message available"
|
||||
self.type = "core"
|
||||
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
|
||||
def gethelp(self):
|
||||
return self.help
|
||||
|
||||
|
||||
def start(self,args=None):
|
||||
try:
|
||||
return self.run(args)
|
||||
except:
|
||||
trace = inspect.trace()
|
||||
frame = trace[len(trace)-1]
|
||||
|
||||
filename = frame[1]
|
||||
lineno = str(frame[2])
|
||||
|
||||
|
||||
#filename = frame[1]
|
||||
#lineno = str(inspect.currentframe().f_back.f_lineno)
|
||||
#filename = inspect.currentframe().f_forward.f_code.co_filename
|
||||
filename = filename.rsplit(os.sep,1)[1]
|
||||
write(filename+" ("+lineno+")")
|
||||
#print e
|
||||
|
||||
|
||||
|
||||
def run(self,args=None):
|
||||
return None
|
|
@ -46,19 +46,19 @@ class PluginLoader:
|
|||
continue
|
||||
# Load the module into our module array
|
||||
write("Attempting to load "+mod, True)
|
||||
try:
|
||||
self.loadmod(split[0], os.path.join(dir,mod))
|
||||
except:
|
||||
error("Error loading "+mod)
|
||||
#try:
|
||||
self.loadmod(split[0], os.path.join(dir,mod))
|
||||
#except:
|
||||
# error("Error loading "+mod)
|
||||
|
||||
|
||||
# Call with a module name to import and path to plugin
|
||||
# Adds the imported module to a list
|
||||
def loadmod(self,mod,path):
|
||||
__import__(mod)
|
||||
plugin = sys.modules[mod]
|
||||
plugin = sys.modules[mod].Plugin()
|
||||
plugin.name = mod
|
||||
plugin.path = path
|
||||
#plugin.path = path
|
||||
self.plugins += [plugin]
|
||||
|
||||
|
||||
|
|
|
@ -65,9 +65,17 @@ class Manager:
|
|||
if (name in sys.modules) == False:
|
||||
write("Plugin not loaded: "+name, True)
|
||||
return
|
||||
# Disable the plugin and pop from sys.modules
|
||||
## Disable the plugin and pop from sys.modules
|
||||
reenable = self.disablePlugin(name)
|
||||
reload(self.disabled[name])
|
||||
for index,p in self.disabled:
|
||||
if p.name==name:
|
||||
break
|
||||
self.disabled.pop(index)
|
||||
|
||||
#reload(self.disabled[name])
|
||||
reload(sys.modules[name])
|
||||
p = sys.modules[name].Plugin()
|
||||
self.disabled+=[p]
|
||||
if reenable == True:
|
||||
self.enablePlugin(name)
|
||||
|
||||
|
@ -103,7 +111,7 @@ class Manager:
|
|||
name = name.strip()
|
||||
if (name in self.enabled)==True:
|
||||
try:
|
||||
return self.enabled[name].run(args)
|
||||
return self.enabled[name].start(args)
|
||||
except:
|
||||
error("Plugin "+name+" has caused an error. Disabling.")
|
||||
self.disablePlugin(name)
|
||||
|
|
|
@ -12,14 +12,9 @@ import getopt
|
|||
global settings
|
||||
settings = dict()
|
||||
|
||||
#from bt.map import Map
|
||||
#global settings
|
||||
#settings = Map()
|
||||
|
||||
|
||||
# Return true if settings contains key
|
||||
def has(key):
|
||||
#return settings.has(key)
|
||||
return (key.upper() in settings.keys())
|
||||
|
||||
|
||||
|
@ -28,15 +23,6 @@ def has(key):
|
|||
def set(key,value):
|
||||
key = key.upper()
|
||||
settings[key] = value
|
||||
#return settings.set(key,value,end)
|
||||
#stack = [value]
|
||||
#key = key.upper()
|
||||
#if has(key) == True:
|
||||
# if end == False:
|
||||
# stack += settings[key]
|
||||
# else:
|
||||
# stack = settings[key] + stack
|
||||
#settings[key.upper()] = stack
|
||||
|
||||
|
||||
from bt.message import write
|
||||
|
@ -50,51 +36,14 @@ from bt import xm
|
|||
def get(key):
|
||||
key = key.upper()
|
||||
return settings[key]
|
||||
#return settings.get(key,all)
|
||||
#key = key.upper()
|
||||
#global settings
|
||||
#if has(key)==False:
|
||||
# return None
|
||||
#if(all == False):
|
||||
# return settings[key][0]
|
||||
#else:
|
||||
# return settings[key]
|
||||
|
||||
|
||||
# Set key to value only if it is not set yet
|
||||
#def init(key,value):
|
||||
# if settings.has(key) == False:
|
||||
# settings.set(key,value)
|
||||
|
||||
|
||||
# Replace settings[key] with value
|
||||
#def replace(key,value):
|
||||
# global settings
|
||||
# key = key.upper()
|
||||
# if (key in settings) == True:
|
||||
# del settings[key]
|
||||
# set(key,value)
|
||||
|
||||
|
||||
def delete(key):
|
||||
key = key.upper()
|
||||
#global settings
|
||||
if has(key) == True:
|
||||
del settings[key]
|
||||
|
||||
|
||||
# Pop off the first value at key.upper()
|
||||
#def pop(key):
|
||||
# key = key.upper()
|
||||
# global settings
|
||||
# if (key in settings.keys()) == True:
|
||||
# item = settings[key].pop(0)
|
||||
# if len(settings[key]) == 0:
|
||||
# delete(key)
|
||||
# return item
|
||||
# return None
|
||||
|
||||
|
||||
# Read settings from file
|
||||
def readfile(file):
|
||||
write("Reading file: "+file,True)
|
||||
|
@ -125,12 +74,9 @@ def clean():
|
|||
delete("appname")
|
||||
delete("arch")
|
||||
delete("args")
|
||||
delete("loop")
|
||||
delete("loopquit")
|
||||
delete("plugpath")
|
||||
delete("user")
|
||||
delete("verbose")
|
||||
delete("write")
|
||||
|
||||
|
||||
def save(path):
|
||||
|
@ -176,9 +122,8 @@ write("Setting default values...", True)
|
|||
|
||||
# Find who is running the program
|
||||
user = os.path.expanduser("~")
|
||||
#user = os.path.join(user,".ocarina2")
|
||||
set("USER", user)
|
||||
set("PLUGPATH", ["../core", "../extra"])
|
||||
set("PLUGPATH", ["../core" ]) #, "../extra"])
|
||||
|
||||
# Find out what platform we are running on
|
||||
set("ARCH", sys.platform)
|
||||
|
|
|
@ -1,56 +1,42 @@
|
|||
#! /usr/bin/python
|
||||
# This is a simple test plugin, to make sure everything is working
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 18, 2009 12:08:57 AM$"
|
||||
__date__ ="$Jan 20, 2010 7:37:39 PM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "cli"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
from bt import plugin
|
||||
#from bt.needle import Needle
|
||||
from bt.signal import *
|
||||
from bt.message import *
|
||||
|
||||
import cline.loop
|
||||
import cline.addch
|
||||
import cline.message
|
||||
#import settings
|
||||
from bt.needle import Needle
|
||||
from bt.signal import *
|
||||
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
write("Starting CLI", True)
|
||||
|
||||
# Tell settings to run this loop
|
||||
#settings.set("loop",cline.loop.loop)
|
||||
#settings.set("loopquit",cline.loop.quit)
|
||||
register("run", cline.loop.loop)
|
||||
register("quit", cline.loop.quit)
|
||||
|
||||
# Initialize a dictionary for key press inputs
|
||||
settings.set("keyinput", dict())
|
||||
settings.get("keyinput")[127] = cline.addch.backspace
|
||||
settings.get("keyinput")[10] = cline.addch.enter
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
self.help = "The command line interface"
|
||||
|
||||
|
||||
def open(self):
|
||||
write("Starting CLI", True)
|
||||
|
||||
# Register our run function and close function
|
||||
register("run", cline.loop.loop)
|
||||
register("quit", cline.loop.quit)
|
||||
|
||||
# Initialize a dictionary for key press inputs
|
||||
settings.set("keyinput", dict())
|
||||
settings.get("keyinput")[127] = cline.addch.backspace
|
||||
settings.get("keyinput")[10] = cline.addch.enter
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
cline.loop.quit()
|
||||
write("CLI has been stopped", True)
|
||||
settings.delete("keyinput")
|
||||
def close(self):
|
||||
cline.loop.quit()
|
||||
write("CLI has been stopped", True)
|
||||
settings.delete("keyinput")
|
||||
|
||||
|
||||
def help():
|
||||
return "This is a simple command line interface"
|
||||
|
||||
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
pass
|
||||
|
|
|
@ -1,43 +1,26 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
# This is a simple test plugin, to make sure everything is working
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 20, 2009 12:52:29 AM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "disable"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
__date__ ="$Jan 20, 2010 7:51:32 PM$"
|
||||
|
||||
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
pass
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
# Run this to prevent disable from ever being disabled
|
||||
manager.run("enable",["disable"])
|
||||
pass
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
self.help = "Used to disable plugins"
|
||||
|
||||
|
||||
def help():
|
||||
return "This plugin is used to disable plugins"
|
||||
|
||||
def run(self,args=None):
|
||||
if args == None:
|
||||
return
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
if args == None:
|
||||
return
|
||||
dont = ["disable", "enable", "exit"]
|
||||
for plugin in args:
|
||||
# Only disable if plugin is not in the "do not disable" list
|
||||
if not (plugin in dont):
|
||||
manager.disablePlugin(plugin)
|
||||
|
||||
for plugin in args:
|
||||
manager.disablePlugin(plugin)
|
||||
|
|
|
@ -1,42 +1,23 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
# This is a simple test plugin, to make sure everything is working
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 20, 2009 12:54:32 AM$"
|
||||
__date__ ="$Jan 20, 2010 7:59:07 PM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "enable"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
pass
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
# Prevent enable from ever being disabled
|
||||
manager.enablePlugin("enable")
|
||||
pass
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
self.help = "This plugin is used to reenable other plugins"
|
||||
|
||||
|
||||
def help():
|
||||
return "This plugin is used to reenable other plugins"
|
||||
def run(self, args=None):
|
||||
if args == None:
|
||||
return
|
||||
|
||||
for plugin in args:
|
||||
manager.enablePlugin(plugin)
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
if args == None:
|
||||
return
|
||||
|
||||
for plugin in args:
|
||||
manager.enablePlugin(plugin)
|
||||
|
|
|
@ -4,35 +4,19 @@
|
|||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 20, 2009 12:24:44 AM$"
|
||||
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "exit"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
__date__ ="$Jan 20, 2010 6:42:45 PM$"
|
||||
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
pass
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
self.help = "This plugin begins the shutdown routine"
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
pass
|
||||
def run(self,args=None):
|
||||
manager.shutdown()
|
||||
|
||||
|
||||
def help():
|
||||
return "This plugin will begin the proper shutdown procedure"
|
||||
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
manager.shutdown()
|
||||
|
|
|
@ -1,54 +1,39 @@
|
|||
# This is a simple test plugin, to make sure everything is working
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Jan 16, 2010 1:45:27 AM$"
|
||||
__date__ ="$Jan 20, 2010 8:01:55 PM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "help"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
from bt.message import write
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
pass
|
||||
class Plugin(plugin.Plugin):
|
||||
def __init__(self):
|
||||
plugin.Plugin.__init__(self)
|
||||
self.help = "Returns a short description of the plugin"
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
pass
|
||||
def run(self, args=None):
|
||||
if args == None:
|
||||
plugin = "help"
|
||||
else:
|
||||
plugin = args[0]
|
||||
|
||||
module = None
|
||||
if (plugin in manager.enabled.keys()) == True:
|
||||
module = manager.enabled[plugin]
|
||||
elif (plugin in manager.disabled.keys()) == True:
|
||||
module = manager.disabled[plugin]
|
||||
else:
|
||||
message = "Plugin "+plugin+" does not appear to exist."
|
||||
|
||||
def help():
|
||||
return "Returns a short description of the plugin"
|
||||
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
if args == None:
|
||||
plugin = "help"
|
||||
else:
|
||||
plugin = args[0]
|
||||
|
||||
module = None
|
||||
if (plugin in manager.enabled.keys()) == True:
|
||||
module = manager.enabled[plugin]
|
||||
elif (plugin in manager.disabled.keys()) == True:
|
||||
module = manager.disabled[plugin]
|
||||
else:
|
||||
message = "Plugin "+plugin+" does not appear to exist."
|
||||
|
||||
try:
|
||||
if not module == None:
|
||||
message = module.help()
|
||||
write(message)
|
||||
return message
|
||||
except:
|
||||
write("Plugin "+plugin+" has no help message.")
|
||||
return ""
|
||||
try:
|
||||
if not module == None:
|
||||
message = module.gethelp()
|
||||
write(message)
|
||||
return message
|
||||
except:
|
||||
write("Plugin "+plugin+" has no help message.")
|
||||
return ""
|
|
@ -1,41 +0,0 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
# To change this template, choose Tools | Templates
|
||||
# and open the template in the editor.
|
||||
|
||||
__author__="bjschuma"
|
||||
__date__ ="$Dec 20, 2009 12:30:00 AM$"
|
||||
|
||||
|
||||
global name, app, type, path, opt
|
||||
name = "reload"
|
||||
app = "scion"
|
||||
type = "core"
|
||||
path = ""
|
||||
opt = []
|
||||
|
||||
|
||||
from manager import manager
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
pass
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
pass
|
||||
|
||||
|
||||
def help():
|
||||
return "Closes and then reopens a plugin"
|
||||
|
||||
|
||||
# Called when the plugin needs to perform some action
|
||||
def run(args=None):
|
||||
if args == None:
|
||||
return
|
||||
|
||||
for plugin in args:
|
||||
manager.reloadPlugin(plugin)
|
|
@ -12,12 +12,12 @@ path = ""
|
|||
opt = []
|
||||
|
||||
from bt.message import write
|
||||
from bt import signal
|
||||
from manager import manager
|
||||
import settings
|
||||
from guiGTK import *
|
||||
import gtk
|
||||
|
||||
|
||||
global win
|
||||
global vbox
|
||||
global bar
|
||||
|
@ -60,15 +60,6 @@ def loop():
|
|||
gtk.main()
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
settings.init("guirunning",False)
|
||||
#settings.init("gtkfuncs", [])
|
||||
if settings.get("guirunning") == True:
|
||||
settings.set("loop",loop)
|
||||
pass
|
||||
|
||||
|
||||
# Called every time the plugin is stopped
|
||||
def close():
|
||||
gtk.main_quit()
|
||||
|
@ -76,6 +67,20 @@ def close():
|
|||
pass
|
||||
|
||||
|
||||
# Called every time the plugin is enabled
|
||||
def open():
|
||||
settings.set("guirunning",False)
|
||||
#settings.init("gtkfuncs", [])
|
||||
if settings.get("guirunning") == True:
|
||||
signal.register("run",loop)
|
||||
signal.register("quit",close)
|
||||
#1settings.set("loop",loop)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def help():
|
||||
return "Allows the usage of GTK"
|
||||
|
||||
|
|
Loading…
Reference in New Issue