]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Fixing lib/webhooks/base_app.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 7 Dec 2018 12:37:09 +0000 (13:37 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 7 Dec 2018 12:37:09 +0000 (13:37 +0100)
lib/webhooks/__init__.py
lib/webhooks/base_app.py

index 136e6caf3278b9d72420c5178e156a20c2c718ac..d3b502f390e68c233e19944349ec43169f9911f8 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '1.2.2'
+__version__ = '1.2.3'
 
 # vim: ts=4 et list
index ffaf22c5a8cb549a1c026e9b7a43096bcce422e5..deb21526e2a245fb550d0a5449531a79a1e1756f 100644 (file)
@@ -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'))
         # ./<appname>.yaml
-        yaml_files.append(os.path.join(self.base_dir, self.appname + '.yaml'))
+        yaml_files.append(self.base_dir.joinpath(self.appname + '.yaml'))
         # ./<appname>.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/<appname>.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))