import os.path as path

import utils.config_parse_helper as cfg_help
from backup import Backup
from utils.config_parse_helper import ConfigSchema, ConfigSchemaSection, ConfigSchemaLine

EXPECTED_CONFIG_FILE = path.join(path.dirname(__file__), './mailman_backup.config')

MAILMAN_SCHEMA = ConfigSchema(
    [ ConfigSchemaSection('DEFAULT',
        [ ConfigSchemaLine('backup_paths',   True,  list,
            cfg_help.SpecialSchemaProcessing.commma_separated)
        , ConfigSchemaLine('source_machine', True,  str)
        , ConfigSchemaLine('verbose',        False, bool)
        , ConfigSchemaLine('make_dirs',      False, bool)
        ])
    , ConfigSchemaSection('RSYNC',
        [ ConfigSchemaLine('sources', True, list,
            cfg_help.SpecialSchemaProcessing.commma_separated)
        , ConfigSchemaLine('additional_args', False, list,
            cfg_help.SpecialSchemaProcessing.space_separated)
        ])
    ]
)


class MailmanBackup(Backup):

    def __init__(self, config_file=EXPECTED_CONFIG_FILE, schema=MAILMAN_SCHEMA):
        self.load_config(config_file, schema)


def main(config=EXPECTED_CONFIG_FILE, schema=MAILMAN_SCHEMA):
    mb = MailmanBackup(config, schema)
    mb.run_backup_processes()


if __name__ == "__main__":
    main()
