Settings stores each value as a stack, began command line plugin
This commit is contained in:
parent
f63bc51d2e
commit
60d3e58688
|
@ -40,7 +40,7 @@ class PluginLoader:
|
||||||
# Check for things we should not import
|
# Check for things we should not import
|
||||||
if split[0]=="__init__":
|
if split[0]=="__init__":
|
||||||
continue
|
continue
|
||||||
elif split[1]=="pyc":
|
elif len(split)>1 and split[1]=="pyc":
|
||||||
continue
|
continue
|
||||||
# Load the module into our module array
|
# Load the module into our module array
|
||||||
write("Attempting to load "+mod, True)
|
write("Attempting to load "+mod, True)
|
||||||
|
|
|
@ -70,5 +70,13 @@ class Manager:
|
||||||
self.enablePlugin(name)
|
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
|
global manager
|
||||||
manager = Manager()
|
manager = Manager()
|
|
@ -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()
|
|
@ -17,7 +17,10 @@ settings = dict()
|
||||||
# Set key to value
|
# Set key to value
|
||||||
# This must be defined before other imports so bt.message can use it
|
# This must be defined before other imports so bt.message can use it
|
||||||
def set(key,value):
|
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
|
from bt.message import write
|
||||||
|
@ -27,8 +30,11 @@ from bt.file import fopen
|
||||||
|
|
||||||
|
|
||||||
# Return the value at key
|
# Return the value at key
|
||||||
def get(key):
|
def get(key, all=False):
|
||||||
return settings[key.upper()]
|
if(all == False):
|
||||||
|
return settings[key.upper()][0]
|
||||||
|
else:
|
||||||
|
return settings[key.upper()]
|
||||||
|
|
||||||
|
|
||||||
# Read settings from file
|
# Read settings from file
|
||||||
|
@ -55,18 +61,18 @@ def parseInput():
|
||||||
|
|
||||||
# Set default values
|
# Set default values
|
||||||
# Set verbose first so we can use write()
|
# 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)
|
write("Setting default values...", True)
|
||||||
# Find who is running the program
|
# Find who is running the program
|
||||||
user = os.path.expanduser("~")
|
user = os.path.expanduser("~")
|
||||||
user = os.path.join(user,".ocarina2")
|
user = os.path.join(user,".ocarina2")
|
||||||
settings["USER"] = user
|
set("USER", user)
|
||||||
settings["PLUGPATH"] = ["../core"]
|
set("PLUGPATH", "../core")
|
||||||
|
|
||||||
# Find out what platform we are running on
|
# 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")
|
readfile("/etc/ocarina.conf")
|
||||||
|
|
||||||
parseInput()
|
parseInput()
|
|
@ -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
|
|
@ -4,8 +4,9 @@ __author__="bjschuma"
|
||||||
__date__ ="$Dec 7, 2009 9:12:00 AM$"
|
__date__ ="$Dec 7, 2009 9:12:00 AM$"
|
||||||
|
|
||||||
|
|
||||||
global name, type, path, opt
|
global name, app, type, path, opt
|
||||||
name = "test"
|
name = "test"
|
||||||
|
app = "scion"
|
||||||
type = "core"
|
type = "core"
|
||||||
path = ""
|
path = ""
|
||||||
opt = []
|
opt = []
|
||||||
|
@ -21,7 +22,7 @@ def open():
|
||||||
|
|
||||||
# Called every time the plugin is stopped
|
# Called every time the plugin is stopped
|
||||||
def close():
|
def close():
|
||||||
write("Example plugin has been stopped")
|
write("Example plugin has been stopped",True)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue