import copy
import socket
import pwd
+import pathlib
from email.message import EmailMessage
"""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."
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)
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):
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:
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))