import logging
import copy
import pipes
+import os
from email.mime.text import MIMEText
from email import charset
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
def _perform_cmdline_mail_rcpt(self):
v = getattr(self.args, 'mail_recipients', None)
- if v not None:
+ if v is None:
return
recipients = []
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)
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)
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),
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)
)
# -------------------------------------------------------------------------
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
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
# =============================================================================
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()
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:
self.smtp_port = port
+
# =============================================================================
if __name__ == "__main__":
# 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
MAX_PDNS_API_TIMEOUT = 3600
-__version__ = '0.1.1'
+__version__ = '0.1.2'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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
# -------------------------------------------------------------------------
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':
# -------------------------------------------------------------------------
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':
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)
# -------------------------------------------------------------------------
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)
# -------------------------------------------------------------------------
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)