From 84c148fb3b304514d26f194c61cd01ef66c5fa53 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 8 Sep 2017 21:25:42 -0700 Subject: [PATCH] #39: Fix to make /etc/borgmatic/config.yaml optional rather than required when using the default config paths. --- NEWS | 4 ++++ borgmatic/commands/borgmatic.py | 6 ++---- borgmatic/config/collect.py | 5 ++++- .../tests/integration/commands/test_borgmatic.py | 4 ++-- borgmatic/tests/unit/config/test_collect.py | 15 ++++++++++++++- setup.py | 2 +- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 04a3d5a..6bd9ece 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.1.8 + * #39: Fix to make /etc/borgmatic/config.yaml optional rather than required when using the default + config paths. + 1.1.7 * #28: Add "archive_name_format" to configuration for customizing archive names. diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 5085b65..2fdff34 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -9,8 +9,6 @@ from borgmatic.config import collect, convert, validate LEGACY_CONFIG_PATH = '/etc/borgmatic/config' -DEFAULT_CONFIG_PATHS = ['/etc/borgmatic/config.yaml', '/etc/borgmatic.d'] -DEFAULT_EXCLUDES_PATH = '/etc/borgmatic/excludes' def parse_arguments(*arguments): @@ -30,8 +28,8 @@ def parse_arguments(*arguments): '-c', '--config', nargs='+', dest='config_paths', - default=DEFAULT_CONFIG_PATHS, - help='Configuration filenames or directories, defaults to: {}'.format(' '.join(DEFAULT_CONFIG_PATHS)), + default=collect.DEFAULT_CONFIG_PATHS, + help='Configuration filenames or directories, defaults to: {}'.format(' '.join(collect.DEFAULT_CONFIG_PATHS)), ) parser.add_argument( '--excludes', diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index dbe6f2f..4b8b88e 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -1,6 +1,9 @@ import os +DEFAULT_CONFIG_PATHS = ['/etc/borgmatic/config.yaml', '/etc/borgmatic.d'] + + def collect_config_filenames(config_paths): ''' Given a sequence of config paths, both filenames and directories, resolve that to just an @@ -14,7 +17,7 @@ def collect_config_filenames(config_paths): for path in config_paths: exists = os.path.exists(path) - if os.path.realpath(path) == '/etc/borgmatic.d' and not exists: + if os.path.realpath(path) in DEFAULT_CONFIG_PATHS and not exists: continue if not os.path.isdir(path) or not exists: diff --git a/borgmatic/tests/integration/commands/test_borgmatic.py b/borgmatic/tests/integration/commands/test_borgmatic.py index 2b82ecf..1d6aa5c 100644 --- a/borgmatic/tests/integration/commands/test_borgmatic.py +++ b/borgmatic/tests/integration/commands/test_borgmatic.py @@ -9,7 +9,7 @@ from borgmatic.commands import borgmatic as module def test_parse_arguments_with_no_arguments_uses_defaults(): parser = module.parse_arguments() - assert parser.config_paths == module.DEFAULT_CONFIG_PATHS + assert parser.config_paths == module.collect.DEFAULT_CONFIG_PATHS assert parser.excludes_filename == None assert parser.verbosity is None @@ -32,7 +32,7 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list(): def test_parse_arguments_with_verbosity_flag_overrides_default(): parser = module.parse_arguments('--verbosity', '1') - assert parser.config_paths == module.DEFAULT_CONFIG_PATHS + assert parser.config_paths == module.collect.DEFAULT_CONFIG_PATHS assert parser.excludes_filename == None assert parser.verbosity == 1 diff --git a/borgmatic/tests/unit/config/test_collect.py b/borgmatic/tests/unit/config/test_collect.py index 2adee63..c2572c8 100644 --- a/borgmatic/tests/unit/config/test_collect.py +++ b/borgmatic/tests/unit/config/test_collect.py @@ -32,6 +32,19 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno ) +def test_collect_config_filenames_skips_etc_borgmatic_config_dot_yaml_if_it_does_not_exist(): + config_paths = ('config.yaml', '/etc/borgmatic/config.yaml') + mock_path = flexmock(module.os.path) + mock_path.should_receive('exists').with_args('config.yaml').and_return(True) + mock_path.should_receive('exists').with_args('/etc/borgmatic/config.yaml').and_return(False) + mock_path.should_receive('isdir').with_args('config.yaml').and_return(False) + mock_path.should_receive('isdir').with_args('/etc/borgmatic/config.yaml').and_return(True) + + config_filenames = tuple(module.collect_config_filenames(config_paths)) + + assert config_filenames == ('config.yaml',) + + def test_collect_config_filenames_skips_etc_borgmatic_dot_d_if_it_does_not_exist(): config_paths = ('config.yaml', '/etc/borgmatic.d') mock_path = flexmock(module.os.path) @@ -45,7 +58,7 @@ def test_collect_config_filenames_skips_etc_borgmatic_dot_d_if_it_does_not_exist assert config_filenames == ('config.yaml',) -def test_collect_config_filenames_includes_directory_if_it_does_not_exist(): +def test_collect_config_filenames_includes_other_directory_if_it_does_not_exist(): config_paths = ('config.yaml', '/my/directory') mock_path = flexmock(module.os.path) mock_path.should_receive('exists').with_args('config.yaml').and_return(True) diff --git a/setup.py b/setup.py index bd93926..d3b8307 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '1.1.7' +VERSION = '1.1.8' setup(