qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject [1/2] qpid-dispatch git commit: Add controls specify pure json config file; skips conf file processing.
Date Mon, 18 Jan 2016 16:52:00 GMT
Repository: qpid-dispatch
Updated Branches:
  refs/heads/crolke-DISPATCH-202-1 [created] b0e4b77e1


Add controls specify pure json config file; skips conf file processing.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/fe69669e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/fe69669e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/fe69669e

Branch: refs/heads/crolke-DISPATCH-202-1
Commit: fe69669eb7a693fbb8b38fe6e4dcd4ebcea29c4b
Parents: e8b516b
Author: Chuck Rolke <crolke@redhat.com>
Authored: Mon Jan 18 11:21:33 2016 -0500
Committer: Chuck Rolke <crolke@redhat.com>
Committed: Mon Jan 18 11:21:33 2016 -0500

----------------------------------------------------------------------
 .../qpid_dispatch_internal/management/config.py | 23 +++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/fe69669e/python/qpid_dispatch_internal/management/config.py
----------------------------------------------------------------------
diff --git a/python/qpid_dispatch_internal/management/config.py b/python/qpid_dispatch_internal/management/config.py
index 73725c1..e083372 100644
--- a/python/qpid_dispatch_internal/management/config.py
+++ b/python/qpid_dispatch_internal/management/config.py
@@ -30,13 +30,13 @@ from .qdrouter import QdSchema
 class Config(object):
     """Load config entities from qdrouterd.conf and validated against L{QdSchema}."""
 
-    def __init__(self, filename=None, schema=QdSchema()):
+    def __init__(self, filename=None, schema=QdSchema(), raw_json=False):
         self.schema = schema
         self.config_types = [et for et in schema.entity_types.itervalues()
                              if schema.is_configuration(et)]
         if filename:
             try:
-                self.load(filename)
+                self.load(filename, raw_json)
             except Exception, e:
                 raise Exception, "Cannot load configuration file %s: %s" % (filename, e),
sys.exc_info()[2]
         else:
@@ -67,6 +67,17 @@ class Config(object):
             s[1] = dict((camelcase(k), v) for k, v in s[1].iteritems())
         return sections
 
+    @staticmethod
+    def _parserawjson(lines):
+        """Parse raw json config file format into a section list"""
+        def sub(line):
+            """Do substitutions to make line json-friendly"""
+            line = line.split('#')[0].strip() # Strip comments
+            return line
+        js_text = "%s"%("".join([sub(l) for l in lines]))
+        sections = json.loads(js_text)
+        return sections
+
 
     def _expand(self, content):
         """
@@ -90,16 +101,18 @@ class Config(object):
         return [_expand_section(s, annotations) for s in content
                 if self.schema.is_configuration(self.schema.entity_type(s[0], False))]
 
-    def load(self, source):
+    def load(self, source, raw_json=False):
         """
         Load a configuration file.
         @param source: A file name, open file object or iterable list of lines
+        @param raw_json: Source is pure json not needing conf-style substitutions
         """
         if isinstance(source, basestring):
+            raw_json |= source.endswith(".json")
             with open(source) as f:
-                self.load(f)
+                self.load(f, raw_json)
         else:
-            sections = self._parse(source)
+            sections = self._parserawjson(source) if raw_json else self._parse(source)
             # Add missing singleton sections
             for et in self.config_types:
                 if et.singleton and not [s for s in sections if s[0] == et.short_name]:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message