mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-07 01:47:32 +01:00
Avance
This commit is contained in:
34
srcantiguo/sessionmanager/manager.py
Normal file
34
srcantiguo/sessionmanager/manager.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: cp1252 -*-
|
||||
""" Lightweigth module that saves session position across global config and performs validation of config files. """
|
||||
import os
|
||||
import logging
|
||||
import config
|
||||
import paths
|
||||
log = logging.getLogger("sessionmanager.manager")
|
||||
from sessions import session_exceptions
|
||||
|
||||
manager = None
|
||||
def setup():
|
||||
""" 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):
|
||||
""" 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
|
||||
Reference in New Issue
Block a user