From: Frank Brehm Date: Fri, 14 Sep 2018 13:08:58 +0000 (+0200) Subject: Applying flake8 to lib/webhooks/base_app.py X-Git-Tag: 1.6.4^2~120 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=f1a1d74379745ee6f8348d7fe459552c2bf1f60d;p=pixelpark%2Fpuppetmaster-webhooks.git Applying flake8 to lib/webhooks/base_app.py --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index cb0ae01..847cf0d 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.0.1' +__version__ = '1.1.0' # vim: ts=4 et list diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index 9b8e7e2..63f02af 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -558,6 +558,12 @@ class BaseHookApp(BaseObject): # ------------------------------------------------------------------------- def evaluate_config(self, config, yaml_file): + self._evaluate_general_config(config, yaml_file) + self.__evaluate_mail_config(config, yaml_file) + + # ------------------------------------------------------------------------- + def _evaluate_general_config(self, config, yaml_file): + if 'verbose' in config: try: v = int(config['verbose']) @@ -575,36 +581,12 @@ class BaseHookApp(BaseObject): if 'simulate' in config and not self.simulate: self.simulate = config['simulate'] - if 'no_error_mail' in config and not self.no_error_mail: - self.no_error_mail = to_bool(config['no_error_mail']) - if 'do_sudo' in config: self.do_sudo = to_bool(config['do_sudo']) if 'log_dir' in config and config['log_dir']: self._log_directory = config['log_dir'] - if 'default_email' in config and config['default_email']: - self.default_email = config['default_email'] - - if 'sender_address' in config and config['sender_address']: - self.sender_address = config['sender_address'] - - if 'smtp_server' in config and config['smtp_server'].strip(): - self.smtp_server = config['smtp_server'].strip() - - if 'smtp_port' in config and config['smtp_port']: - msg = "Invalid port {p!r} for SMTP in {f!r} found.".format( - p=config['smtp_port'], f=yaml_file) - try: - port = int(config['smtp_port']) - if port > 0 and port < 2**16: - self.smtp_port = port - else: - self.error_data.append(msg) - except ValueError: - self.error_data.append(msg) - if 'default_parent_dir' in config and config['default_parent_dir']: pdir = config['default_parent_dir'] if os.path.isabs(pdir): @@ -626,6 +608,33 @@ class BaseHookApp(BaseObject): elif 'cache_file' in config: self._cachefile = config['cache_file'] + # ------------------------------------------------------------------------- + def __evaluate_mail_config(self, config, yaml_file): + + if 'no_error_mail' in config and not self.no_error_mail: + self.no_error_mail = to_bool(config['no_error_mail']) + + if 'default_email' in config and config['default_email']: + self.default_email = config['default_email'] + + if 'sender_address' in config and config['sender_address']: + self.sender_address = config['sender_address'] + + if 'smtp_server' in config and config['smtp_server'].strip(): + self.smtp_server = config['smtp_server'].strip() + + if 'smtp_port' in config and config['smtp_port']: + msg = "Invalid port {p!r} for SMTP in {f!r} found.".format( + p=config['smtp_port'], f=yaml_file) + try: + port = int(config['smtp_port']) + if port > 0 and port < 2**16: + self.smtp_port = port + else: + self.error_data.append(msg) + except ValueError: + self.error_data.append(msg) + if 'mail_cc_addresses' in config: if config['mail_cc_addresses'] is None: self.mail_cc_addresses = [] @@ -1074,8 +1083,8 @@ class BaseHookApp(BaseObject): return True -# ============================================================================= +# ============================================================================= if __name__ == "__main__": pass