Breaking borgmatic command main() apart, since it was getting a little unwieldy.
This commit is contained in:
parent
6e9e7c45d7
commit
f13ed92b0e
1 changed files with 40 additions and 32 deletions
|
@ -79,28 +79,20 @@ def parse_arguments(*arguments):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main(): # pragma: no cover
|
def run_configuration(config_filename, args): # pragma: no cover
|
||||||
try:
|
'''
|
||||||
args = parse_arguments(*sys.argv[1:])
|
Parse and single configuration file, and execute its defined pruning, backups, and/or consistency
|
||||||
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
checks.
|
||||||
|
'''
|
||||||
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
|
||||||
logger.debug('Ensuring legacy configuration is upgraded')
|
|
||||||
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
|
||||||
|
|
||||||
if len(config_filenames) == 0:
|
|
||||||
raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths)))
|
|
||||||
|
|
||||||
for config_filename in config_filenames:
|
|
||||||
logger.info('{}: Parsing configuration file'.format(config_filename))
|
logger.info('{}: Parsing configuration file'.format(config_filename))
|
||||||
config = validate.parse_configuration(config_filename, validate.schema_filename())
|
config = validate.parse_configuration(config_filename, validate.schema_filename())
|
||||||
(location, storage, retention, consistency, hooks) = (
|
(location, storage, retention, consistency, hooks) = (
|
||||||
config.get(section_name, {})
|
config.get(section_name, {})
|
||||||
for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
|
for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
|
||||||
)
|
)
|
||||||
remote_path = location.get('remote_path')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
remote_path = location.get('remote_path')
|
||||||
create.initialize(storage)
|
create.initialize(storage)
|
||||||
hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup')
|
hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup')
|
||||||
|
|
||||||
|
@ -124,6 +116,22 @@ def main(): # pragma: no cover
|
||||||
except (OSError, CalledProcessError):
|
except (OSError, CalledProcessError):
|
||||||
hook.execute_hook(hooks.get('on_error'), config_filename, 'on-error')
|
hook.execute_hook(hooks.get('on_error'), config_filename, 'on-error')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def main(): # pragma: no cover
|
||||||
|
try:
|
||||||
|
args = parse_arguments(*sys.argv[1:])
|
||||||
|
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
||||||
|
|
||||||
|
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||||
|
logger.debug('Ensuring legacy configuration is upgraded')
|
||||||
|
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
||||||
|
|
||||||
|
if len(config_filenames) == 0:
|
||||||
|
raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths)))
|
||||||
|
|
||||||
|
for config_filename in config_filenames:
|
||||||
|
run_configuration(config_filename, args)
|
||||||
except (ValueError, OSError, CalledProcessError) as error:
|
except (ValueError, OSError, CalledProcessError) as error:
|
||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in a new issue