#mail_cc_addresses: []
#sender_address: 'Puppetmaster <puppetmaster@pixelpark.com>'
#data_dir: '/var/lib/webhooks'
+# Relative to data_dir
+#cachefile: 'modules-info.yaml'
default_data_dir = os.sep + os.path.join('var', 'lib', 'webhooks')
default_tz_name = 'Europe/Berlin'
+ default_cachefile_stem = 'modules-info.yaml'
special_chars_re = re.compile(r'[^a-z0-9_\-]', re.IGNORECASE)
dev_re = re.compile(r'^dev')
self.tz_name = self.default_tz_name
self._html_title = None
self._no_error_mail = False
+ self._cachefile = self.default_cachefile_stem
if not hasattr(self, '_output_type'):
self._output_type = self.default_output_type
"""MIME-Typ der Response."""
return self._mime_type
+ # -----------------------------------------------------------
+ @property
+ def cachefile(self):
+ """The filename of the cacheing file."""
+
+ if os.path.isabs(self._cachefile):
+ return os.path.normpath(self._cachefile)
+ return os.path.normpath(os.path.join(self.data_dir, self._cachefile))
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['valid_output_types'] = self.valid_output_types
res['default_output_type'] = self.default_output_type
res['default_mime_type'] = self.default_mime_type
+ res['default_cachefile_stem'] = self.default_cachefile_stem
+ res['cachefile'] = self.cachefile
res['output_type'] = self.output_type
res['mime_type'] = self.mime_type
res['html_title'] = self.html_title
path = os.path.join(self.base_dir, path)
self.data_dir = path
+ if 'cachefile' in config:
+ self._cachefile = config['cachefile']
+ elif 'cache_file' in config:
+ self._cachefile = config['cache_file']
+
if 'mail_cc_addresses' in config:
if config['mail_cc_addresses'] is None:
self.mail_cc_addresses = []
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2017 by Frank Brehm, Berlin
-@summary: The module for the deploy application object.
+@summary: The module for the 'get-forge-modules' application object.
"""
from __future__ import absolute_import
def __init__(self, appname=None, verbose=0, version=__version__):
"""Constructor."""
- self.cache_file = None
+ #self.cache_file = None
self.environments = []
self.puppet_root_env_dir = self.default_puppet_root_env_dir
self.forge_uri = self.default_forge_uri
def post_init(self):
self.read_stdin = False
- self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
+ #self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
self.initialized = True
# -------------------------------------------------------------------------
def write_cache_file(self):
- output_file = os.path.join(self.data_dir, 'modules-info.yaml')
+ output_file = self.cachefile
tmp_file = output_file + '.new'
fd = None
returns a list with all used Puppet modules
''').strip()
- self.cache_file = None
+ #self.cache_file = None
self._output_type = output_type
self.filters = None
@rtype: dict
"""
- res = super(ShowModulesApp, self).as_dict()
+ res = super(ShowModulesApp, self).as_dict(short=short)
res['open_args'] = self.open_args
res['main_branches'] = copy.copy(self.main_branches)
def post_init(self):
self.read_stdin = False
- self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
+ #self.cache_file = os.path.join(self.data_dir, 'modules-info.yaml')
self.init_filters()
self.no_error_mail = True
# -------------------------------------------------------------------------
def read_cache_file(self, only_main_branches=True):
- LOG.debug("Searching for {!r} ...".format(self.cache_file))
- if not os.path.exists(self.cache_file):
+ LOG.debug("Searching for {!r} ...".format(self.cachefile))
+ if not os.path.exists(self.cachefile):
raise ShowModulesUncriticalError(
- "Cache file {!r} not found.".format(self.cache_file))
+ "Cache file {!r} not found.".format(self.cachefile))
- if not os.access(self.cache_file, os.R_OK):
+ if not os.access(self.cachefile, os.R_OK):
raise ShowModulesUncriticalError(
- "Cache file {!r} not readable.".format(self.cache_file))
+ "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.cache_file))
+ LOG.debug("Reading {!r} ...".format(self.cachefile))
try:
- with open(self.cache_file, 'r', **self.open_args) as fh:
+ 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,
modules.append(module_info)
except yaml.YAMLError as e:
raise ShowModulesUncriticalError(
- "Could not evaluate content of {f!r}: {e}".format(f=self.cache_file, e=e))
+ "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.cache_file, c=pp(modules.as_list())))
+ 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.")