From 60d3e5868865aabcb1334850f46a43cf85840fea Mon Sep 17 00:00:00 2001 From: bjschuma Date: Fri, 18 Dec 2009 15:18:49 -0500 Subject: [PATCH] Settings stores each value as a stack, began command line plugin --- src/base/loader.py | 2 +- src/base/manager.py | 8 ++++++++ src/base/scion.py | 42 +++++++++++++++++++++++++++++++++++++++++ src/base/settings.py | 22 ++++++++++++++-------- src/core/cli.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/core/example.py | 5 +++-- 6 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 src/base/scion.py create mode 100644 src/core/cli.py diff --git a/src/base/loader.py b/src/base/loader.py index b0c3c66a..56f41367 100644 --- a/src/base/loader.py +++ b/src/base/loader.py @@ -40,7 +40,7 @@ class PluginLoader: # Check for things we should not import if split[0]=="__init__": continue - elif split[1]=="pyc": + elif len(split)>1 and 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 129f458c..d171b79a 100644 --- a/src/base/manager.py +++ b/src/base/manager.py @@ -70,5 +70,13 @@ class Manager: self.enablePlugin(name) + # Disable all plugins + def shutdown(self): + write("Shutting down manager, disabling all active plugins", True) + keys = self.enabled.keys() + for plugin in keys: + self.disablePlugin(plugin) + + global manager manager = Manager() \ No newline at end of file diff --git a/src/base/scion.py b/src/base/scion.py new file mode 100644 index 00000000..e7526d68 --- /dev/null +++ b/src/base/scion.py @@ -0,0 +1,42 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Dec 4, 2009 3:37:21 PM$" + +global name +name = "scion" + +# We need to import settings before we can use disp() +import settings + +# The first thing we do is import write() so we can occasionally print messages +from bt.message import write +write("Welcome to " + name) + +# Next, we set the process name to ocarina2 +from bt.proc import setname +setname(name) + +# Import the plugin loader class! +import loader +import manager + + +def loadPluginPath(path): + loader.load.loaddir(path) + manager.manager.addPlugins(loader.load.getPlugins()) + + +# Begin our main loop +def main(): + for path in settings.get("PLUGPATH",True): + loadPluginPath(path) + + #raw_input("Input something: ") + #manager.manager.reloadPlugin("example") + manager.manager.shutdown() + + + +if __name__ == "__main__":main() diff --git a/src/base/settings.py b/src/base/settings.py index f9ccaf9e..9179945f 100644 --- a/src/base/settings.py +++ b/src/base/settings.py @@ -17,7 +17,10 @@ settings = dict() # Set key to value # This must be defined before other imports so bt.message can use it def set(key,value): - settings[key.upper()] = value + stack = [value] + if settings.has_key(key.upper()) == True: + stack += settings[key.upper()] + settings[key.upper()] = stack from bt.message import write @@ -27,8 +30,11 @@ from bt.file import fopen # Return the value at key -def get(key): - return settings[key.upper()] +def get(key, all=False): + if(all == False): + return settings[key.upper()][0] + else: + return settings[key.upper()] # Read settings from file @@ -55,18 +61,18 @@ def parseInput(): # Set default values # Set verbose first so we can use write() -settings["VERBOSE"] = ('-v' in sys.argv) or ("--verbose" in sys.argv) +set("VERBOSE", ('-v' in sys.argv) or ("--verbose" in sys.argv) ) write("Setting default values...", True) # Find who is running the program user = os.path.expanduser("~") user = os.path.join(user,".ocarina2") -settings["USER"] = user -settings["PLUGPATH"] = ["../core"] +set("USER", user) +set("PLUGPATH", "../core") # Find out what platform we are running on -settings["ARCH"] = sys.platform +set("ARCH", sys.platform) -if settings["ARCH"] == 'linux2': +if get("ARCH") == 'linux2': readfile("/etc/ocarina.conf") parseInput() \ No newline at end of file diff --git a/src/core/cli.py b/src/core/cli.py new file mode 100644 index 00000000..86506978 --- /dev/null +++ b/src/core/cli.py @@ -0,0 +1,45 @@ +#! /usr/bin/python + +__author__="bjschuma" +__date__ ="$Dec 18, 2009 12:08:57 AM$" + + +global name, app, type, path, opt +name = "cli" +app = "scion" +type = "core" +path = "" +opt = [] + +import curses +from bt.message import write + + +global maxxy, input, stdscr +input = "" + + +# Called every time the plugin is enabled +def open(): + write("Starting CLI", True) + global maxxy, input, stdscr + stdscr = curses.initscr() + maxxy = stdscr.getmaxyx() + curses.cbreak() + curses.noecho() + stdscr.keypad(1) + + +# Called every time the plugin is stopped +def close(): + global stdscr + curses.nocbreak() + curses.echo() + stdscr.keypad(0) + curses.endwin() + write("CLI has been stopped", True) + + +# Called when the plugin needs to perform some action +def run(): + pass diff --git a/src/core/example.py b/src/core/example.py index 80ca8e74..17a2915b 100644 --- a/src/core/example.py +++ b/src/core/example.py @@ -4,8 +4,9 @@ __author__="bjschuma" __date__ ="$Dec 7, 2009 9:12:00 AM$" -global name, type, path, opt +global name, app, type, path, opt name = "test" +app = "scion" type = "core" path = "" opt = [] @@ -21,7 +22,7 @@ def open(): # Called every time the plugin is stopped def close(): - write("Example plugin has been stopped") + write("Example plugin has been stopped",True) pass