From: Frank Brehm Date: Wed, 22 Aug 2018 16:29:51 +0000 (+0200) Subject: Adding property data_dir X-Git-Tag: 0.9.8^2~15 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=2f004bc35481989578c64e45b6a875e6f0bf0fe2;p=pixelpark%2Fpuppetmaster-webhooks.git Adding property data_dir --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 2126891..68678e2 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.8.7' +__version__ = '0.8.8' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index c61381f..f7a2f90 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -64,6 +64,8 @@ class BaseHookApp(BaseObject): puppet_envs_dir = os.path.join(puppetlabs_cfg_dir, 'code', 'environments') fileserver_dir = os.path.join(puppetlabs_cfg_dir, 'code', 'fileserver') + default_data_dir = os.sep + os.path.join('var', 'lib', 'webhooks') + special_chars_re = re.compile(r'[^a-z0-9_\-]', re.IGNORECASE) dev_re = re.compile(r'^dev') @@ -93,6 +95,7 @@ class BaseHookApp(BaseObject): self.full_name = None self.git_ssh_url = None self.do_sudo = True + self.data_dir = self.default_data_dir self.cmdline_args = None @@ -187,6 +190,7 @@ class BaseHookApp(BaseObject): res['puppet_envs_dir'] = self.puppet_envs_dir res['env_dir'] = self.env_dir res['fileserver_dir'] = self.fileserver_dir + res['default_data_dir'] = self.default_data_dir return res @@ -198,6 +202,11 @@ class BaseHookApp(BaseObject): add_help=False, ) + arg_parser.add_argument( + "-D", '--data', '--data-dir', metavar='DIR', dest='data_dir', + help="Data directory, default: {!r}.".format(self.data_dir), + ) + arg_parser.add_argument( "-v", "--verbose", action="count", dest='verbose', help='Increase the verbosity level', @@ -235,6 +244,12 @@ class BaseHookApp(BaseObject): arg_parser.print_usage(sys.stdout) sys.exit(0) + if self.cmdline_args.data_dir: + path = self.cmdline_args.data_dir + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(os.getcwd(), path)) + self.data_dir = path + if self.cmdline_args.verbose is not None: if self.cmdline_args.verbose > self.verbose: self.verbose = self.cmdline_args.verbose @@ -346,6 +361,12 @@ class BaseHookApp(BaseObject): if os.path.isabs(pdir): self.default_parent_dir = pdir + 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) + self.data_dir = path + if 'mail_cc_addresses' in config: if config['mail_cc_addresses'] is None: self.mail_cc_addresses = [] @@ -532,6 +553,31 @@ class BaseHookApp(BaseObject): return True + # ------------------------------------------------------------------------- + def check_data_dir(self): + + LOG.debug("Checking availibility of data directory {!r} ...".format(self.data_dir)) + + if not os.path.exists(self.data_dir): + msg = "Data directory {!r} does not exists.".format(self.data_dir) + LOG.error(msg) + self.print_out(msg + "\n") + return False + + if not os.path.isdir(self.data_dir): + msg = "Path for data directory {!r} is not a directory.".format(self.data_dir) + LOG.error(msg) + self.print_out(msg + "\n") + return False + + if not os.access(self.data_dir, os.W_OK): + msg = "Data directory {!r} is not writeable.".format(self.data_dir) + LOG.error(msg) + self.print_out(msg + "\n") + return False + + return True + # ------------------------------------------------------------------------- def send_error_msgs(self, project='undefined'):