tools.win_pg_dump_controller

Yohn Y. 2022-05-05 Parent:be791d354d2a

2:7c93b0305522 Go to Latest

tools.win_pg_dump_controller/win_pg_dump_controller/config.py

+ Возможность отправлять оповещения по почте

History
     1.1 --- a/win_pg_dump_controller/config.py	Fri Feb 11 23:55:12 2022 +0300
     1.2 +++ b/win_pg_dump_controller/config.py	Thu May 05 22:25:18 2022 +0300
     1.3 @@ -14,6 +14,7 @@
     1.4  
     1.5  COMMON_SECTION = 'common'
     1.6  MAIN = 'main'
     1.7 +SMTP = 'smtp'
     1.8  DEFAULT_PG_PORT = 5432
     1.9  
    1.10  
    1.11 @@ -74,7 +75,7 @@
    1.12  
    1.13              tmpl = cls(host_name=host_name, user_name=user_name, passwd=passwd, dst_dir=dst_dir, port=port)
    1.14  
    1.15 -        for _section in filter(lambda x: x not in (COMMON_SECTION, MAIN), config.sections()):
    1.16 +        for _section in filter(lambda x: x not in (COMMON_SECTION, MAIN, SMTP), config.sections()):
    1.17              yield tmpl.parse_section(config[_section])
    1.18  
    1.19  
    1.20 @@ -97,6 +98,18 @@
    1.21          self.tier2_store_days = _main_section.getint('tier2_store_days', 30)
    1.22          self.keep_logs_days = _main_section.getint('keep_logs_days', 30)
    1.23  
    1.24 +        self.smtp_server = None
    1.25 +        self.mail_from = None
    1.26 +        self.mail_to = None
    1.27 +        self.smtp_port = None
    1.28 +
    1.29 +        if _config.has_section(SMTP):
    1.30 +            _smtp_section = _config[SMTP]
    1.31 +            self.smtp_server = _smtp_section.get('smtp server')
    1.32 +            self.mail_from = _smtp_section.get('mail from')
    1.33 +            self.mail_to = _smtp_section.get('mail to', fallback='root')
    1.34 +            self.smtp_port = _smtp_section.getint('smtp port', fallback=25)
    1.35 +
    1.36          if not isdir(self.pg_bin_path):
    1.37              raise ConfigError(f'No valid directory with binnary files of PostgreSQL is set: {self.pg_bin_path}')
    1.38