]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding property data_dir
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 22 Aug 2018 16:29:51 +0000 (18:29 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 22 Aug 2018 16:29:51 +0000 (18:29 +0200)
lib/webhooks/__init__.py
lib/webhooks/base_app.py

index 2126891416137086badf027974d981d970b790f0..68678e2ea5e4aef5b687bc81302d6a1d28b602af 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.8.7'
+__version__ = '0.8.8'
 
 # vim: ts=4 et list
index c61381feb2394d7ef7e4d8c1864e2c044b427f4d..f7a2f90bd544fc86142aa8947abd9ce78535a783 100644 (file)
@@ -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'):