ocarina/src/core/session.py

83 lines
1.7 KiB
Python
Raw Normal View History

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
from bt.alias import Alias
from bt.file import *
from bt.message import write
from bt import signal
global alias
#alias = Alias()
from manager import Manager
global settings
global manager
2010-02-17 22:22:43 -05:00
def getSession():
path = settings["appdir"]
mkdir(path)
path = join(path,"session")
mkdir(path)
return path
2010-02-17 22:22:43 -05:00
def restore():
write("Restoring session",1)
path = getSession()
write(path,2)
# Load settings from file
settings.load(path)
# Load aliases from file
alias.load(path)
# Restore enabled plugins (new plugins are automatically disabled)
enabled = fopen( join(path,"enabled") )
if not enabled == None:
for line in enabled:
manager.enablePlugin(line.strip())
enabled.close()
# Enable everything if we don't have an enabled list
else:
for key in manager.disabled.keys():
manager.enablePlugin(key)
def save():
write("Saving session")
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-17 22:22:43 -05:00
settings = Settings()
manager = Manager()
alias = Alias()
#print alias
# We want to restore settings as early as possible
settings.setdefaults()
signal.register("scion-plugins-loaded",restore,0)
signal.register("scion-end",save,0)