Continued migrating to using a session to store settings. Can load
saved settings.
This commit is contained in:
parent
e28bf46c60
commit
be07a50c20
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<coverage xmlns="http://www.netbeans.org/ns/code-coverage/1" enabled="false"/>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
|
||||
</project-private>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
java.lib.path=
|
||||
main.file=ocarina.py
|
||||
platform.active=Python_2.6.3
|
||||
python.lib.path=
|
||||
main.file=core/scion.py
|
||||
platform.active=default
|
||||
python.lib.path=/usr/bin/python|
|
||||
src.dir=src
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
|
||||
rm -r ./*/*.pyc
|
||||
rm -r ./*/*/*.pyc
|
||||
#rm -r ./*/*.class
|
||||
#rm -r ./*/*/*.class
|
||||
#rm -r ./*/*.pyo
|
||||
#rm -r ./*/*/*.pyo
|
||||
|
|
|
@ -17,13 +17,13 @@ def checkDir(path):
|
|||
# Check if path exists
|
||||
def checkPath(path):
|
||||
path = os.path.expanduser(path)
|
||||
write("Checking if "+path+" exists", True)
|
||||
write("Checking if "+path+" exists", 2)
|
||||
return os.path.exists(path)
|
||||
|
||||
|
||||
def mkdir(path):
|
||||
if checkDir(path)==False:
|
||||
write("Creating directory: "+path,True)
|
||||
write("Creating directory: "+path,2)
|
||||
os.mkdir(path)
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ def fopen(path,flags='r'):
|
|||
if ('r' in flags) == True:
|
||||
exists = checkPath(path)
|
||||
if exists == False:
|
||||
write(path+" does not exist", True)
|
||||
write(path+" does not exist", 2)
|
||||
return None
|
||||
return open(path, flags)
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ from sys import argv,platform
|
|||
import os
|
||||
|
||||
from bt.message import write
|
||||
from bt.file import join
|
||||
from bt import xm
|
||||
|
||||
|
||||
class Settings(dict):
|
||||
|
@ -57,4 +59,17 @@ class Settings(dict):
|
|||
|
||||
|
||||
def load(self,path):
|
||||
write("Loading saved settings",1)
|
||||
path = join(path,"settings")
|
||||
xm.load(path)
|
||||
elm = xm.child()
|
||||
if elm == None:
|
||||
return
|
||||
for node in xm.children(elm):
|
||||
if xm.isElm(node) == False:
|
||||
continue
|
||||
key = xm.name(node)
|
||||
val = xm.value( xm.child(node) )
|
||||
write(" ( "+key + ", " + str(val) + " )",2)
|
||||
self[key] = val
|
||||
pass
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
__author__="bjschuma"
|
||||
__date__ ="$Jan 20, 2010 12:13:21 AM$"
|
||||
|
||||
|
||||
from map import Map
|
||||
global signals, status
|
||||
signals = Map()
|
||||
|
|
|
@ -23,7 +23,7 @@ class PluginLoader:
|
|||
|
||||
# Load plugins from a directory
|
||||
def loaddir(self, dir):
|
||||
write("Loading plugins from " + dir, True)
|
||||
write("Loading plugins from " + dir, 1)
|
||||
|
||||
# Add the directory to our import path
|
||||
sys.path.append(dir)
|
||||
|
@ -45,7 +45,7 @@ class PluginLoader:
|
|||
elif split[1]=="pyc":
|
||||
continue
|
||||
# Load the module into our module array
|
||||
write("Attempting to load "+mod, True)
|
||||
write("Attempting to load "+mod, 2)
|
||||
#try:
|
||||
self.loadmod(split[0], os.path.join(dir,mod))
|
||||
#except:
|
||||
|
|
|
@ -9,13 +9,14 @@ from bt.signal import *
|
|||
from bt import alias
|
||||
#import loader
|
||||
|
||||
import session
|
||||
#import session
|
||||
|
||||
import inspect
|
||||
|
||||
class Manager:
|
||||
def __init__(self):
|
||||
write("Creating plugin manager", True)
|
||||
register("scion-end",self.shutdown,1)
|
||||
# Map the plugin name to a dictionary
|
||||
self.enabled = dict()
|
||||
self.disabled = dict()
|
||||
|
@ -25,7 +26,7 @@ class Manager:
|
|||
def addPlugins(self, plugins):
|
||||
# Add each plugin to the disabled list
|
||||
for plugin in plugins:
|
||||
write("Adding plugin: "+plugin.name, True)
|
||||
write("Adding plugin: "+plugin.name, 2)
|
||||
self.disabled[plugin.name] = plugin
|
||||
|
||||
|
||||
|
@ -53,7 +54,7 @@ class Manager:
|
|||
def enablePlugin(self,name):
|
||||
if (name in self.disabled) == True:
|
||||
try:
|
||||
write("Enabling plugin: "+name,True)
|
||||
write("Enabling plugin: "+name,2)
|
||||
plugin = self.movePlugin(name, self.disabled, self.enabled)
|
||||
plugin.open()
|
||||
return True
|
||||
|
@ -82,27 +83,12 @@ class Manager:
|
|||
|
||||
# Disable all plugins
|
||||
def shutdown(self):
|
||||
emit("scion-end")
|
||||
write("Shutting down manager, disabling all active plugins", True)
|
||||
path = session.getSession()
|
||||
#session = self.findsession()
|
||||
self.savesession(path)
|
||||
write("Shutting down manager, disabling all active plugins", 1)
|
||||
keys = self.enabled.keys()
|
||||
for plugin in keys:
|
||||
self.disablePlugin(plugin)
|
||||
#session.settings.save(path)
|
||||
|
||||
|
||||
def startup(self):
|
||||
if len(self.restored) == 0:
|
||||
for key in self.disabled.keys():
|
||||
if self.disabled[key].type == "core":
|
||||
self.enablePlugin(key)
|
||||
return
|
||||
|
||||
for name in self.restored:
|
||||
self.enablePlugin(name)
|
||||
|
||||
|
||||
def run(self,name,args=None):
|
||||
name = name.strip()
|
||||
|
@ -124,15 +110,11 @@ class Manager:
|
|||
return None
|
||||
|
||||
|
||||
#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 call(self,name,args):
|
||||
disable()
|
||||
result = self.run(name,args)
|
||||
enable()
|
||||
return result
|
||||
|
||||
|
||||
def savesession(self,session):
|
||||
|
@ -140,34 +122,4 @@ class Manager:
|
|||
file = fopen(path,'w')
|
||||
for key in self.enabled.keys():
|
||||
file.write(key+"\n")
|
||||
file.close()
|
||||
|
||||
|
||||
def restoresession(self):
|
||||
path = session.getSession()
|
||||
session.settings.load(path)
|
||||
path = join(path,"enabled")
|
||||
file = fopen(path)
|
||||
self.restored = []
|
||||
if file==None:
|
||||
return
|
||||
for line in file:
|
||||
self.restored+=[line.strip()]
|
||||
|
||||
|
||||
|
||||
global manager
|
||||
manager = Manager()
|
||||
|
||||
|
||||
def run(name,args=None):
|
||||
global manager
|
||||
return manager.run(name,args)
|
||||
|
||||
|
||||
def call(name,args=None):
|
||||
global manager
|
||||
disable()
|
||||
result = manager.run(name,args)
|
||||
enable()
|
||||
return result
|
||||
file.close()
|
|
@ -17,12 +17,11 @@ from bt.file import join
|
|||
|
||||
# Import the plugin loader class!
|
||||
import loader
|
||||
import manager
|
||||
|
||||
|
||||
def loadPluginPath(path):
|
||||
loader.load.loaddir(path)
|
||||
manager.manager.addPlugins(loader.load.getPlugins())
|
||||
session.manager.addPlugins(loader.load.getPlugins())
|
||||
|
||||
|
||||
# Begin our main loop
|
||||
|
@ -30,15 +29,12 @@ def main():
|
|||
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)
|
||||
|
||||
manager.manager.restoresession()
|
||||
manager.manager.startup()
|
||||
emit("scion-plugins-loaded")
|
||||
emit("scion-begin")
|
||||
|
||||
|
||||
|
|
|
@ -9,19 +9,42 @@ __date__ ="$Feb 17, 2010 9:18:50 PM$"
|
|||
|
||||
from bt.settings import Settings
|
||||
from bt.file import *
|
||||
from bt.message import write
|
||||
from bt import signal
|
||||
from manager import Manager
|
||||
|
||||
global settings
|
||||
global manager
|
||||
|
||||
|
||||
def getSession():
|
||||
path = settings["user"]
|
||||
if path == expandPath("~"):
|
||||
path = join(path,"."+settings["appname"])
|
||||
mkdir(path)
|
||||
path = settings["appdir"]
|
||||
mkdir(path)
|
||||
path = join(path,"session")
|
||||
mkdir(path)
|
||||
return path
|
||||
|
||||
|
||||
def restore():
|
||||
write("Restoring session",1)
|
||||
path = getSession()
|
||||
write(path,2)
|
||||
settings.load(path)
|
||||
enabled = fopen( join(path,"enabled") )
|
||||
if not enabled == None:
|
||||
for line in enabled:
|
||||
manager.enablePlugin(line.strip())
|
||||
|
||||
|
||||
def save():
|
||||
write("Saving session")
|
||||
|
||||
|
||||
|
||||
settings = Settings()
|
||||
settings.setdefaults()
|
||||
manager = Manager()
|
||||
# We want to restore settings as early as possible
|
||||
settings.setdefaults()
|
||||
|
||||
signal.register("scion-plugins-loaded",restore,0)
|
||||
signal.register("scion-end",save,0)
|
|
@ -13,47 +13,6 @@ global settings
|
|||
settings = dict()
|
||||
|
||||
|
||||
# Return true if settings contains key
|
||||
def has(key):
|
||||
return (key.upper() in settings.keys())
|
||||
|
||||
|
||||
# Set key to value
|
||||
# This must be defined before other imports so bt.message can use it
|
||||
def set(key,value):
|
||||
key = key.upper()
|
||||
settings[key] = value
|
||||
|
||||
|
||||
# Return the value at key
|
||||
def get(key):
|
||||
key = key.upper()
|
||||
if has(key) == False:
|
||||
return None
|
||||
return settings[key]
|
||||
|
||||
|
||||
from bt.message import write
|
||||
from bt.message import error
|
||||
from bt.file import fopen
|
||||
from bt.file import join
|
||||
from bt import xm
|
||||
from bt import scripting
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def delete(key):
|
||||
key = key.upper()
|
||||
if has(key) == True:
|
||||
del settings[key]
|
||||
|
||||
|
||||
# Read settings from file
|
||||
def readfile(file):
|
||||
write("Reading file: "+file,True)
|
||||
file = fopen(file)
|
||||
|
||||
|
||||
# Parse the user input
|
||||
|
@ -106,36 +65,3 @@ def save(path):
|
|||
xm.append(t,e)
|
||||
xm.append(e,elm)
|
||||
xm.write(path)
|
||||
|
||||
|
||||
def load(path):
|
||||
write("Loading saved settings",True)
|
||||
global settings
|
||||
path = join(path,"settings")
|
||||
xm.load(path)
|
||||
elm = xm.child()
|
||||
if elm == None:
|
||||
return
|
||||
for node in xm.children(elm):
|
||||
if xm.isElm(node) == False:
|
||||
continue
|
||||
key = xm.name(node)
|
||||
val = xm.child(node)
|
||||
set(key,xm.value(val))
|
||||
|
||||
|
||||
# Set default values
|
||||
# Set verbose first so we can use write()
|
||||
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("~")
|
||||
set("USER", user)
|
||||
set("PLUGPATH", ["plugins", "extra"])
|
||||
|
||||
# Find out what platform we are running on
|
||||
set("ARCH", sys.platform)
|
||||
|
||||
|
||||
parseInput()
|
|
@ -2,44 +2,46 @@ Documentation for signals, and where they are emitted
|
|||
|
||||
cli-loop-begin:
|
||||
Called at the beginning of every loop in the cli
|
||||
Emitted in core.cline.loop.loop()
|
||||
Emitted in plugins.cline.loop.loop()
|
||||
|
||||
|
||||
cli-loop-end:
|
||||
Called at the end of every loop in the cli
|
||||
Emitted in core.cline.loop.loop()
|
||||
Emitted in plugins.cline.loop.loop()
|
||||
|
||||
|
||||
message-write:
|
||||
Displays text to the screen
|
||||
Emitted in bt.message.write()
|
||||
Registered in bt.message
|
||||
Registered in core.cline.loop.init()
|
||||
Removed in core.cline.loop.quit()
|
||||
Stopped in core.cline.message.insert()
|
||||
Emitted in core.bt.message.write()
|
||||
Registered in core.bt.message
|
||||
Registered in plugins.cline.loop.init()
|
||||
Removed in plugins.cline.loop.quit()
|
||||
Stopped in plugins.cline.message.insert()
|
||||
|
||||
|
||||
scion-begin:
|
||||
Begins a main loop for the program.
|
||||
Emitted in base.scion.main()
|
||||
Registered in core.cli.Plugin.open()
|
||||
Emitted in core.scion.main()
|
||||
Registered in plugins.cli.Plugin.open()
|
||||
Registered in extra.sgtk.Plugin.open()
|
||||
Removed in core.cli.Plugin.close()
|
||||
Removed in plugins.cli.Plugin.close()
|
||||
Removed in extra.sgtk.Plugin.close()
|
||||
|
||||
|
||||
scion-end:
|
||||
Ends the main loop and closes all plugins
|
||||
Emitted in base.manager.shutdown()
|
||||
Registered in core.cli.Plugin.open()
|
||||
Emitted in plugins.exit.run()
|
||||
Registered in plugins.manager.Manager.__init__()
|
||||
Registered in plugins.cli.Plugin.open()
|
||||
Registered in extra.sgtk.Plugin.open()
|
||||
Removed in core.cli.Plugin.close()
|
||||
Removed in plugins.cli.Plugin.close()
|
||||
Removed in extra.sgtk.Plugin.close()
|
||||
|
||||
|
||||
scion-plugins-loaded:
|
||||
Called right after loading all the plugins (before restoring settings or
|
||||
enabling any plugins)
|
||||
Emitted in scion.main()
|
||||
Emitted in core.scion.main()
|
||||
Registered in core.session
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ __date__ ="$Jan 9, 2010 7:22:31 PM$"
|
|||
|
||||
|
||||
from bt.message import write
|
||||
import settings
|
||||
from session import settings
|
||||
from bt import plugin
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ class Plugin(plugin.Plugin):
|
|||
|
||||
|
||||
def run(self, args=None):
|
||||
keys = settings.settings.keys()
|
||||
keys = settings.keys()
|
||||
join = ", "
|
||||
|
||||
if args == None:
|
||||
|
@ -26,5 +26,5 @@ class Plugin(plugin.Plugin):
|
|||
write(str)
|
||||
else:
|
||||
if settings.has(args[0]) == True:
|
||||
write( settings.get(args[0]) )
|
||||
write( settings[args[0]] )
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ __date__ ="$Jan 13, 2010 12:02:58 AM$"
|
|||
from bt import plugin
|
||||
from bt.message import write
|
||||
from bt import signal
|
||||
from manager import manager
|
||||
import settings
|
||||
#from manager import manager
|
||||
from session import settings,manager
|
||||
from guiGTK import *
|
||||
import gtk
|
||||
|
||||
|
@ -27,17 +27,17 @@ class Plugin(plugin.Plugin):
|
|||
|
||||
def open(self):
|
||||
#settings.set("guirunning",False)
|
||||
if settings.get("guirunning") == True:
|
||||
if settings["guirunning"] == True:
|
||||
signal.register("scion-begin",self.loop,90)
|
||||
signal.register("scion-end",self.close,90)
|
||||
else:
|
||||
settings.set("guirunning",False)
|
||||
settings["guirunning"] = False
|
||||
|
||||
|
||||
def close(self):
|
||||
if settings.get("guirunning") == True:
|
||||
if settings["guirunning"] == True:
|
||||
gtk.main_quit()
|
||||
settings.delete("gtkfuncs")
|
||||
#del settings["gtkfuncs"]
|
||||
signal.remove("scion-begin",self.loop)
|
||||
signal.remove("scion-end",self.close)
|
||||
|
||||
|
@ -71,9 +71,9 @@ class Plugin(plugin.Plugin):
|
|||
bar = menu.makeBar()
|
||||
vbox.pack(bar)
|
||||
|
||||
if settings.has("gtkfuncs") == True:
|
||||
for func in settings.get("gtkfuncs", True):
|
||||
func([win,vbox,bar])
|
||||
#if settings.has("gtkfuncs") == True:
|
||||
# for func in settings.get("gtkfuncs", True):
|
||||
# func([win,vbox,bar])
|
||||
|
||||
settings.set("guirunning",True)
|
||||
settings["guirunning"] = True
|
||||
gtk.main()
|
||||
|
|
|
@ -57,7 +57,7 @@ class Plugin(plugin.Plugin):
|
|||
return
|
||||
|
||||
if args[0]=="prompt":
|
||||
settings.set("prompt",args[1]+" ")
|
||||
settings["prompt"] = args[1] + " "
|
||||
elif args[0]=="maxhist":
|
||||
if len(args) == 1:
|
||||
write(settings.get("maxhist"))
|
||||
|
|
|
@ -36,7 +36,8 @@ def init():
|
|||
settings["maxyx"] = maxyx
|
||||
#if settings.has("prompt") == False:
|
||||
# settings.set("prompt", ">>> ")
|
||||
settings.init("prompt",">>> ")
|
||||
settings.init("prompt",">>>")
|
||||
settings["prompt"] += " "
|
||||
#else:
|
||||
# settings.set("prompt",settings.get("prompt")+" ")
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
__author__="bjschuma"
|
||||
__date__ ="$Dec 19, 2009 11:38:46 PM$"
|
||||
|
||||
from manager import manager
|
||||
from session import manager
|
||||
from session import settings
|
||||
#from bt.message import write
|
||||
import history
|
||||
|
|
|
@ -7,7 +7,7 @@ __author__="bjschuma"
|
|||
__date__ ="$Jan 20, 2010 6:42:45 PM$"
|
||||
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
from bt.signal import emit
|
||||
|
||||
|
||||
class Plugin(plugin.Plugin):
|
||||
|
@ -18,6 +18,6 @@ class Plugin(plugin.Plugin):
|
|||
|
||||
|
||||
def run(self,args=None):
|
||||
manager.shutdown()
|
||||
emit("scion-end")
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ __date__ ="$Jan 20, 2010 8:01:55 PM$"
|
|||
|
||||
from bt.message import write, disable, enable
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
from session import manager
|
||||
|
||||
|
||||
class Plugin(plugin.Plugin):
|
||||
|
|
|
@ -6,7 +6,7 @@ __date__ ="$Jan 22, 2010 12:14:01 AM$"
|
|||
|
||||
from bt.message import write
|
||||
from bt import plugin
|
||||
from manager import manager
|
||||
from session import manager
|
||||
|
||||
|
||||
class Plugin(plugin.Plugin):
|
||||
|
@ -52,7 +52,7 @@ class Plugin(plugin.Plugin):
|
|||
|
||||
def run(self, args=None):
|
||||
if args == None:
|
||||
write("Usage:" + self.usage)
|
||||
write("Usage: " + self.usage)
|
||||
return
|
||||
|
||||
if args[0] == "enable":
|
||||
|
|
Loading…
Reference in New Issue