Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: Use ovirt engine configfile ......................................................................
packaging: setup: Use ovirt engine configfile Use configfile from ovirt-engine-lib and (a copy of) escape from ovirt-engine-setup to parse db credential files. Change-Id: Icdea6a02f2737387a4b89b7156eb2c9ebd248fdd Bug-Url: https://bugzilla.redhat.com/1070344 Signed-off-by: Yedidyah Bar David <[email protected]> --- M packaging/common_utils.py M packaging/ovirt-engine-reports-setup.py 2 files changed, 25 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/16/25316/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index 85b8214..308ba99 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -21,6 +21,8 @@ from decorators import transactionDisplay +from ovirt_engine import configfile + #text colors RED = "\033[0;31m" GREEN = "\033[92m" @@ -291,10 +293,13 @@ self.data = [] self.sep = sep - def open(self): + def open(self, useconfigfile=False): fd = file(self.filepath) self.data = fd.readlines() fd.close() + self._useconfigfile = useconfigfile + if self._useconfigfile: + self._configfile = configfile.ConfigFile([self.filepath]) def close(self): fd = file(self.filepath, 'w') @@ -304,11 +309,14 @@ def getParam(self, param): value = None - for line in self.data: - if not re.match("\s*#", line): - found = re.match("\s*%s\s*\%s\s*(.+)$" % (param, self.sep), line) - if found: - value = found.group(1) + if self._useconfigfile: + value = self._configfile.get(param) + else: + for line in self.data: + if not re.match("\s*#", line): + found = re.match("\s*%s\s*\%s\s*(.+)$" % (param, self.sep), line) + if found: + value = found.group(1) return value def editParam(self, param, value): @@ -1287,6 +1295,13 @@ database=db_dict['dbname'], ) +def escape(s, chars): + ret = '' + for c in s: + if c in chars: + ret += '\\' + ret += c + return ret def storeConf(db_dict): if not os.path.exists(DIR_DATABASE_REPORTS_CONFIG): @@ -1302,11 +1317,11 @@ ( 'REPORTS_DB_DATABASE={database}\n' 'REPORTS_DB_USER={user}\n' - 'REPORTS_DB_PASSWORD={password}' + 'REPORTS_DB_PASSWORD="{password}"' ).format( database=db_dict['dbname'], user=db_dict['username'], - password=db_dict['password'], + password=escape(db_dict['password'], '"\\$'), ) ) diff --git a/packaging/ovirt-engine-reports-setup.py b/packaging/ovirt-engine-reports-setup.py index 591ecb2..743e408 100755 --- a/packaging/ovirt-engine-reports-setup.py +++ b/packaging/ovirt-engine-reports-setup.py @@ -350,7 +350,7 @@ if os.path.exists(file): handler = utils.TextConfigFileHandler(file) - handler.open() + handler.open(useconfigfile=True) for k, v in ( ('dbname', 'REPORTS_DB_DATABASE'), @@ -367,7 +367,7 @@ ): s = handler.getParam(v) if s is not None: - db_dict[k] = s.strip('"') + db_dict[k] = s handler.close() return db_dict -- To view, visit http://gerrit.ovirt.org/25316 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icdea6a02f2737387a4b89b7156eb2c9ebd248fdd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-reports Gerrit-Branch: ovirt-3.3 Gerrit-Owner: Yedidyah Bar David <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
