]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Fixing syntax errors and applying flake8 rules
authorFrank Brehm <frank@brehm-online.com>
Sun, 27 Mar 2022 14:32:17 +0000 (16:32 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 27 Mar 2022 14:32:17 +0000 (16:32 +0200)
lib/pp_admintools/mail_app.py
lib/pp_admintools/mail_config.py
lib/pp_admintools/pdns_config.py

index daa264d5788a628d5ca48ba190e2b0a9e51fc5cc..0f7074811d2b220c3a183144682b914c14c7ed78 100644 (file)
@@ -11,6 +11,7 @@ from __future__ import absolute_import
 import logging
 import copy
 import pipes
+import os
 
 from email.mime.text import MIMEText
 from email import charset
@@ -32,10 +33,12 @@ from fb_tools.xlate import format_list
 
 from .xlate import XLATOR
 
-from .mail_config import MailConfigError, MailConfiguration
+from .mail_config import MailConfiguration
 from .mail_config import VALID_MAIL_METHODS, MAX_PORT_NUMBER
 
-__version__ = '0.2.1'
+from .mailaddress import MailAddress
+
+__version__ = '0.2.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -122,7 +125,7 @@ class BaseMailApplication(FbConfigApplication):
     def _perform_cmdline_mail_rcpt(self):
 
         v = getattr(self.args, 'mail_recipients', None)
-        if v not None:
+        if v is None:
             return
 
         recipients = []
@@ -136,7 +139,7 @@ class BaseMailApplication(FbConfigApplication):
 
         if bad_rcpts:
             msg = _("Got invalid recipient mail addresses:")
-            msg += " " + format_list(bad_rcpts, do_repr=True)
+            msg += " " + format_list(bad_rcpts, do_repr=True)
             LOG.error(msg)
             self.exit(1)
 
@@ -164,7 +167,7 @@ class BaseMailApplication(FbConfigApplication):
 
         if bad_cc:
             msg = _("Got invalid cc mail addresses:")
-            msg += " " + format_list(bad_cc, do_repr=True)
+            msg += " " + format_list(bad_cc, do_repr=True)
             LOG.error(msg)
             self.exit(1)
 
@@ -196,7 +199,7 @@ class BaseMailApplication(FbConfigApplication):
 
         mail_group.add_argument(
             '--from', '--mail-from',
-             metavar=_("ADDRESS"), dest="mail_from",
+            metavar=_("ADDRESS"), dest="mail_from",
             help=_(
                 "Sender mail address for mails generated by this script. "
                 "Default: {!r}").format(self.cfg.mail_from),
@@ -244,7 +247,8 @@ class BaseMailApplication(FbConfigApplication):
             metavar=_("PORT"), type=int, dest='smtp_port',
             help=_(
                 "The port to use for submitting generated by this script if "
-                "the mail method of this script is 'smtp'. Default: {}.").format(self.cfg.smtp_port)
+                "the mail method of this script is 'smtp'. Default: {}.").format(
+                self.cfg.smtp_port)
         )
 
     # -------------------------------------------------------------------------
index d650762f2e70c537bae0d08e796175216d3280a0..0363b59dac3216e013a1d25cbebf6e706eb2a827 100644 (file)
@@ -14,14 +14,14 @@ import logging
 import pwd
 import re
 import copy
-
-from numbers import Number
+import os
+import socket
 
 # Third party modules
 
 # Own modules
 
-from fb_tools.common import is_sequence
+from fb_tools.common import is_sequence, pp
 
 # from .config import ConfigError, BaseConfiguration
 from fb_tools.multi_config import MultiConfigError, BaseMultiConfig
@@ -33,14 +33,14 @@ from .mailaddress import MailAddress
 
 from .xlate import XLATOR
 
-__version__ = '0.1.3'
+__version__ = '0.1.4'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
 
 DEFAULT_CONFIG_DIR = 'pixelpark'
 VALID_MAIL_METHODS = ('smtp', 'sendmail')
-MAX_PORT_NUMBER = (2 ** 16) -1
+MAX_PORT_NUMBER = (2 ** 16) - 1
 
 
 # =============================================================================
@@ -293,7 +293,7 @@ class MailConfiguration(BaseMultiConfig):
         re_method = re.compile(r'^\s*(mail[_-]?)?method\s*$', re.IGNORECASE)
 
         for key in section.keys():
-            if not re_reply.search(key):
+            if not re_method.search(key):
                 continue
 
             val = section[key].strip().lower()
@@ -331,11 +331,12 @@ class MailConfiguration(BaseMultiConfig):
             if not re_server.search(key):
                 continue
 
