From 4f76481ffcee9b9d4ea803f345972e9e21a7c680 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 7 Sep 2018 12:01:11 +0200 Subject: [PATCH] Adding get-module-changes and lib/webhooks/get_module_changes.py --- get-module-changes | 29 +++++++ lib/webhooks/__init__.py | 2 +- lib/webhooks/get_module_changes.py | 123 +++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100755 get-module-changes create mode 100644 lib/webhooks/get_module_changes.py diff --git a/get-module-changes b/get-module-changes new file mode 100755 index 0000000..f521364 --- /dev/null +++ b/get-module-changes @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Standard modules +import os +import sys +import logging + +# own modules: +basedir = os.path.abspath(os.path.dirname(__file__)) +libdir = os.path.join(basedir, 'lib') + +sys.path.insert(0, libdir) + +from webhooks.get_module_changes import GetModuleChangesApp + +MY_APPNAME = os.path.basename(sys.argv[0]) +LOG = logging.getLogger(MY_APPNAME) + +app = GetModuleChangesApp(appname=MY_APPNAME) + +if app.verbose > 2: + LOG.debug("{c} object:\n{o}".format(c=app.__class__.__name__, o=app)) + +app() + +sys.exit(0) + +# vim: ts=4 et diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index ff926e6..303ae19 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.12.2' +__version__ = '0.12.3' # vim: ts=4 et list diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py new file mode 100644 index 0000000..3863b48 --- /dev/null +++ b/lib/webhooks/get_module_changes.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2017 by Frank Brehm, Berlin +@summary: The module for the 'get-module-changes' application object. +""" +from __future__ import absolute_import + +# Standard modules +import os +import logging +import textwrap +import json +import glob +import datetime +import fcntl +import pwd +import grp +import errno +import sys + +from operator import itemgetter + +# Third party modules +import six +import yaml + +from six import reraise + +# Own modules +from . import __version__ + +from .common import pp, to_bytes, to_bool + +from .base_app import BaseHookError, UncriticalHookError, BaseHookApp + +from .module_info import ModuleInfo + +from .module_list import ModuleInfoDict + +from .puppetfile import Puppetfile, PuppetfileError + +LOG = logging.getLogger(__name__) + + +# ============================================================================= +class GetModuleChangesError(BaseHookError): + + pass + + +# ============================================================================= +class GetModuleChangesApp(BaseHookApp): + """ + Class for the application objects. + """ + + default_env = 'development' + + # ------------------------------------------------------------------------- + def __init__(self, appname=None, verbose=0, version=__version__): + """Constructor.""" + + self.description = textwrap.dedent('''\ + Generates a list of all Puppets modules, which are newer + in Puppet forge than in a defined environment + ''').strip() + + super(GetModuleChangesApp, self).__init__( + appname=appname, verbose=verbose, version=version) + + # ------------------------------------------------------------------------- + def as_dict(self, short=True): + """ + Transforms the elements of the object into a dict + + @return: structure as dict + @rtype: dict + """ + + res = super(GetModuleChangesApp, self).as_dict(short=short) + + res['default_env'] = self.default_env + + return res + + # ------------------------------------------------------------------------- + def evaluate_config(self, config, yaml_file): + + super(GetModuleChangesApp, self).evaluate_config(config, yaml_file) + + # ------------------------------------------------------------------------- + def post_init(self): + + self.read_stdin = False + self.no_error_mail = True + + self.initialized = True + + # ------------------------------------------------------------------------- + def run(self): + """Main routine.""" + + LOG.info("Here I go. ...") + module_infos = [] + try: + module_infos = self.read_cache_file(only_main_branches=False) + except UncriticalHookError as e: + LOG.error(str(e)) + self.exit(7) + + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list + -- 2.39.5