コード例 #1
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_archive_with_mount():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--config', 'myconfig', 'mount', '--archive',
                           'test', '--mount-point', '/mnt')
コード例 #2
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_disallows_glob_archives_with_successful():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    with pytest.raises(ValueError):
        module.parse_arguments(
            '--config', 'myconfig', 'list', '--glob-archives', '*glob*', '--successful'
        )
コード例 #3
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_paths_unless_action_consumes_it():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', '--path', 'test')
コード例 #4
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_init_and_create():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--config', 'myconfig', 'init', '--encryption',
                           'repokey', 'create')
コード例 #5
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_repository_with_list():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--config', 'myconfig', 'list', '--repository',
                           'test.borg')
コード例 #6
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_storage_quota_without_init():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', '--storage-quota', '5G')
コード例 #7
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_append_only_without_init():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', '--append-only')
コード例 #8
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_encryption_mode_with_dashed_init():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--config', 'myconfig', '--init', '--encryption',
                           'repokey')
コード例 #9
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_disallows_init_and_dry_run():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    with pytest.raises(ValueError):
        module.parse_arguments(
            '--config', 'myconfig', 'init', '--encryption', 'repokey', '--dry-run'
        )
コード例 #10
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_archive_with_dashed_restore():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--config', 'myconfig', '--restore', '--archive',
                           'test')
コード例 #11
0
def test_parse_arguments_disallows_archive_without_extract_or_list():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', '--archive', 'test')
コード例 #12
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_extract_archive_check_does_not_raise_check_subparser_error(
):
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('extract', '--archive', 'check')
コード例 #13
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_extract_with_check_only_extract_does_not_raise():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('extract', '--archive', 'name', 'check', '--only',
                           'extract')
コード例 #14
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_json_with_list_or_info():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('list', '--json')
    module.parse_arguments('info', '--json')
コード例 #15
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_json_with_both_list_and_info():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(ValueError):
        module.parse_arguments('list', 'info', '--json')
コード例 #16
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_with_invalid_arguments_exits():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--posix-me-harder')
コード例 #17
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_progress_without_create():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--progress', 'list')
コード例 #18
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_allows_progress_and_restore():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    module.parse_arguments('--progress', 'restore', '--archive', 'test',
                           'list')
コード例 #19
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_requires_mount_point_with_umount():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', 'umount')
コード例 #20
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_deprecated_excludes_option():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(ValueError):
        module.parse_arguments('--config', 'myconfig', '--excludes',
                               'myexcludes')
コード例 #21
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_disallows_encryption_mode_without_init():
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--config', 'myconfig', '--encryption',
                               'repokey')
コード例 #22
0
ファイル: test_arguments.py プロジェクト: wellic/borgmatic
def test_parse_arguments_with_files_flag_but_no_create_or_prune_or_restore_flag_raises_value_error(
):
    flexmock(
        module.collect).should_receive('get_default_config_paths').and_return(
            ['default'])

    with pytest.raises(SystemExit):
        module.parse_arguments('--files', 'list')
コード例 #23
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_help_and_no_actions_shows_global_help(capsys):
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    with pytest.raises(SystemExit) as exit:
        module.parse_arguments('--help')

    assert exit.value.code == 0
    captured = capsys.readouterr()
    assert 'global arguments:' in captured.out
    assert 'actions:' in captured.out
コード例 #24
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_multiple_overrides_parses():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    arguments = module.parse_arguments('--override', 'foo.bar=baz', 'foo.quux=7')

    global_arguments = arguments['global']
    assert global_arguments.overrides == ['foo.bar=baz', 'foo.quux=7']
コード例 #25
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    arguments = module.parse_arguments()

    assert 'prune' in arguments
    assert 'create' in arguments
    assert 'check' in arguments
コード例 #26
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_multiple_dashed_actions_leaves_other_action_disabled():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    arguments = module.parse_arguments('--create', '--check')

    assert 'prune' not in arguments
    assert 'create' in arguments
    assert 'check' in arguments
コード例 #27
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_multiple_config_paths_parses_as_list():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    arguments = module.parse_arguments('--config', 'myconfig', 'otherconfig')

    global_arguments = arguments['global']
    assert global_arguments.config_paths == ['myconfig', 'otherconfig']
    assert global_arguments.verbosity == 0
    assert global_arguments.syslog_verbosity == 0
    assert global_arguments.log_file_verbosity == 0
コード例 #28
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_syslog_verbosity_overrides_default():
    config_paths = ['default']
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)

    arguments = module.parse_arguments('--syslog-verbosity', '2')

    global_arguments = arguments['global']
    assert global_arguments.config_paths == config_paths
    assert global_arguments.excludes_filename is None
    assert global_arguments.verbosity == 0
    assert global_arguments.syslog_verbosity == 2
コード例 #29
0
ファイル: test_arguments.py プロジェクト: jbacker/borgmatic
def test_parse_arguments_with_no_actions_passes_argument_to_relevant_actions():
    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

    arguments = module.parse_arguments('--stats', '--files')

    assert 'prune' in arguments
    assert arguments['prune'].stats
    assert arguments['prune'].files
    assert 'create' in arguments
    assert arguments['create'].stats
    assert arguments['create'].files
    assert 'check' in arguments
コード例 #30
0
ファイル: borgmatic.py プロジェクト: DuncanBetts/borgmatic
def main():  # pragma: no cover
    configure_signals()

    try:
        arguments = parse_arguments(*sys.argv[1:])
    except ValueError as error:
        configure_logging(logging.CRITICAL)
        logger.critical(error)
        exit_with_help_link()
    except SystemExit as error:
        if error.code == 0:
            raise error
        configure_logging(logging.CRITICAL)
        logger.critical('Error parsing arguments: {}'.format(' '.join(
            sys.argv)))
        exit_with_help_link()

    global_arguments = arguments['global']
    if global_arguments.version:
        print(pkg_resources.require('borgmatic')[0].version)
        sys.exit(0)

    config_filenames = tuple(
        collect.collect_config_filenames(global_arguments.config_paths))
    configs, parse_logs = load_configurations(config_filenames)

    colorama.init(
        autoreset=True,
        strip=not should_do_markup(global_arguments.no_color, configs))
    configure_logging(
        verbosity_to_log_level(global_arguments.verbosity),
        verbosity_to_log_level(global_arguments.syslog_verbosity),
    )

    logger.debug('Ensuring legacy configuration is upgraded')
    convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)

    summary_logs = list(
        collect_configuration_run_summary_logs(configs, arguments))

    logger.info('')
    logger.info('summary:')
    [
        logger.handle(log) for log in parse_logs + summary_logs
        if log.levelno >= logger.getEffectiveLevel()
    ]

    if any(log.levelno == logging.CRITICAL for log in summary_logs):
        exit_with_help_link()