__init__.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/python2 -O
  2. '''Qubes extensions
  3. Extensions provide additional features (like application menus) found only on
  4. some systems. They may be OS- or architecture-dependent or custom-developed for
  5. particular customer.
  6. .. autoclass:: Extension
  7. :members:
  8. :show-inheritance:
  9. .. autoclass:: ExtensionPlugin
  10. :members:
  11. :show-inheritance:
  12. '''
  13. import inspect
  14. import qubes.events
  15. import qubes.plugins
  16. class ExtensionPlugin(qubes.plugins.Plugin):
  17. '''Metaclass for :py:class:`Extension`'''
  18. def __init__(cls, name, bases, dict_):
  19. super(ExtensionPlugin, cls).__init__(name, bases, dict_)
  20. cls._instance = None
  21. def __call__(cls, *args, **kwargs):
  22. if cls._instance is None:
  23. cls._instance = super(ExtensionPlugin, cls).__call__(*args, **kwargs)
  24. return cls._instance
  25. class Extension(object):
  26. '''Base class for all extensions'''
  27. __metaclass__ = ExtensionPlugin
  28. def __init__(self):
  29. for name in dir(self):
  30. attr = getattr(self, name)
  31. if not ishook(attr):
  32. continue
  33. if attr.ho_vm is not None:
  34. attr.ho_vm.add_hook(event, attr)
  35. else:
  36. # global hook
  37. qubes.events.add_system_hook(event, attr)
  38. def init():
  39. for ext in Extension.register.values():
  40. instance = ext()
  41. __all__ = qubes.plugins.load(__file__)