import os.path as path

from utils.config_parse_helper import SpecialSchemaProcessing
from backup import Backup
from utils.config_parse_helper import ConfigSchema, ConfigSchemaSection, ConfigSchemaLine

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

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


class SvnBackup(Backup):

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


def main(config=EXPECTED_CONFIG_FILE, schema=SVN_SCHEMA):
    sb = SvnBackup(config, schema)
    sb.run_backup_processes()


if __name__ == "__main__":
    main()
