#!/bin/env python3
# -*- coding: utf-8 -*-
-__version__ = '0.8.4'
+__version__ = '0.8.5'
# vim: ts=4 et list
self.cmdline_args = None
- self.puppet_bin = None
self.curl_bin = None
self.handler = None
else:
LOG.debug("We are NOT in CGI.")
- self.search_puppet_bin()
self.search_curl_bin()
self.handler = BaseHandler(
sys.stderr.write("\nSimulation mode - nothing is really done.\n\n")
self.simulate = True
- # -------------------------------------------------------------------------
- def search_puppet_bin(self):
-
- searcher = BaseHandler(
- appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
-
- cmd = searcher.get_cmd('puppet')
- del searcher
- if not cmd:
- sys.exit(9)
- self.puppet_bin = cmd
- return
-
# -------------------------------------------------------------------------
def search_curl_bin(self):
import textwrap
import copy
import pipes
-import subprocess
# Third party modules
try:
os.chdir(parent_dir)
+
cmd = []
- if self.do_sudo:
- cmd = ['sudo', '-n']
if os.access(workdir, os.F_OK):
os.chdir(workdir)
- cmd += ['git', 'pull']
+ cmd = ['git', 'pull']
else:
- cmd += ['git', 'clone', self.git_ssh_url, workdir]
+ cmd = ['git', 'clone', self.git_ssh_url, workdir]
if branch:
cmd += ['-b', branch]
- if self.verbose > 2:
- LOG.debug("Cmd: {}".format(pp(cmd)))
- cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.info("Executing: {}".format(cmd_str))
-
- if self.simulate:
- LOG.info("Simulation mode, don't executing.")
- return
- git = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdoutdata, stderrdata) = git.communicate()
- ret_val = git.wait()
+ (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo)
- LOG.debug("Return value: {}".format(ret_val))
if stdoutdata:
msg = "Output:\n{}".format(to_str(stdoutdata))
- LOG.info(msg)
self.print_out(msg)
else:
LOG.debug("No output.")
+
if stderrdata:
+ cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata))
if ret_val:
- LOG.warn(msg)
self.error_data.append(msg)
- else:
- LOG.info(msg)
self.print_out(msg)
finally:
if stderrdata:
if six.PY3:
- if self.verbose > 3:
+ if self.verbose > 2:
LOG.debug("Decoding {what} from {enc!r}.".format(
what='STDERR', enc=cur_encoding))
stderrdata = stderrdata.decode(cur_encoding)
if stdoutdata:
if six.PY3:
- if self.verbose > 3:
+ if self.verbose > 2:
LOG.debug("Decoding {what} from {enc!r}.".format(
what='STDOUT', enc=cur_encoding))
stdoutdata = stdoutdata.decode(cur_encoding)
if not quiet:
msg = "Output on {where}:\n{what}.".format(
- where="STDOUT", what=stderrdata.strip())
+ where="STDOUT", what=stdoutdata.strip())
if log_output:
LOG.info(msg)
else:
import textwrap
import locale
import pipes
-import subprocess
import urllib.parse
import time
import warnings
"""Constructor."""
self.r10k_bin = None
+ self.puppet_bin = None
self.description = textwrap.dedent('''\
Receives push events as JSON-Data and deploys it with r10k.
''').strip()
self.user_agent = 'pp-webhook-client/' + __version__
+ self.search_puppet_bin()
self.search_r10k_bin()
self.check_cert_files()
return res
+ # -------------------------------------------------------------------------
+ def search_puppet_bin(self):
+
+ searcher = BaseHandler(
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
+ cmd = searcher.get_cmd('puppet')
+ del searcher
+ if not cmd:
+ sys.exit(9)
+ self.puppet_bin = cmd
+ return
+
# -------------------------------------------------------------------------
def search_r10k_bin(self):