-            val = section[[key]
+            val = section[key]
             try:
                 port = int(val)
             except (ValueError, TypeError) as e:
                 msg = _("Value {!r} for SMTP port is invalid:").format(val)
+                msg += ' ' + str(e)
                 LOG.error(msg)
                 continue
             if port <= 0 or port > MAX_PORT_NUMBER:
@@ -345,6 +346,7 @@ class MailConfiguration(BaseMultiConfig):
 
             self.smtp_port = port
 
+
 # =============================================================================
 if __name__ == "__main__":
 
index 0b6de91e72981ace4994f8ddda2aec87b161512e..276e2a52111f16af9b4e178d136f11496338891d 100644 (file)
@@ -12,20 +12,16 @@ from __future__ import absolute_import
 
 # Standard module
 import logging
-import pwd
 import re
 import copy
 
-from numbers import Number
-
 # Third party modules
 
 # Own modules
 
-from fb_tools.common import is_sequence
+from fb_tools.common import is_sequence, pp
 
 # from .config import ConfigError, BaseConfiguration
-from fb_tools.multi_config import MultiConfigError
 from fb_tools.multi_config import DEFAULT_ENCODING
 
 from .mail_config import MailConfigError, MailConfiguration
@@ -35,7 +31,7 @@ from .xlate import XLATOR
 
 MAX_PDNS_API_TIMEOUT = 3600
 
-__version__ = '0.1.1'
+__version__ = '0.1.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -183,12 +179,13 @@ class PdnsConfiguration(MailConfiguration):
             val = section[key]
             try:
                 timeout = int(val)
+                if timeout <= 0 or timeout > MAX_PDNS_API_TIMEOUT:
+                    msg = _("A timeout has to be between 1 and {} seconds.")
+                    msg = msg.format(MAX_PDNS_API_TIMEOUT)
+                    raise ValueError(msg)
             except (ValueError, TypeError) as e:
                 msg = _("Value {!r} for PowerDNS API timeout is invalid:").format(val)
-                LOG.error(msg)
-                continue
-            if timeout <= 0 or port > MAX_PDNS_API_TIMEOUT:
-                msg = _("Value {!r} for PowerDNS API timeout is invalid:").format(timeout)
+                msg += " " + str(e)
                 LOG.error(msg)
                 continue
 
@@ -223,9 +220,9 @@ class PdnsConfiguration(MailConfiguration):
     # -------------------------------------------------------------------------
     def _eval_pdns_inst_host(self, iname, section):
 
-        if self.verbose > 2
+        if self.verbose > 2:
             msg = _("Searching for host for PDNS instance {!r} ..")
-            LOG.debug(msg.format(iname)
+            LOG.debug(msg.format(iname))
 
         for key in section.keys():
             if key.lower() == 'host':
@@ -239,9 +236,9 @@ class PdnsConfiguration(MailConfiguration):
     # -------------------------------------------------------------------------
     def _eval_pdns_inst_port(self, iname, section):
 
-        if self.verbose > 2
+        if self.verbose > 2:
             msg = _("Searching for post number for PDNS instance {!r} ..")
-            LOG.debug(msg.format(iname)
+            LOG.debug(msg.format(iname))
 
         for key in section.keys():
             if key.lower() == 'port':
@@ -251,7 +248,7 @@ class PdnsConfiguration(MailConfiguration):
                     port = int(val)
                     if port <= 0 or port > MAX_PORT_NUMBER:
                         msg = _("A port must be greater than 0 and less than {}.")
-                        raise ValueError(msg.format(MAX_PORT_NUMBER)
+                        raise ValueError(msg.format(MAX_PORT_NUMBER))
                 except (TypeError, ValueError) as e:
                     msg = _("Wrong port number {p!r} for PDNS instance {inst!r} found: {e}")
                     msg = msg.format(p=val, inst=iname, e=e)
@@ -269,9 +266,9 @@ class PdnsConfiguration(MailConfiguration):
     # -------------------------------------------------------------------------
     def _eval_pdns_inst_servername(self, iname, section):
 
-        if self.verbose > 2
+        if self.verbose > 2:
             msg = _("Searching for internal server name of PDNS instance {!r} ..")
-            LOG.debug(msg.format(iname)
+            LOG.debug(msg.format(iname))
 
         re_servername = re.compile(r'^\s*server[_-]?(name|id)\s*$', re.IGNORECASE)
 
@@ -287,9 +284,9 @@ class PdnsConfiguration(MailConfiguration):
     # -------------------------------------------------------------------------
     def _eval_pdns_inst_key(self, iname, section):
 
-        if self.verbose > 2
+        if self.verbose > 2:
             msg = _("Searching for API key of PDNS instance {!r} ..")
-            LOG.debug(msg.format(iname)
+            LOG.debug(msg.format(iname))
 
         re_key = re.compile(r'^\s*(api[_-]?)?key\s*$', re.IGNORECASE)