#!/bin/env python3
# -*- coding: utf-8 -*-
-__version__ = '0.11.4'
+__version__ = '0.12.1'
# vim: ts=4 et list
from email.message import EmailMessage
# Third party modules
+import six
import yaml
import pytz
from .handler import BaseHandler
+from .module_info import ModuleInfo
+
+from .module_list import ModuleInfoDict
+
__version__ = webhooks.__version__
LOG = logging.getLogger(__name__)
default_output_type = 'txt'
default_mime_type = valid_output_types[default_output_type]
+ open_args = {}
+ if six.PY3:
+ open_args = {
+ 'encoding': 'utf-8',
+ 'errors': 'surrogateescape',
+ }
+
# -------------------------------------------------------------------------
def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__):
"""Constructor."""
res['mime_type'] = self.mime_type
res['html_title'] = self.html_title
res['no_error_mail'] = self.no_error_mail
+ res['open_args'] = self.open_args
return res
self.__class__.__name__)
raise NotImplementedError(msg)
+ # -------------------------------------------------------------------------
+ def read_cache_file(self, only_main_branches=True):
+
+ LOG.debug("Searching for {!r} ...".format(self.cachefile))
+ if not os.path.exists(self.cachefile):
+ raise ShowModulesUncriticalError(
+ "Cache file {!r} not found.".format(self.cachefile))
+
+ if not os.access(self.cachefile, os.R_OK):
+ raise ShowModulesUncriticalError(
+ "Cache file {!r} not readable.".format(self.cachefile))
+
+ modules = ModuleInfoDict(
+ appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
+ LOG.debug("Reading {!r} ...".format(self.cachefile))
+ try:
+ with open(self.cachefile, 'r', **self.open_args) as fh:
+ for struct in yaml.load(fh):
+ module_info = ModuleInfo.init_from_data(
+ struct, appname=self.appname, verbose=self.verbose,
+ base_dir=self.base_dir)
+ if module_info:
+ if only_main_branches:
+ in_main_branches = False
+ for branch in self.main_branches:
+ if (branch in module_info.local_versions and
+ module_info.local_versions[branch]):
+ in_main_branches = True
+ elif (branch in module_info.expected_versions and
+ module_info.expected_versions[branch]):
+ in_main_branches = True
+ if in_main_branches:
+ break
+ if not in_main_branches:
+ continue
+ if self.should_display(module_info):
+ modules.append(module_info)
+ except yaml.YAMLError as e:
+ raise ShowModulesUncriticalError(
+ "Could not evaluate content of {f!r}: {e}".format(f=self.cachefile, e=e))
+ if self.verbose > 3:
+ LOG.debug("Content of {f!r}:\n{c}".format(f=self.cachefile, c=pp(modules.as_list())))
+ if not len(modules):
+ LOG.debug("Did not found any matching modules.")
+
+ return modules
+
# =============================================================================
default_http_timeout = 30
max_http_timeout = 600
- open_args = {}
- if six.PY3:
- open_args = {
- 'encoding': 'utf-8',
- 'errors': 'surrogateescape',
- }
-
# -------------------------------------------------------------------------
def __init__(self, appname=None, verbose=0, version=__version__):
"""Constructor."""
res['default_http_timeout'] = self.default_http_timeout
res['max_http_timeout'] = self.max_http_timeout
res['default_puppet_root_env_dir'] = self.default_puppet_root_env_dir
- res['open_args'] = self.open_args
res['do_forge'] = self.do_forge
return res
Class for the application objects.
"""
- open_args = {}
- if six.PY3:
- open_args = {
- 'encoding': 'utf-8',
- 'errors': 'surrogateescape',
- }
-
main_branches = ('development', 'test', 'production')
# -------------------------------------------------------------------------
returns a list with all used Puppet modules
''').strip()
- #self.cache_file = None
self._output_type = output_type
self.filters = None
res = super(ShowModulesApp, self).as_dict(short=short)
- res['open_args'] = self.open_args
res['main_branches'] = copy.copy(self.main_branches)
return res
def post_init(self):
self.read_stdin = False
- #self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
self.init_filters()
self.no_error_mail = True
LOG.debug("Output data:\n{}".format(pp(output_data)))
return output_data
- # -------------------------------------------------------------------------
- def read_cache_file(self, only_main_branches=True):
-
- LOG.debug("Searching for {!r} ...".format(self.cachefile))
- if not os.path.exists(self.cachefile):
- raise ShowModulesUncriticalError(
- "Cache file {!r} not found.".format(self.cachefile))
-
- if not os.access(self.cachefile, os.R_OK):
- raise ShowModulesUncriticalError(
- "Cache file {!r} not readable.".format(self.cachefile))
-
- modules = ModuleInfoDict(
- appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
-
- LOG.debug("Reading {!r} ...".format(self.cachefile))
- try:
- with open(self.cachefile, 'r', **self.open_args) as fh:
- for struct in yaml.load(fh):
- module_info = ModuleInfo.init_from_data(
- struct, appname=self.appname, verbose=self.verbose,
- base_dir=self.base_dir)
- if module_info:
- if only_main_branches:
- in_main_branches = False
- for branch in self.main_branches:
- if (branch in module_info.local_versions and
- module_info.local_versions[branch]):
- in_main_branches = True
- elif (branch in module_info.expected_versions and
- module_info.expected_versions[branch]):
- in_main_branches = True
- if in_main_branches:
- break
- if not in_main_branches:
- continue
- if self.should_display(module_info):
- modules.append(module_info)
- except yaml.YAMLError as e:
- raise ShowModulesUncriticalError(
- "Could not evaluate content of {f!r}: {e}".format(f=self.cachefile, e=e))
- if self.verbose > 3:
- LOG.debug("Content of {f!r}:\n{c}".format(f=self.cachefile, c=pp(modules.as_list())))
- if not len(modules):
- LOG.debug("Did not found any matching modules.")
-
- return modules
-
# -------------------------------------------------------------------------
def should_display(self, module_info):