diff --git a/src/base/bt/__init__.py b/src/base/bt/__init__.py index fbe1ed4c..e86af2ef 100644 --- a/src/base/bt/__init__.py +++ b/src/base/bt/__init__.py @@ -1,4 +1,4 @@ # This is the base tools package # It contains various tools needed by the base layer of ocarina2 -__all__ = ["proc", "message"] \ No newline at end of file +__all__ = ["file", "proc", "message", "needle"] \ No newline at end of file diff --git a/src/base/bt/needle.py b/src/base/bt/needle.py index 58e6338d..66d486f2 100644 --- a/src/base/bt/needle.py +++ b/src/base/bt/needle.py @@ -11,10 +11,14 @@ from threading import Thread class Needle(Thread): - def __init__(self, func, args): + def __init__(self, func, args=None): + Thread.__init__(self) self.func = func self.args = args def run(self): - func(args) \ No newline at end of file + if self.args==None: + self.func() + else: + self.func(self.args) \ No newline at end of file diff --git a/src/base/loader.py b/src/base/loader.py index 56f41367..4c894b21 100644 --- a/src/base/loader.py +++ b/src/base/loader.py @@ -40,7 +40,9 @@ class PluginLoader: # Check for things we should not import if split[0]=="__init__": continue - elif len(split)>1 and split[1]=="pyc": + elif len(split)==1: + continue + elif split[1]=="pyc": continue # Load the module into our module array write("Attempting to load "+mod, True) diff --git a/src/base/manager.py b/src/base/manager.py index d171b79a..2192f2bf 100644 --- a/src/base/manager.py +++ b/src/base/manager.py @@ -4,7 +4,7 @@ __author__="bjschuma" __date__ ="$Dec 8, 2009 8:40:36 AM$" import sys -from bt.message import write +from bt.message import * import loader class Manager: @@ -21,8 +21,11 @@ class Manager: write("Adding plugin: " + str(plugin), True) self.disabled[plugin.name] = plugin # If we are adding a core plugin, activate it right away - if(plugin.type=="core"): - self.enablePlugin(plugin.name) + try: + if plugin.type=="core": + self.enablePlugin(plugin.name) + except: + error("Error adding plugin: "+plugin.name) # Move plugin from old[name] to new[name] @@ -37,7 +40,7 @@ class Manager: # Returns true if there was a plugin to disable, false otherwise def disablePlugin(self,name): if (name in self.enabled) == True: - write("Disabling plugin: "+name) + write("Disabling plugin: "+name, True) plugin = self.movePlugin(name, self.enabled, self.disabled) plugin.close() return True @@ -47,13 +50,14 @@ class Manager: # Move a plugin to the enabled list # Returns true if a plugin was enabled, false otherwise def enablePlugin(self,name): - #index = self.findPlugin(name, self.disabled) - #if index > -1: if (name in self.disabled) == True: - write("Enabling plugin: "+name,True) - plugin = self.movePlugin(name, self.disabled, self.enabled) - plugin.open() - return True + try: + write("Enabling plugin: "+name,True) + plugin = self.movePlugin(name, self.disabled, self.enabled) + plugin.open() + return True + except: + error("Error enabling: "+name) return False diff --git a/src/base/scion.py b/src/base/scion.py index e7526d68..e168f1bb 100644 --- a/src/base/scion.py +++ b/src/base/scion.py @@ -35,7 +35,7 @@ def main(): #raw_input("Input something: ") #manager.manager.reloadPlugin("example") - manager.manager.shutdown() + #manager.manager.shutdown() diff --git a/src/core/cli.py b/src/core/cli.py index 7860c636..2b9f8173 100644 --- a/src/core/cli.py +++ b/src/core/cli.py @@ -12,32 +12,48 @@ path = "" opt = [] import curses -from bt.message import write -from bt.needle import Needle +from bt.message import * +#from bt.needle import Needle +import bt.needle +import cline.loop +import settings -global maxxy, input, stdscr -input = "" +global maxxy, stdscr, thread +threads = [] # Called every time the plugin is enabled def open(): write("Starting CLI", True) - global maxxy, input, stdscr + global maxxy, stdscr, thread + # Initialize ncurses screen stdscr = curses.initscr() maxxy = stdscr.getmaxyx() curses.cbreak() curses.noecho() stdscr.keypad(1) + # Set these values in settings class for use elsewhere + settings.set("stdscr", stdscr) + settings.set("maxxy", maxxy) + + # Start loop in new thread + thread = bt.needle.Needle(cline.loop.loop) + thread.start() + # Called every time the plugin is stopped def close(): - global stdscr + global stdscr, thread + # Undo ncurses initialization curses.nocbreak() curses.echo() stdscr.keypad(0) curses.endwin() + # Stop looping + cline.loop.quit() + #thread.join() write("CLI has been stopped", True) diff --git a/src/core/cline/__init__.py b/src/core/cline/__init__.py index 43d04fb6..63228c41 100644 --- a/src/core/cline/__init__.py +++ b/src/core/cline/__init__.py @@ -1,2 +1,5 @@ __author__="bjschuma" -__date__ ="$Dec 19, 2009 9:13:05 PM$" \ No newline at end of file +__date__ ="$Dec 19, 2009 9:13:05 PM$" + + +__all__ = ["loop"] \ No newline at end of file diff --git a/src/core/cline/loop.py b/src/core/cline/loop.py new file mode 100644 index 00000000..485a3b28 --- /dev/null +++ b/src/core/cline/loop.py @@ -0,0 +1,41 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Dec 19, 2009 9:39:37 PM$" + +import curses + +from bt.message import write +import manager +import settings + + +global halt +halt = False + +def loop(): + write("Beginning command line loop",True) + global halt + + stdscr = settings.get("stdscr") + input = "" + + while halt == False: + c = stdscr.getch() + + if(c >= 32 and c<= 126): + input += curses.keyname(c) + #input=input[:x-4]+curses.keyname(c)+input[x-4:] + #self.changeLine(y) + #self.stdscr.move(y,x+1) + if input == "exit": + manager.manager.shutdown() + halt = True + + +def quit(): + global halt + halt = True \ No newline at end of file diff --git a/src/core/example.py b/src/core/example.py index 17a2915b..443e2749 100644 --- a/src/core/example.py +++ b/src/core/example.py @@ -23,7 +23,6 @@ def open(): # Called every time the plugin is stopped def close(): write("Example plugin has been stopped",True) - pass # Called when the plugin needs to perform some action