Can save and restore a scion session
This commit is contained in:
parent
1271406620
commit
ac895c547f
|
@ -23,7 +23,7 @@ def checkPath(path):
|
||||||
|
|
||||||
def mkdir(path):
|
def mkdir(path):
|
||||||
if checkDir(path)==False:
|
if checkDir(path)==False:
|
||||||
write("Creating directory: "+path)
|
write("Creating directory: "+path,True)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ __date__ ="$Dec 8, 2009 8:40:36 AM$"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from bt.message import *
|
from bt.message import *
|
||||||
|
from bt.file import *
|
||||||
import loader
|
import loader
|
||||||
|
|
||||||
class Manager:
|
class Manager:
|
||||||
|
@ -13,6 +14,8 @@ class Manager:
|
||||||
# Map the plugin name to a dictionary
|
# Map the plugin name to a dictionary
|
||||||
self.enabled = dict()
|
self.enabled = dict()
|
||||||
self.disabled = dict()
|
self.disabled = dict()
|
||||||
|
self.restored = []
|
||||||
|
self.restoresession()
|
||||||
|
|
||||||
|
|
||||||
def addPlugins(self, plugins):
|
def addPlugins(self, plugins):
|
||||||
|
@ -24,6 +27,8 @@ class Manager:
|
||||||
try:
|
try:
|
||||||
if plugin.type=="core":
|
if plugin.type=="core":
|
||||||
self.enablePlugin(plugin.name)
|
self.enablePlugin(plugin.name)
|
||||||
|
elif (plugin.name in self.restored)==True:
|
||||||
|
self.enablePlugin(plugin.name)
|
||||||
except:
|
except:
|
||||||
error("Error adding plugin: "+plugin.name)
|
error("Error adding plugin: "+plugin.name)
|
||||||
|
|
||||||
|
@ -77,6 +82,7 @@ class Manager:
|
||||||
# Disable all plugins
|
# Disable all plugins
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
write("Shutting down manager, disabling all active plugins", True)
|
write("Shutting down manager, disabling all active plugins", True)
|
||||||
|
self.savesession()
|
||||||
keys = self.enabled.keys()
|
keys = self.enabled.keys()
|
||||||
for plugin in keys:
|
for plugin in keys:
|
||||||
self.disablePlugin(plugin)
|
self.disablePlugin(plugin)
|
||||||
|
@ -84,12 +90,41 @@ class Manager:
|
||||||
|
|
||||||
def run(self,name,args=None):
|
def run(self,name,args=None):
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
|
|
||||||
if (name in self.enabled)==True:
|
if (name in self.enabled)==True:
|
||||||
self.enabled[name].run(args)
|
self.enabled[name].run(args)
|
||||||
else:
|
else:
|
||||||
write("Plugin either not loaded or doesn't exist")
|
write("Plugin either not loaded or doesn't exist")
|
||||||
|
|
||||||
|
|
||||||
|
def findsession(self):
|
||||||
|
path = settings.get("user")
|
||||||
|
if path == expandPath("~"):
|
||||||
|
path = join(path,".scion")
|
||||||
|
mkdir(path)
|
||||||
|
path = join(path,"session")
|
||||||
|
mkdir(path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def savesession(self):
|
||||||
|
path = self.findsession()
|
||||||
|
path = join(path,"enabled")
|
||||||
|
file = fopen(path,'w')
|
||||||
|
for key in self.enabled.keys():
|
||||||
|
file.write(key+"\n")
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def restoresession(self):
|
||||||
|
path = self.findsession()
|
||||||
|
path = join(path,"enabled")
|
||||||
|
file = fopen(path)
|
||||||
|
if file==None:
|
||||||
|
return
|
||||||
|
for line in file:
|
||||||
|
self.restored+=[line.strip()]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
global manager
|
global manager
|
||||||
manager = Manager()
|
manager = Manager()
|
Loading…
Reference in New Issue