Settings stores each value as a stack, began command line plugin

This commit is contained in:
bjschuma 2009-12-18 15:18:49 -05:00
parent f63bc51d2e
commit 60d3e58688
6 changed files with 113 additions and 11 deletions

View File

@ -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)

View File

@ -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()

42
src/base/scion.py Normal file
View File

@ -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()

View File

@ -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()

45
src/core/cli.py Normal file
View File

@ -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

View File

@ -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