Continued work with reworking startup / sessions

This commit is contained in:
bjschuma 2010-02-19 00:19:39 -05:00 committed by bjschuma
parent 2bf15d4161
commit 6b7347464a
8 changed files with 72 additions and 41 deletions

View File

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

View File

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

View File

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

View File

@ -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 = []

View File

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

View File

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

View File

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

View File

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