diff src/core/sat_main.py @ 2443:81a45e7886c9

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
author Goffi <goffi@goffi.org>
date Sun, 19 Nov 2017 16:46:07 +0100
parents a9fac72825a2
children 0199c0bd4c60
line wrap: on
line diff
--- a/src/core/sat_main.py	Sun Nov 19 16:41:59 2017 +0100
+++ b/src/core/sat_main.py	Sun Nov 19 16:46:07 2017 +0100
@@ -55,6 +55,7 @@
         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 @@
         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 @@
         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)