from parallels.core.logging import get_logger
from parallels.core.runners.base import BaseRunner
from parallels.plesk.source.confixx import messages
from parallels.plesk.source.legacy.pmm_agent import UnixPmmMigrationAgent

logger = get_logger(__name__)


class ConfixxPmmMigrationAgent(UnixPmmMigrationAgent):
    def __init__(self, global_context, server, migrator_dump_dir, settings):
        super(ConfixxPmmMigrationAgent, self).__init__(global_context, server, migrator_dump_dir, settings)

    def get_confixx_config_path(self):
        logger.info(messages.LOG_GET_CONFIXX_CONFIG_PATH)

        with self._source_server.runner() as runner:
            assert isinstance(runner, BaseRunner)
            path = runner.execute_command(
                u'cd {path}; {perl} ConfixxConfigPath.pl',
                {
                    'perl': self._perl_bin,
                    'path':    self.agent_dir
                }
            ).stdout.strip()
            logger.fdebug("Confixx config path = '{path}'", path=path)
            return path

    def _is_dump_agent_creates_archive(self):
        """Whether dump agent creates ready to use dump archive (ZIP or TAR). If False then agent creates plain XML.

        :rtype: bool
        """
        return False

    def _is_dump_version_upgrade_required(self):
        """Whether dump agent creates dump in old format (< 17.0), and upgrade is required to use with target Plesk 18

        :rtype: bool
        """
        return True
