2014-10-27 16:29:04 -06:00
|
|
|
# -*- coding: cp1252 -*-
|
2014-11-12 20:41:29 -06:00
|
|
|
#from config_utils import Configuration, ConfigurationResetException
|
2019-06-06 11:52:23 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from builtins import object
|
2014-11-12 20:41:29 -06:00
|
|
|
import config
|
2014-10-27 16:29:04 -06:00
|
|
|
import paths
|
|
|
|
import os
|
2015-01-18 17:19:39 -06:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger("sessionmanager.manager")
|
2018-08-17 05:12:49 -05:00
|
|
|
from sessions import session_exceptions
|
2014-10-27 16:29:04 -06:00
|
|
|
|
|
|
|
manager = None
|
|
|
|
def setup():
|
2021-06-16 16:18:41 -05:00
|
|
|
global manager
|
|
|
|
if not manager:
|
|
|
|
manager = sessionManager()
|
2014-10-27 16:29:04 -06:00
|
|
|
|
|
|
|
class sessionManager(object):
|
2021-06-16 16:18:41 -05:00
|
|
|
# def __init__(self):
|
|
|
|
# FILE = "sessions.conf"
|
|
|
|
# SPEC = "app-configuration.defaults"
|
|
|
|
# try:
|
|
|
|
# self.main = Configuration(paths.config_path(FILE), paths.app_path(SPEC))
|
|
|
|
# except ConfigurationResetException:
|
|
|
|
# pass
|
2014-10-27 16:29:04 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def get_current_session(self):
|
|
|
|
if self.is_valid(config.app["sessions"]["current_session"]):
|
|
|
|
return config.app["sessions"]["current_session"]
|
|
|
|
else:
|
|
|
|
return False
|
2014-10-27 16:29:04 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def add_session(self, id):
|
|
|
|
log.debug("Adding a new session: %s" % (id,))
|
|
|
|
path = os.path.join(paths.config_path(), id)
|
|
|
|
if not os.path.exists(path):
|
|
|
|
log.debug("Creating %s path" % (os.path.join(paths.config_path(), path),))
|
|
|
|
os.mkdir(path)
|
|
|
|
config.app["sessions"]["sessions"].append(id)
|
2014-10-27 16:29:04 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def set_current_session(self, sessionID):
|
|
|
|
config.app["sessions"]["current_session"] = sessionID
|
|
|
|
config.app.write()
|
2014-10-27 16:29:04 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
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
|