#39: Fix to make /etc/borgmatic/config.yaml optional rather than required when using the default config paths.

This commit is contained in:
Dan Helfman 2017-09-08 21:25:42 -07:00
parent b44bc57548
commit 84c148fb3b
6 changed files with 27 additions and 9 deletions

4
NEWS
View file

@ -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 1.1.7
* #28: Add "archive_name_format" to configuration for customizing archive names. * #28: Add "archive_name_format" to configuration for customizing archive names.

View file

@ -9,8 +9,6 @@ from borgmatic.config import collect, convert, validate
LEGACY_CONFIG_PATH = '/etc/borgmatic/config' 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): def parse_arguments(*arguments):
@ -30,8 +28,8 @@ def parse_arguments(*arguments):
'-c', '--config', '-c', '--config',
nargs='+', nargs='+',
dest='config_paths', dest='config_paths',
default=DEFAULT_CONFIG_PATHS, default=collect.DEFAULT_CONFIG_PATHS,
help='Configuration filenames or directories, defaults to: {}'.format(' '.join(DEFAULT_CONFIG_PATHS)), help='Configuration filenames or directories, defaults to: {}'.format(' '.join(collect.DEFAULT_CONFIG_PATHS)),
) )
parser.add_argument( parser.add_argument(
'--excludes', '--excludes',

View file

@ -1,6 +1,9 @@
import os import os
DEFAULT_CONFIG_PATHS = ['/etc/borgmatic/config.yaml', '/etc/borgmatic.d']
def collect_config_filenames(config_paths): def collect_config_filenames(config_paths):
''' '''
Given a sequence of config paths, both filenames and directories, resolve that to just an 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: for path in config_paths:
exists = os.path.exists(path) 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 continue
if not os.path.isdir(path) or not exists: if not os.path.isdir(path) or not exists:

View file

@ -9,7 +9,7 @@ from borgmatic.commands import borgmatic as module
def test_parse_arguments_with_no_arguments_uses_defaults(): def test_parse_arguments_with_no_arguments_uses_defaults():
parser = module.parse_arguments() 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.excludes_filename == None
assert parser.verbosity is 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(): def test_parse_arguments_with_verbosity_flag_overrides_default():
parser = module.parse_arguments('--verbosity', '1') 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.excludes_filename == None
assert parser.verbosity == 1 assert parser.verbosity == 1

View file

@ -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(): def test_collect_config_filenames_skips_etc_borgmatic_dot_d_if_it_does_not_exist():
config_paths = ('config.yaml', '/etc/borgmatic.d') config_paths = ('config.yaml', '/etc/borgmatic.d')
mock_path = flexmock(module.os.path) 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',) 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') config_paths = ('config.yaml', '/my/directory')
mock_path = flexmock(module.os.path) 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('config.yaml').and_return(True)

View file

@ -1,7 +1,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '1.1.7' VERSION = '1.1.8'
setup( setup(