2010-02-17 22:22:43 -05:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
# To change this template, choose Tools | Templates
|
|
|
|
# and open the template in the editor.
|
|
|
|
|
|
|
|
__author__="bjschuma"
|
|
|
|
__date__ ="$Feb 17, 2010 9:18:50 PM$"
|
|
|
|
|
|
|
|
|
|
|
|
from bt.settings import Settings
|
2010-02-20 15:37:09 -05:00
|
|
|
from bt.alias import Alias
|
2010-02-19 00:19:39 -05:00
|
|
|
from bt.file import *
|
2010-02-20 00:52:06 -05:00
|
|
|
from bt.message import write
|
|
|
|
from bt import signal
|
2010-02-20 15:37:09 -05:00
|
|
|
|
|
|
|
global alias
|
|
|
|
#alias = Alias()
|
|
|
|
|
2010-02-20 00:52:06 -05:00
|
|
|
from manager import Manager
|
|
|
|
|
2010-02-19 00:19:39 -05:00
|
|
|
global settings
|
2010-02-20 00:52:06 -05:00
|
|
|
global manager
|
2010-02-17 22:22:43 -05:00
|
|
|
|
|
|
|
|
2010-02-19 00:19:39 -05:00
|
|
|
def getSession():
|
2010-02-20 00:52:06 -05:00
|
|
|
path = settings["appdir"]
|
|
|
|
mkdir(path)
|
2010-02-19 00:19:39 -05:00
|
|
|
path = join(path,"session")
|
|
|
|
mkdir(path)
|
|
|
|
return path
|
2010-02-17 22:22:43 -05:00
|
|
|
|
|
|
|
|
2010-02-20 00:52:06 -05:00
|
|
|
def restore():
|
|
|
|
write("Restoring session",1)
|
|
|
|
path = getSession()
|
|
|
|
write(path,2)
|
2010-02-20 15:37:09 -05:00
|
|
|
# Load settings from file
|
2010-02-20 00:52:06 -05:00
|
|
|
settings.load(path)
|
2010-02-20 15:37:09 -05:00
|
|
|
# Load aliases from file
|
|
|
|
alias.load(path)
|
|
|
|
# Restore enabled plugins (new plugins are automatically disabled)
|
2010-02-20 00:52:06 -05:00
|
|
|
enabled = fopen( join(path,"enabled") )
|
|
|
|
if not enabled == None:
|
|
|
|
for line in enabled:
|
|
|
|
manager.enablePlugin(line.strip())
|
2010-02-20 15:42:38 -05:00
|
|
|
enabled.close()
|
|
|
|
# Enable everything if we don't have an enabled list
|
|
|
|
else:
|
|
|
|
for key in manager.disabled.keys():
|
|
|
|
manager.enablePlugin(key)
|
2010-02-20 00:52:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
def save():
|
|
|
|
write("Saving session")
|
2010-02-20 15:37:09 -05:00
|
|
|
path = getSession()
|
|
|
|
write(path,2)
|
|
|
|
# Find list of enabled plugins
|
|
|
|
enabledList = manager.enabled.keys()
|
|
|
|
# Shutdown plugins
|
|
|
|
manager.shutdown()
|
|
|
|
write(enabledList,2)
|
|
|
|
# Record enabled plugins to a file
|
|
|
|
enabled = fopen( join(path,"enabled"), 'w' )
|
|
|
|
if not enabled == None:
|
|
|
|
for plugin in enabledList:
|
|
|
|
enabled.write(plugin+"\n")
|
|
|
|
enabled.close()
|
|
|
|
|
|
|
|
# Save aliases and settings
|
|
|
|
alias.save(path)
|
|
|
|
settings.save(path)
|
2010-02-20 00:52:06 -05:00
|
|
|
|
|
|
|
|
2010-02-17 22:22:43 -05:00
|
|
|
|
2010-02-19 00:19:39 -05:00
|
|
|
settings = Settings()
|
2010-02-20 00:52:06 -05:00
|
|
|
manager = Manager()
|
2010-02-20 15:37:09 -05:00
|
|
|
alias = Alias()
|
|
|
|
#print alias
|
2010-02-20 00:52:06 -05:00
|
|
|
# We want to restore settings as early as possible
|
|
|
|
settings.setdefaults()
|
|
|
|
|
|
|
|
signal.register("scion-plugins-loaded",restore,0)
|
|
|
|
signal.register("scion-end",save,0)
|