main_branches = ('development', 'test', 'production')
# -------------------------------------------------------------------------
- def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__):
+ def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__, no_cc=False):
"""Constructor."""
if not base_dir:
self.default_parent_dir = '/var/log/webhooks'
self.default_email = DEFAULT_TO_EMAIL
self.mail_to_addresses = []
- self.mail_cc_addresses = [
- self.default_email,
- ]
+ self.mail_cc_addresses = []
+ if not no_cc:
+ self.mail_cc_addresses = [self.default_email,]
self.sender_address = DEFAULT_FROM_SENDER
self._log_directory = os.sep + os.path.join('var', 'log', 'webhooks')
s=s, a=self.appname)
subject = 'Puppetmaster error{s} processing {a!r}'.format(
s=s, a=self.appname)
- body += '\n\n'.join(self.error_data)
+ body += '\n'.join(self.error_data)
body += '\n\nCheers\nPuppetmaster'
msg.set_content(body)
msg.set_charset('utf-8')
self._environment = self.default_env
super(GetModuleChangesApp, self).__init__(
- appname=appname, verbose=verbose, version=version)
+ appname=appname, verbose=verbose, version=version, no_cc=True)
# -----------------------------------------------------------
@property
self.exit(7)
version_infos = self.get_newer_modules(module_infos)
+ self.generate_version_msgs(version_infos)
# -------------------------------------------------------------------------
def get_newer_modules(self, module_infos):
return version_infos
+ # -------------------------------------------------------------------------
+ def generate_version_msgs(self, version_infos):
+
+ if not version_infos:
+ msg = (
+ "Didn't found any modules in environment {!r} with a\n"
+ "newer version on Puppet Forge.\n\n:-D"
+ ).format(self.environment)
+ self.error_data.append(msg)
+ return
+
+ s = ''
+ if len(version_infos) != 1:
+ s = 's'
+
+ self.error_data.append((
+ "Found {n} module{s} in environment {e!r} with a "
+ "newer version on Puppet Forge.\n\n:-(\n").format(
+ n=len(version_infos), s=s, e=self.environment))
+
+ label = {
+ 'name': 'Module',
+ 'full_name': 'Full Module name',
+ 'local_version': 'Used Version',
+ 'forge_version': 'Version on Puppet Forge',
+ }
+ width = {}
+ for key in label.keys():
+ width[key] = len(label[key])
+
+ for version_info in version_infos:
+ for key in label.keys():
+ if len(str(version_info[key])) > width[key]:
+ width[key] = len(str(version_info[key]))
+
+ len_total = 0
+ first = True
+ for key in width.keys():
+ len_total += width[key]
+ if not first:
+ len_total += 3
+ first = False
+
+ template = "{{name:<{name}}} | "
+ template += "{{full_name:<{full_name}}} | "
+ template += "{{local_version:<{local_version}}} | "
+ template += "{{forge_version:<{forge_version}}}"
+
+ template = template.format(**width)
+
+ if self.verbose > 2:
+ LOG.debug("Zeilen-Template:\n{}".format(template))
+ LOG.debug("Zeilen-Länge: {}".format(len_total))
+
+ title = template.format(**label)
+ self.error_data.append(title)
+ self.error_data.append('=' * len_total)
+
+ for version_info in version_infos:
+ self.error_data.append(template.format(
+ name=version_info['name'], full_name=version_info['full_name'],
+ local_version=str(version_info['local_version']),
+ forge_version=str(version_info['forge_version'])
+ ))
+
# =============================================================================
if __name__ == "__main__":