core: added a mechanism to associate short names to namespaces:

- new internal registerNamespace can be used by a plugin to associate a short name to a namespace
- new NamespacesGet bridge method retrieve those associations
This commit is contained in:
Goffi 2017-11-19 16:46:07 +01:00
commit da077485d2

View file

@ -55,6 +55,7 @@ class SAT(service.Service):
self.initialised = defer.Deferred()
self.profiles = {}
self.plugins = {}
self._ns_map = {} # map for short name to whole namespace
self.memory = Memory(self)
self.trigger = trigger.TriggerManager() # trigger are used to change SàT behaviour
@ -118,6 +119,7 @@ class SAT(service.Service):
self.bridge.register_method("saveParamsTemplate", self.memory.save_xml)
self.bridge.register_method("loadParamsTemplate", self.memory.load_xml)
self.bridge.register_method("sessionInfosGet", self.getSessionInfos)
self.bridge.register_method("namespacesGet", self.getNamespaces)
self.memory.initialized.addCallback(self._postMemoryInit)
@ -955,6 +957,17 @@ class SAT(service.Service):
languageSwitch()
return help_string
# misc methods
def registerNamespace(self, short_name, namespace):
"""associate a namespace to a short name"""
if short_name in self._ns_map:
raise exceptions.ConflictError(u'this short name is already used')
self._ns_map[short_name] = namespace
def getNamespaces(self):
return self._ns_map
def getSessionInfos(self, profile_key):
"""compile interesting data on current profile session"""
client = self.getClient(profile_key)