No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sessionhandler.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .plugins import Plugin, MetaPlugType
  2. from .exceptions import *
  3. from lodel.settings.validator import SettingValidator
  4. ##@brief SessionHandlerPlugin metaclass designed to implements a wrapper
  5. #between SessionHandlerPlugin classmethod and plugin loader functions
  6. class SessionPluginWrapper(MetaPlugType):
  7. ##@brief Constant that stores all possible session actions
  8. #
  9. #Key is the SessionHandlerPlugin method name and value is SessionHandler
  10. #plugin function name
  11. _ACTIONS = {
  12. 'start': 'start_session',
  13. 'destroy': 'destroy_session',
  14. 'restore': 'restore_session',
  15. 'save': 'save_session'}
  16. def __init__(self, name, bases, attrs):
  17. super().__init__(name, bases, attrs)
  18. ##@brief Handles wrapper between class method and plugin loader functions
  19. def __get_attribute__(self, name):
  20. if name in SessionPluginWrapper._Actions:
  21. return getattr(
  22. self._instance.loader_module(),
  23. SessionPluginWrapper._Actions[name])
  24. return super().__get_attribute__(name)
  25. ##@page lodel2_plugins Lodel2 plugins system
  26. #
  27. # @par Plugin structure
  28. #A plugin is a package (a folder containing, at least, an __init__.py file.
  29. #This file should expose multiple things :
  30. # - a CONFSPEC variable containing configuration specifications
  31. # - an _activate() method that returns True if the plugin can be activated (
  32. # optionnal)
  33. #
  34. class SessionHandlerPlugin(Plugin, metaclass=SessionPluginWrapper):
  35. ##@brief Stores the singleton instance
  36. _instance = None
  37. _plist_confspecs = {
  38. 'section': 'lodel2',
  39. 'key': 'session_handler',
  40. 'default': None,
  41. 'validator': SettingValidator('string', none_is_valid=False)}
  42. def __init__(self, plugin_name):
  43. if self._instance is None:
  44. super(Plugin, self).__init__(plugin_name)
  45. self._instance = self
  46. else:
  47. raise RuntimeError("A SessionHandler Plugin is already plug")