From 6b7347464a3b683b61935d4397afcc818ea91205 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Fri, 19 Feb 2010 00:19:39 -0500 Subject: [PATCH] Continued work with reworking startup / sessions --- src/core/bt/message.py | 9 +++++---- src/core/bt/proc.py | 2 +- src/core/bt/settings.py | 23 +++++++++++++++++++++++ src/core/manager.py | 24 ++++++++++++------------ src/core/scion.py | 18 ++++++++---------- src/core/session.py | 19 +++++++++++++------ src/plugins/cli.py | 14 ++++++++------ src/plugins/cline/history.py | 4 ++-- 8 files changed, 72 insertions(+), 41 deletions(-) diff --git a/src/core/bt/message.py b/src/core/bt/message.py index d755dafc..30fa4f2b 100644 --- a/src/core/bt/message.py +++ b/src/core/bt/message.py @@ -4,8 +4,9 @@ __author__="bjschuma" __date__ ="$Dec 5, 2009 6:46:13 PM$" import os -import inspect -from session import session +#import inspect +#from session import session +import session import bt.signal global enabled @@ -27,11 +28,11 @@ def disp(text): # Print general text to the screen -def write(text,verbose=False): +def write(text,verbose=0): global enabled if enabled == False: return - if (verbose==False) or (session.settings["verbose"]==True): + if (verbose <= session.settings["verbose"]): bt.signal.emit("message-write",str(text)) diff --git a/src/core/bt/proc.py b/src/core/bt/proc.py index 755bf411..556b2d4e 100644 --- a/src/core/bt/proc.py +++ b/src/core/bt/proc.py @@ -3,7 +3,7 @@ __author__="bjschuma" __date__ ="$Dec 5, 2009 6:33:50 PM$" -from session import session +import session from message import write # Set our process name to name diff --git a/src/core/bt/settings.py b/src/core/bt/settings.py index 3d3f1798..11b9ebf3 100644 --- a/src/core/bt/settings.py +++ b/src/core/bt/settings.py @@ -6,12 +6,31 @@ __author__="bjschuma" __date__ ="$Feb 17, 2010 9:32:56 PM$" +from sys import argv,platform +import os + +from bt.message import write + class Settings(dict): def __init__(self): dict.__init__(self) + def setdefaults(self): + count = 0 + if ("-v" in argv) or ("--verbose" in argv): + count = argv.count("-v") + argv.count("--verbose") + self['verbose'] = count + write("Setting default values",1) + self['user'] = os.path.expanduser("~") + self['plugpath'] = ["plugins", "extra"] + self['arch'] = platform + self['appname'] = "scion" + write(self,3) + + + def has(self,key): return (key.upper() in self) @@ -35,3 +54,7 @@ class Settings(dict): def __delitem__(self,key): dict.__delitem__(self,key.upper()) + + + def load(self,path): + pass diff --git a/src/core/manager.py b/src/core/manager.py index 791c84af..08eb5ec6 100644 --- a/src/core/manager.py +++ b/src/core/manager.py @@ -9,7 +9,7 @@ from bt.signal import * from bt import alias #import loader -import settings +import session import inspect @@ -123,15 +123,15 @@ class Manager: return None - def findsession(self): - path = settings.get("user") - if path == expandPath("~"): - #path = join(path,".scion") - path = join(path,"."+settings.get("appname")) - mkdir(path) - path = join(path,"session") - mkdir(path) - return path + #def findsession(self): + # path = session.session.settings.get("user") + # if path == expandPath("~"): + # #path = join(path,".scion") + # path = join(path,"."+settings.get("appname")) + # mkdir(path) + # path = join(path,"session") + # mkdir(path) + # return path def savesession(self,session): @@ -143,8 +143,8 @@ class Manager: def restoresession(self): - path = self.findsession() - settings.load(path) + path = session.getSession() + session.settings.load(path) path = join(path,"enabled") file = fopen(path) self.restored = [] diff --git a/src/core/scion.py b/src/core/scion.py index 326fb49a..439479c4 100644 --- a/src/core/scion.py +++ b/src/core/scion.py @@ -5,8 +5,7 @@ __author__="bjschuma" __date__ ="$Dec 4, 2009 3:37:21 PM$" # We need to import settings before we can use disp() -from session import session -session.settings["appname"] = "scion" +import session # The first thing we do is import write() so we can occasionally print messages from bt.message import write @@ -17,8 +16,8 @@ from bt.signal import emit from bt.file import join # Import the plugin loader class! -#import loader -#import manager +import loader +import manager def loadPluginPath(path): @@ -28,20 +27,19 @@ def loadPluginPath(path): # Begin our main loop def main(): - #for path in session.settings.get("PLUGPATH"): - # loadPluginPath(path) + for path in session.settings.get("PLUGPATH"): + loadPluginPath(path) emit("scion-plugins-loaded") app = session.settings["appname"] write("Welcome to "+app+"!") setname(app) - #session.settings["appdir"] = join(session.settings["user"], "."+app) + session.settings["appdir"] = join(session.settings["user"], "."+app) - #manager.manager.restoresession() - #manager.manager.startup() + manager.manager.restoresession() + manager.manager.startup() #emit("scion-begin") - #settings.get("loop")() diff --git a/src/core/session.py b/src/core/session.py index fa14429c..2ed264e2 100644 --- a/src/core/session.py +++ b/src/core/session.py @@ -8,13 +8,20 @@ __date__ ="$Feb 17, 2010 9:18:50 PM$" from bt.settings import Settings +from bt.file import * +global settings -class Session(): - def __init__(self): - self.settings = Settings() + +def getSession(): + path = settings["user"] + if path == expandPath("~"): + path = join(path,"."+settings["appname"]) + mkdir(path) + path = join(path,"session") + mkdir(path) + return path -global session -session = Session() - +settings = Settings() +settings.setdefaults() \ No newline at end of file diff --git a/src/plugins/cli.py b/src/plugins/cli.py index 943287e0..77b7ece8 100644 --- a/src/plugins/cli.py +++ b/src/plugins/cli.py @@ -13,6 +13,8 @@ import cline.loop import cline.addch import cline.message import cline.history + +from session import settings #import settings @@ -33,18 +35,18 @@ class Plugin(plugin.Plugin): register("scion-end", cline.loop.quit) # Initialize a dictionary for key press inputs - settings.set("keyinput", dict()) - settings.get("keyinput")[259] = cline.history.prev - settings.get("keyinput")[258] = cline.history.next - settings.get("keyinput")[127] = cline.addch.backspace - settings.get("keyinput")[10] = cline.addch.enter + settings["keyinput"] = dict() + settings["keyinput"][259] = cline.history.prev + settings["keyinput"][258] = cline.history.next + settings["keyinput"][127] = cline.addch.backspace + settings["keyinput"][10] = cline.addch.enter def close(self): cline.loop.quit() cline.history.save() write("CLI has been stopped", True) - settings.delete("keyinput") + del settings["keyinput"] remove("scion-begin",cline.loop.loop) remove("scion-end",cline.loop.quit) diff --git a/src/plugins/cline/history.py b/src/plugins/cline/history.py index ae906b34..2cd88df1 100644 --- a/src/plugins/cline/history.py +++ b/src/plugins/cline/history.py @@ -6,7 +6,7 @@ __author__="bjschuma" __date__ ="$Jan 29, 2010 9:59:20 AM$" -import settings +from session import settings from bt.file import * global hist @@ -29,7 +29,7 @@ def insert(input): def getfile(flags='r'): - dir = settings.get("appdir") + dir = settings["appdir"] file = join(dir,"history") return fopen(file,flags)