Sandro Bonazzola has uploaded a new change for review.

Change subject: conf: use ovirt-engine-lib configfile
......................................................................

conf: use ovirt-engine-lib configfile

Use ovirt-engine-lib configfile module for reading
configuration files.
The previous implementation had an issue if a variable
was defined recursively in more than one config file.

Change-Id: I1f47875a279953bae783407dca41102904a70061
Bug-Url: http://bugzilla.redhat.com/1022557
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M ovirt-log-collector.spec.in
M src/Makefile.am
M src/__main__.py
D src/util.py
4 files changed, 6 insertions(+), 110 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/31/20531/1

diff --git a/ovirt-log-collector.spec.in b/ovirt-log-collector.spec.in
index 63c5cfd..a5b8ae9 100644
--- a/ovirt-log-collector.spec.in
+++ b/ovirt-log-collector.spec.in
@@ -32,6 +32,7 @@
 Requires:      python-dateutil
 Requires:      python-lxml
 Requires:      ovirt-engine-sdk
+Requires:      ovirt-engine-lib
 Requires:      logrotate
 Requires:      sos
 Requires:      openssh-clients
diff --git a/src/Makefile.am b/src/Makefile.am
index 74bf7cb..49cd324 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,7 +49,6 @@
 dist_ovirtlogcollectorlib_PYTHON = \
        __init__.py \
        __main__.py \
-       util.py \
        $(NULL)
 
 dist_man_MANS = \
diff --git a/src/__main__.py b/src/__main__.py
index 08c0245..8485dee 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -37,9 +37,12 @@
 import socket
 
 
+from ovirt_engine import configfile
+
+
 from helper import hypervisors
 from ovirt_log_collector import config
-from ovirt_log_collector import util
+
 
 DEFAULT_SSH_USER = 'root'
 DEFAULT_TIME_SHIFT_FILE = 'time_diff.txt'
@@ -135,7 +138,7 @@
     global pg_dbhost
     global pg_dbport
     global pg_dbname
-    engine_config = util.ConfigFile([
+    engine_config = configfile.ConfigFile([
         config.ENGINE_DEFAULTS,
         config.ENGINE_CONF,
     ])
diff --git a/src/util.py b/src/util.py
deleted file mode 100644
index b824e17..0000000
--- a/src/util.py
+++ /dev/null
@@ -1,107 +0,0 @@
-#
-# ovirt-log-collector
-# Copyright (C) 2013 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-import glob
-import os
-import re
-
-
-class ConfigFile(object):
-    _COMMENT_EXPR = re.compile(r'\s*#.*$')
-    _BLANK_EXPR = re.compile(r'^\s*$')
-    _VALUE_EXPR = re.compile(r'^\s*(?P<key>\w+)\s*=\s*(?P<value>.*?)\s*$')
-    _REF_EXPR = re.compile(r'\$\{(?P<ref>\w+)\}')
-
-    def _loadLine(self, line):
-        # Remove comments:
-        commentMatch = self._COMMENT_EXPR.search(line)
-        if commentMatch is not None:
-            line = line[:commentMatch.start()] + line[commentMatch.end():]
-
-        # Skip empty lines:
-        emptyMatch = self._BLANK_EXPR.search(line)
-        if emptyMatch is None:
-            # Separate name from value:
-            keyValueMatch = self._VALUE_EXPR.search(line)
-            if keyValueMatch is not None:
-                key = keyValueMatch.group('key')
-                value = keyValueMatch.group('value')
-
-                # Strip quotes from value:
-                if len(value) >= 2 and value[0] == '"' and value[-1] == '"':
-                    value = value[1:-1]
-
-                # Expand references to other parameters:
-                while True:
-                    refMatch = self._REF_EXPR.search(value)
-                    if refMatch is None:
-                        break
-                    refKey = refMatch.group('ref')
-                    refValue = self._values.get(refKey)
-                    if refValue is None:
-                        break
-                    value = '%s%s%s' % (
-                        value[:refMatch.start()],
-                        refValue,
-                        value[refMatch.end():],
-                    )
-
-                self._values[key] = value
-
-    def __init__(self, files=[]):
-        super(ConfigFile, self).__init__()
-
-        self._values = {}
-
-        for filename in files:
-            self.loadFile(filename)
-            for filed in sorted(
-                glob.glob(
-                    os.path.join(
-                        '%s.d' % filename,
-                        '*.conf',
-                    )
-                )
-            ):
-                self.loadFile(filed)
-
-    def loadFile(self, filename):
-        if os.path.exists(filename):
-            with open(filename, 'r') as f:
-                for line in f:
-                    self._loadLine(line)
-
-    def get(self, name, default=None):
-        return self._values.get(name, default)
-
-    def getboolean(self, name, default=None):
-        text = self.get(name)
-        if text is None:
-            return default
-        else:
-            return text.lower() in ('t', 'true', 'y', 'yes', '1')
-
-    def getinteger(self, name, default=None):
-        value = self.get(name)
-        if value is None:
-            return default
-        else:
-            return int(value)
-
-
-# vim: expandtab tabstop=4 shiftwidth=4


-- 
To view, visit http://gerrit.ovirt.org/20531
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f47875a279953bae783407dca41102904a70061
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to