import datetime
import json
import smtplib
+import argparse
from email.message import EmailMessage
# Third party modules
def __init__(self, appname=None, verbose=0, version=__version__):
"""Constructor."""
+ if not getattr(self, 'description', None):
+ self.description = "Base gitlab webhook application."
+
self._appname = None
"""
@ivar: name of the current running application
self.git_ssh_url = None
self.do_sudo = True
+ self.cmdline_args = None
+
self.error_data = []
self.smtp_server = 'smtp.pixelpark.com'
self.smtp_port = 25
self._log_directory = os.sep + os.path.join('var', 'log', 'webhooks')
+ self.do_arg_parser()
+
self.read_config()
self.init_logging()
return res
+ # -------------------------------------------------------------------------
+ def do_arg_parser(self):
+
+
+ arg_parser = argparse.ArgumentParser(
+ description=self.description,
+ add_help=False,
+ )
+
+ arg_parser.add_argument(
+ "-v", "--verbose",
+ action="count",
+ dest='verbose',
+ help='Increase the verbosity level',
+ )
+
+ arg_parser.add_argument(
+ "-h", "--help",
+ action='help',
+ dest='help',
+ help='Show this help message and exit'
+ )
+
+ arg_parser.add_argument(
+ "--usage",
+ action='store_true',
+ dest='usage',
+ help="Display brief usage message and exit"
+ )
+
+ arg_parser.add_argument(
+ "-V", '--version',
+ action='version',
+ version='Version of %(prog)s: {}'.format(self.version),
+ help="Show program's version number and exit"
+ )
+
+ self.cmdline_args = arg_parser.parse_args()
+
+ if self.cmdline_args.usage:
+ arg_parser.print_usage(sys.stdout)
+ sys.exit(0)
+
+ if self.cmdline_args.verbose is not None:
+ if self.cmdline_args.verbose > self.verbose:
+ self.verbose = self.cmdline_args.verbose
+ if self.cmdline_args.verbose > self._start_verbose:
+ self._start_verbose = self.cmdline_args.verbose
+
# -------------------------------------------------------------------------
def read_config(self):
"""Reading configuration from different YAML files."""
"""Constructor."""
self.ignore_projects = []
+ self.description = textwrap.dedent('''\
+ Receives push events as JSON-Data and synchronizes
+ the local repository and deploys it with r10k.
+ ''').strip()
super(R10kHookApp, self).__init__(
appname=appname, verbose=verbose, version=version)