def _add_backup_dir_increment(parser, params, atype, name, sid): backup = {} backup['name'] = name backup['type'] = _remove_prefix(atype, name) backup['description'] = parser.get(name, 'description', sid) backup['active'] = parser.getboolean(name, 'active', sid) backup['dirstorage'] = parser.get(name, 'dirstorage', sid) backup['dir'] = parser.get(name, 'dir', sid) backup['maxupload'] = parseutil.bytesize(parser.get(name, 'maxupload', sid)) backup['includes'] = parseutil.split_csv_lexer(parser.get(name, 'includes', sid), '\n') backup['excludes'] = parseutil.split_csv_lexer(parser.get(name, 'excludes', sid), '\n') # Optional: frequency err, msg = _optional_frequency(parser, name, sid, backup) if err: return err, msg _add_to_list(params, 'backups', backup) return 0, None
def _add_backup_dir_compress(parser, params, atype, name, sid): backup = {} backup['name'] = name backup['type'] = _remove_prefix(atype, name) backup['description'] = parser.get(name, 'description', sid) backup['active'] = parser.getboolean(name, 'active', sid) backup['dirstorage'] = parser.get(name, 'dirstorage', sid) backup['history'] = parser.getint(name, 'history', sid) backup['dirs'] = parseutil.split_csv_lexer(parser.get(name, 'dirs', sid), '\n') # Optional: frequency err, msg = _optional_frequency(parser, name, sid, backup) if err: return err, msg _add_to_list(params, 'backups', backup) return 0, None
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)