import py_module.docker as docker
from .base import Base
from .export_log import Export_log
from .code_stub import Code_stub
from .mail_maintenance import Mail_maintenance
from .team_update import Team_Update
from .cs_update import CS_Update
from .ds_update import DS_Update
from .cert_generator_trusted import Trusted_Cert_Generator
from .docker_installer import Docker_installer
from .cert_generator import Cert_Generator
class Maintenance(Base):
    def preload(self):
        self.logger.info('Проверяю наличие Docker-среды');
        with Docker_installer() as run:
            pass
        self.dockercli = docker.from_env();
        self.semaphore = ["Выберите необходимое действие:",
            [
                {
                    "lang": "Собрать логи для техподдержки",
                    "exec": Export_log,
                    "msg": "Произвожу сбор логов",
                    "logger_name": "Logs_farmer",
                    "logger_level": self.logger_level
                },
                # {
                #     "lang": "Генерация сертификата",
                #     "exec": Cert_Generator,
                #     "logger_name": "Cert_Generator",
                #     "logger_level": self.logger_level,
                # },                
                # {
                #     "lang": "Генерация сертификата trusted.crt для Р7-Команда",
                #     "exec": Trusted_Cert_Generator,
                #     "logger_name": "Cert_Generator",
                #     "logger_level": self.logger_level,
                # },
            ]
        ];
        containers = self.dockercli.containers.list();
        for container in containers:
            if 'mail-server' in container.attrs.get('Config').get('Image') and container.status == 'running':
                self.semaphore[1].append(
                    {
                        "lang": "Обслуживание почтового ящика",
                        "exec": Mail_maintenance,
                        "logger_name": "Stop",
                        "logger_level": self.logger_level
                    }
                )
