import traceback
import textwrap
import datetime
+import copy
import json
# Third party modules
from .merge import merge_structure
+from .mailaddress import MailAddress
+
from .app import PpApplication
-__version__ = '0.4.4'
+__version__ = '0.5.1'
LOG = logging.getLogger(__name__)
+VALID_MAIL_METHODS = ('smtp', 'sendmail')
+
# =============================================================================
class PpCfgAppError(PpAppError):
Class for configured application objects.
"""
+ default_mail_recipients = [
+ 'frank.brehm@pixelpark.com'
+ ]
+ default_mail_cc = [
+ 'thomas.kotschok@pixelpark.com',
+ ]
+
+ default_reply_to = 'frank.brehm@pixelpark.com'
+
+ default_mail_server = 'mx.pixelpark.net'
+
+ whitespace_re = re.compile(r'(?:[,;]+|\s*[,;]*\s+)')
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
self.cfg_files = []
self.log_cfg_files = []
+ self.mail_recipients = copy.copy(self.default_mail_recipients)
+ self.mail_cc = copy.copy(self.default_mail_cc)
+ self.reply_to = self.default_reply_to
+ self.mail_server = self.default_mail_server
+ self.mail_method = 'smtp'
+
super(PpConfigApplication, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
initialized=False, usage=usage, description=description,
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
+ for section_name in self.cfg.keys():
+
+ if self.verbose > 3:
+ LOG.debug("Checking config section {!r} ...".format(section_name))
+
+ if section_name.lower() != "mail":
+ continue
+ section = self.cfg[section_name]
+
+ if 'mail_recipients' in section:
+ v = section['mail_recipients'].strip()
+ self.mail_recipients = []
+ tokens = self.whitespace_re.split(v)
+ for token in tokens:
+ if MailAddress.valid_address(token):
+ if token not in self.mail_recipients:
+ self.mail_recipients.append(token)
+ else:
+ msg = "Found invalid recipient mail address {!r} in configuration.".format(
+ token)
+ LOG.error(msg)
+
+ if 'mail_cc' in section:
+ v = section['mail_cc'].strip()
+ self.mail_cc = []
+ tokens = self.whitespace_re.split(v)
+ for token in tokens:
+ if MailAddress.valid_address(token):
+ if token not in self.mail_cc:
+ self.mail_cc.append(token)
+ else:
+ msg = "Found invalid cc mail address {!r} in configuration.".format(
+ token)
+ LOG.error(msg)
+
+ if 'reply_to' in section:
+ v = section['reply_to'].strip()
+ self.reply_to = None
+ tokens = self.whitespace_re.split(v)
+ if len(tokens):
+ if MailAddress.valid_address(tokens[0]):
+ self.reply_to = tokens[0]
+ else:
+ msg = "Found invalid reply mail address {!r} in configuration.".format(
+ tokens[0])
+ LOG.error(msg)
+
+ if 'mail_server' in section:
+ v = section['reply_to'].strip()
+ if v:
+ self.mail_server = v
+
+ if 'mail_method' in section:
+ v = section['mail_method'].strip().lower()
+ if v:
+ if v in VALID_MAIL_METHODS:
+ self.mail_method = v
+ else:
+ msg = "Found invalid mail method {!r} in configuration.".format(
+ section['mail_method'])
+ LOG.error(msg)
+
self.perform_config()
# -------------------------------------------------------------------------
from .cfg_app import PpCfgAppError, PpConfigApplication
-__version__ = '0.4.1'
+__version__ = '0.4.2'
LOG = logging.getLogger(__name__)
# /etc/pixelpark/exclude_homes
default_exclude_file = os.sep + os.path.join('etc', 'pixelpark', 'exclude_homes')
- default_mail_recipients = [
- 'frank.brehm@pixelpark.com'
- ]
- default_mail_cc = [
- 'thomas.kotschok\@pixelpark.com',
- ]
-
- default_reply_to = 'frank.brehm@pixelpark.com'
-
comment_re = re.compile(r'\s*#.*')
- whitespace_re = re.compile(r'(?:[,;]+|\s*[,;]*\s+)')
# -------------------------------------------------------------------------
def __init__(self, appname=None, version=__version__):
self.exclude_file = self.default_exclude_file
- self.mail_recipients = copy.copy(self.default_mail_recipients)
- self.mail_cc = copy.copy(self.default_mail_cc)
- self.reply_to = self.default_reply_to
-
self.exclude_dirs = []
self.passwd_home_dirs = []
self.unnecessary_dirs = []
for section_name in self.cfg.keys():
- if self.verbose > 2:
+ if self.verbose > 3:
LOG.debug("Checking config section {!r} ...".format(section_name))
if section_name.lower() not in ('test-home', 'test_home', 'testhome') :