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):
|
||||
if checkDir(path)==False:
|
||||
write("Creating directory: "+path)
|
||||
write("Creating directory: "+path,True)
|
||||
os.mkdir(path)
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ __date__ ="$Dec 8, 2009 8:40:36 AM$"
|
|||
|
||||
import sys
|
||||
from bt.message import *
|
||||
from bt.file import *
|
||||
import loader
|
||||
|
||||
class Manager:
|
||||
|
@ -13,6 +14,8 @@ class Manager:
|
|||
# Map the plugin name to a dictionary
|
||||
self.enabled = dict()
|
||||
self.disabled = dict()
|
||||
self.restored = []
|
||||
self.restoresession()
|
||||
|
||||
|
||||
def addPlugins(self, plugins):
|
||||
|
@ -24,6 +27,8 @@ class Manager:
|
|||
try:
|
||||
if plugin.type=="core":
|
||||
self.enablePlugin(plugin.name)
|
||||
elif (plugin.name in self.restored)==True:
|
||||
self.enablePlugin(plugin.name)
|
||||
except:
|
||||
error("Error adding plugin: "+plugin.name)
|
||||
|
||||
|
@ -77,6 +82,7 @@ class Manager:
|
|||
# Disable all plugins
|
||||
def shutdown(self):
|
||||
write("Shutting down manager, disabling all active plugins", True)
|
||||
self.savesession()
|
||||
keys = self.enabled.keys()
|
||||
for plugin in keys:
|
||||
self.disablePlugin(plugin)
|
||||
|
@ -84,12 +90,41 @@ class Manager:
|
|||
|
||||
def run(self,name,args=None):
|
||||
name = name.strip()
|
||||
|
||||
if (name in self.enabled)==True:
|
||||
self.enabled[name].run(args)
|
||||
else:
|
||||
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
|
||||
manager = Manager()
|
Loading…
Reference in New Issue