From 3ebc19a376b93b0002b111d5b66408637f077c44 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 15 Feb 2017 12:20:08 +0100 Subject: [PATCH] Adding search for commad 'r10k' in lib/webhooks/r10k.py --- lib/webhooks/__init__.py | 2 +- lib/webhooks/r10k.py | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index ff30aa1..349f40b 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.4.2' +__version__ = '0.4.3' # vim: ts=4 et list diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 2bea9b1..b113fa7 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -41,6 +41,7 @@ class R10kHookApp(BaseHookApp): """Constructor.""" self.ignore_projects = [] + self.r10k_bin = None self.description = textwrap.dedent('''\ Receives push events as JSON-Data and synchronizes the local repository and deploys it with r10k. @@ -51,6 +52,8 @@ class R10kHookApp(BaseHookApp): super(R10kHookApp, self).__init__( appname=appname, verbose=verbose, version=version) + self.search_r10k_bin() + # ------------------------------------------------------------------------- def as_dict(self): """ @@ -64,6 +67,63 @@ class R10kHookApp(BaseHookApp): return res + # ------------------------------------------------------------------------- + def search_r10k_bin(self): + + path_list = [] + cmd = 'r10k' + + search_path = os.environ.get('PATH', None) + if not search_path: + search_path = os.defpath + + search_path_list = [ + '/opt/pixelpark/bin', + '/www/bin', + ] + + search_path_list += search_path.split(os.pathsep) + + default_path = [ + '/usr/local/sbin', + '/usr/local/bin', + '/usr/sbin', + '/usr/bin', + '/sbin', + '/bin', + ] + search_path_list += default_path + + for d in search_path_list: + if not os.path.exists(d): + continue + if not os.path.isdir(d): + continue + d_abs = os.path.realpath(d) + if d_abs not in path_list: + path_list.append(d_abs) + + if self.verbose > 1: + LOG.debug("Searching for command {c!r} in:\n{p}".format( + c=cmd, p=pp(path_list))) + + for d in path_list: + p = os.path.join(d, cmd) + if os.path.exists(p): + if self.verbose > 2: + LOG.debug("Found {!r} ...".format(p)) + if os.access(p, os.X_OK): + self.r10k_bin = p + break + else: + LOG.debug("Command {!r} is not executable.".format(p)) + + if self.r10k_bin: + LOG.debug("Found {c!r} in {p!r}.".format(c=cmd, p=self.r10k_bin)) + else: + LOG.error("Command {!r} not found.".format(cmd)) + sys.exit(9) + # ------------------------------------------------------------------------- def evaluate_config(self, config, yaml_file): -- 2.39.5