Ejemplo n.º 1
0
def parse(filepath):
    '''
    Parse backup config file. Returns:
        - err = 0 - OK
        - err = 1 - ERROR
        - err = 2 - WARNING: config doesn't match this machine
    '''

    # Check file is present
    if not os.path.exists(filepath):
        return None, 1, "Config file not found: {}".format(filepath)

    # Load config from filename
    parser, err, msg = confutil.config_parser_improved(filepath)
    if err:
        return None, err, msg

    # Check config matches model
    global _model
    err, msg = parser.validate(_model)
    if err:
        return None, err, '\n'.join(["Error parsing {}".format(filepath), msg])

    params = {}

    # Identity directory matches this machine ?
    id_dir = parser.get('identity', 'dir')
    if os.path.exists(id_dir):
        params['identity_dir'] = id_dir
    else:
        return None, 2, "This machine doesn't match: {}".format(id_dir)

    # Identity gsutil path
    params['gsutil'] = parser.get('identity', 'gsutil')

    err = 0
    msgs = []

    # Parse storage types
    err, msg = _parse_storages(parser, params)
    if err:
        msgs.append(msg)

    # Parse backup types
    err, msg = _parse_backups(parser, params)
    if err:
        msgs.append(msg)

    if msgs:
        err = 1

    return params, err, msgs
Ejemplo n.º 2
0
def parse(state, filepath):
    # Check file is present
    if not os.path.exists(filepath):
        return 1, "Config file not found: {}".format(filepath)

    # Load config file
    parser, err, msg = confutil.config_parser_improved(filepath)
    if err:
        return err, msg

    # Check config matches model
    global _model
    err, msg = parser.validate(_model)
    if err:
        return err, '\n'.join(["Error parsing {}".format(filepath), msg])

    # Fill in state:

    # App info
    state.name = parser.get('app', 'name')
    state.version = parser.get('app', 'version')

    # Logging
    state.log_output = parser.get('logging', 'output')
    state.log_filename_tpl = parser.get('logging', 'file')
    state.log_history_size = parser.getint('logging', 'history_size')

    # Resources
    state.dir_resources = _build_path(state.model.dir_app, parser.get('resources', 'dir'))

    # Configuration
    state.dir_config = _build_path(state.model.dir_app, parser.get('config', 'dir'))

    # Work and its subdirs: log, diag, temp
    state.dir_work = _build_path(state.model.dir_app, parser.get('work', 'dir'))
    state.dir_log = _build_path(state.dir_work, parser.get('work', 'dir_log'))
    state.dir_diagnostics = _build_path(state.dir_work, parser.get('work', 'dir_diagnostics'))
    state.dir_temp = _build_path(state.dir_work, parser.get('work', 'dir_temp'))

    # Done
    return 0, None
Ejemplo n.º 3
0
def parse(filepath):
    # Check file is present
    if not os.path.exists(filepath):
        return None, 1, "Config file not found: {}".format(filepath)

    # Load config from filename
    parser, err, msg = confutil.config_parser_improved(filepath)
    if err:
        return None, err, msg

    # Check config matches model
    global _model
    err, msg = parser.validate(_model)
    if err:
        return err, '\n'.join(["Error parsing {}".format(filepath), msg])

    # Get machine identities and find the first matching
    id_dirs = parser.get('identities', 'dirs')
    id_dirs = parseutil.split_csv_lexer(id_dirs)
    id_dir = None
    for d in id_dirs:
        if os.path.exists(d):
            id_dir = d
            break
    if not id_dir:
        return None, 1, """No matching identifying directories found,
make sure to add this machine's identifying directory into file {},
section 'identities'""".format(filepath)

    params = {}

    # First try to parse default '*' email section
    _parse_email_section(parser, '*', params)

    # Secondly, overlay possible section that matches identity
    _parse_email_section(parser, id_dir, params)

    # Validate params
    return _validate(params)