Files
twblue/src/sessionmanager/manager.py

35 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: cp1252 -*-
2022-03-24 10:39:20 -06:00
""" Lightweigth module that saves session position across global config and performs validation of config files. """
import os
2015-01-18 17:19:39 -06:00
import logging
2022-03-24 10:39:20 -06:00
import config
import paths
2015-01-18 17:19:39 -06:00
log = logging.getLogger("sessionmanager.manager")
from sessions import session_exceptions
manager = None
def setup():
2022-03-24 10:39:20 -06:00
""" Creates the singleton instance used within TWBlue to access this object. """
global manager
if not manager:
manager = sessionManager()
class sessionManager(object):
def get_current_session(self):
2022-03-24 10:39:20 -06:00
""" Returns the currently focused session, if valid. """
if self.is_valid(config.app["sessions"]["current_session"]):
return config.app["sessions"]["current_session"]
def set_current_session(self, sessionID):
config.app["sessions"]["current_session"] = sessionID
config.app.write()
def is_valid(self, id):
if not os.path.exists(os.path.join(paths.config_path(), id)):
raise session_exceptions.NonExistentSessionError("That session does not exist.")
config.app["sessions"]["current_session"] = ""
return False
else:
return True