From: Frank Brehm Date: Fri, 24 Aug 2018 13:21:18 +0000 (+0200) Subject: Adding lib/webhooks/show_modules.py and show-modules X-Git-Tag: 0.10.7^2~10 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=03ccdd2c0b7e29d795c39ac7798bdc629265e5b6;p=pixelpark%2Fpuppetmaster-webhooks.git Adding lib/webhooks/show_modules.py and show-modules --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 7f386bf..7c3b277 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.9.10' +__version__ = '0.10.0' # vim: ts=4 et list diff --git a/lib/webhooks/get_forge_modules.py b/lib/webhooks/get_forge_modules.py index 4dd22eb..ccbf230 100644 --- a/lib/webhooks/get_forge_modules.py +++ b/lib/webhooks/get_forge_modules.py @@ -94,7 +94,7 @@ class GetForgeModulesApp(BaseHookApp): def post_init(self): self.read_stdin = False - self.cache_file = os.path.join(self.data_dir, self.appname + '.yaml') + self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml') self.initialized = True diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py new file mode 100644 index 0000000..da70f14 --- /dev/null +++ b/lib/webhooks/show_modules.py @@ -0,0 +1,90 @@ +#!/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 show-module CGI application to show + information about all Puppet modules from cache. +""" +from __future__ import absolute_import + +# Standard modules +import os +import logging +import textwrap +import copy + +# Third party modules + +# Own modules +from . import __version__ + +from .common import pp, to_str + +from .base_app import BaseHookApp + +LOG = logging.getLogger(__name__) + +DEFAULT_PARENT_DIR = '/etc/puppetlabs/code/fileserver' + + +# ============================================================================= +class ShowModulesApp(BaseHookApp): + """ + Class for the application objects. + """ + + # ------------------------------------------------------------------------- + def __init__(self, appname=None, verbose=0, version=__version__): + """Constructor.""" + + self.description = textwrap.dedent('''\ + returns a list with all used Puppet modules + ''').strip() + + self.cache_file = None + + super(ShowModulesApp, 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(ShowModulesApp, self).as_dict() +# +# return res + + # ------------------------------------------------------------------------- + def evaluate_config(self, config, yaml_file): + + super(ShowModulesApp, self).evaluate_config(config, yaml_file) + + # ------------------------------------------------------------------------- + def post_init(self): + + self.read_stdin = False + self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml') + + self.initialized = True + + # ------------------------------------------------------------------------- + def run(self): + """Main routine.""" + + self.print_out("Hallo!") + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list diff --git a/show-modules b/show-modules new file mode 100755 index 0000000..8b7eb7f --- /dev/null +++ b/show-modules @@ -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.show_modules import ShowModulesApp + +MY_APPNAME = os.path.basename(sys.argv[0]) +LOG = logging.getLogger(MY_APPNAME) + +app = ShowModulesApp(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