diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 0299da6..33b156a 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -28,8 +28,7 @@ def parse_arguments(*arguments): parser.add_argument( '--excludes', dest='excludes_filename', - default=DEFAULT_EXCLUDES_FILENAME if os.path.exists(DEFAULT_EXCLUDES_FILENAME) else None, - help='Excludes filename', + help='Excludes filename, deprecated in favor of excludes_patterns within configuration', ) parser.add_argument( '-v', '--verbosity', @@ -46,7 +45,7 @@ def main(): # pragma: no cover convert.guard_configuration_upgraded(LEGACY_CONFIG_FILENAME, args.config_filename) config = validate.parse_configuration(args.config_filename, validate.schema_filename()) repository = config.location['repository'] - remote_path = config.location.get('remote_path') + remote_path = config.location['remote_path'] borg.initialize(config.storage) borg.create_archive( diff --git a/borgmatic/config/convert.py b/borgmatic/config/convert.py index bdf9eb2..1aaf7aa 100644 --- a/borgmatic/config/convert.py +++ b/borgmatic/config/convert.py @@ -77,3 +77,21 @@ def guard_configuration_upgraded(source_config_filename, destination_config_file ''' if os.path.exists(source_config_filename) and not os.path.exists(destination_config_filename): raise LegacyConfigurationNotUpgraded() + + +class LegacyExcludesFilenamePresent(FileNotFoundError): + def __init__(self): + super(LegacyExcludesFilenamePresent, self).__init__( + '''borgmatic changed its configuration file format in version 1.1.0 from INI-style +to YAML. This better supports validation, and has a more natural way to express +lists of values. The new configuration file incorporates excludes, so you no +longer need to provide an excludes filename on the command-line with an +"--excludes" argument. + +Please remove the "--excludes" argument and run borgmatic again.''' + ) + + +def guard_excludes_filename_omitted(excludes_filename): + if excludes_filename != None: + raise LegacyExcludesFilenamePresent() diff --git a/borgmatic/tests/integration/commands/test_borgmatic.py b/borgmatic/tests/integration/commands/test_borgmatic.py index 12afeed..f1cc43a 100644 --- a/borgmatic/tests/integration/commands/test_borgmatic.py +++ b/borgmatic/tests/integration/commands/test_borgmatic.py @@ -7,18 +7,14 @@ from borgmatic.commands import borgmatic as module def test_parse_arguments_with_no_arguments_uses_defaults(): - flexmock(os.path).should_receive('exists').and_return(True) - parser = module.parse_arguments() assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME - assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME + assert parser.excludes_filename == None assert parser.verbosity is None def test_parse_arguments_with_filename_arguments_overrides_defaults(): - flexmock(os.path).should_receive('exists').and_return(True) - parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes') assert parser.config_filename == 'myconfig' @@ -26,38 +22,14 @@ def test_parse_arguments_with_filename_arguments_overrides_defaults(): assert parser.verbosity is None -def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none(): - flexmock(os.path).should_receive('exists').and_return(False) - - parser = module.parse_arguments() - - assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME - assert parser.excludes_filename is None - assert parser.verbosity is None - - -def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename(): - flexmock(os.path).should_receive('exists').and_return(False) - - parser = module.parse_arguments('--excludes', 'myexcludes') - - assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME - assert parser.excludes_filename == 'myexcludes' - assert parser.verbosity is None - - def test_parse_arguments_with_verbosity_flag_overrides_default(): - flexmock(os.path).should_receive('exists').and_return(True) - parser = module.parse_arguments('--verbosity', '1') assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME - assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME + assert parser.excludes_filename == None assert parser.verbosity == 1 def test_parse_arguments_with_invalid_arguments_exits(): - flexmock(os.path).should_receive('exists').and_return(True) - with pytest.raises(SystemExit): module.parse_arguments('--posix-me-harder') diff --git a/borgmatic/tests/unit/config/test_convert.py b/borgmatic/tests/unit/config/test_convert.py index 2e5849b..39f0cee 100644 --- a/borgmatic/tests/unit/config/test_convert.py +++ b/borgmatic/tests/unit/config/test_convert.py @@ -92,3 +92,12 @@ def test_guard_configuration_upgraded_does_not_raise_when_neither_config_present flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False) module.guard_configuration_upgraded('config', 'config.yaml') + + +def test_guard_excludes_filename_omitted_raises_when_filename_provided(): + with pytest.raises(module.LegacyExcludesFilenamePresent): + module.guard_excludes_filename_omitted(excludes_filename='/etc/borgmatic/excludes') + + +def test_guard_excludes_filename_omitted_does_not_raise_when_filename_not_provided(): + module.guard_excludes_filename_omitted(excludes_filename=None)