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')
self.full_name = None
self.git_ssh_url = None
self.do_sudo = True
+ self.data_dir = self.default_data_dir
self.cmdline_args = None
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
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',
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
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 = []
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'):