From 018a6c765460f36abdd0ec3f60223b36722252be Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 7 Dec 2018 13:37:09 +0100 Subject: [PATCH] Fixing lib/webhooks/base_app.py --- lib/webhooks/__init__.py | 2 +- lib/webhooks/base_app.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 136e6ca..d3b502f 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.2.2' +__version__ = '1.2.3' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index ffaf22c..deb2152 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -24,6 +24,7 @@ import textwrap import copy import socket import pwd +import pathlib from email.message import EmailMessage @@ -110,7 +111,7 @@ class BaseHookApp(FbBaseObject): """Constructor.""" if not base_dir: - base_dir = os.path.dirname(self.cgi_bin_dir) + base_dir = pathlib.Path(self.cgi_bin_dir) if not getattr(self, 'description', None): self.description = "Base gitlab webhook application." @@ -542,19 +543,21 @@ class BaseHookApp(FbBaseObject): def read_config(self): """Reading configuration from different YAML files.""" + pp_conf_path = pathlib.Path('/etc/pixelpark') + yaml_files = [] # ./hooks.yaml - yaml_files.append(os.path.join(self.base_dir, 'hooks.yaml')) + yaml_files.append(self.base_dir.joinpath('hooks.yaml')) # ./hooks.local.yaml - yaml_files.append(os.path.join(self.base_dir, 'hooks.local.yaml')) + yaml_files.append(self.base_dir.joinpath('hooks.local.yaml')) # ./.yaml - yaml_files.append(os.path.join(self.base_dir, self.appname + '.yaml')) + yaml_files.append(self.base_dir.joinpath(self.appname + '.yaml')) # ./.local.yaml - yaml_files.append(os.path.join(self.base_dir, self.appname + '.local.yaml')) + yaml_files.append(self.base_dir.joinpath(self.appname + '.local.yaml')) # /etc/pixelpark/hooks.yaml - yaml_files.append(os.sep + os.path.join('etc', 'pixelpark', 'hooks.yaml')) + yaml_files.append(pp_conf_path.joinpath('hooks.yaml')) # /etc/pixelpark/.yaml - yaml_files.append(os.sep + os.path.join('etc', 'pixelpark', self.appname + '.yaml')) + yaml_files.append(pp_conf_path.joinpath(self.appname + '.yaml')) for yaml_file in yaml_files: self.read_from_yaml(yaml_file) @@ -563,19 +566,21 @@ class BaseHookApp(FbBaseObject): def read_from_yaml(self, yaml_file): """Reading configuration from given YAML file.""" + f = str(yaml_file) + if self._start_verbose > 1: - self.print_err("Trying to read config from {!r} ...".format(yaml_file)) - if not os.access(yaml_file, os.F_OK): + self.print_err("Trying to read config from {!r} ...".format(f)) + if not os.access(f, os.F_OK): return if self._start_verbose > 1: - self.print_err("Reading config from {!r} ...".format(yaml_file)) + self.print_err("Reading config from {!r} ...".format(f)) config = {} - with open(yaml_file, 'rb') as fh: + with open(f, 'rb') as fh: config = yaml.load(fh.read()) if self._start_verbose > 2: self.print_err("Read config:\n{}".format(pp(config))) if config and isinstance(config, dict): - self.evaluate_config(config, yaml_file) + self.evaluate_config(config, f) # ------------------------------------------------------------------------- def evaluate_config(self, config, yaml_file): @@ -622,7 +627,7 @@ class BaseHookApp(FbBaseObject): if 'data_dir' in config and config['data_dir'] and not self.cmdline_args.data_dir: path = config['data_dir'] if not os.path.isabs(path): - path = os.path.join(self.base_dir, path) + path = os.path.join(str(self.base_dir), path) self.data_dir = path if 'cachefile' in config: @@ -766,7 +771,7 @@ class BaseHookApp(FbBaseObject): self.print_htlm_start() if self.verbose > 1: - LOG.debug("Base directory: {!r}".format(self.base_dir)) + LOG.debug("Base directory: {!r}".format(str(self.base_dir))) LOG.debug("STDIN object: {}".format(sys.stdin.__class__.__name__)) LOG.debug("Encoding of STDIN: {!r}".format(sys.stdin.encoding)) -- 2.39.5