diff --git a/NEWS b/NEWS index 3a6aa627..59ea4c1f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.2.6 + * Fix generated configuration to also include a "keep_daily" value so pruning works out of the + box. + 1.2.5 * #57: When generating sample configuration with generate-borgmatic-config, comment out all optional configuration so as to streamline the initial configuration process. diff --git a/borgmatic/config/generate.py b/borgmatic/config/generate.py index 6cff0bc4..74350d30 100644 --- a/borgmatic/config/generate.py +++ b/borgmatic/config/generate.py @@ -55,6 +55,10 @@ def _comment_out_line(line): return '#'.join((one_indent, line[INDENT:])) +REQUIRED_KEYS = {'source_directories', 'repositories', 'keep_daily'} +REQUIRED_SECTION_NAMES = {'location', 'retention'} + + def _comment_out_optional_configuration(rendered_config): ''' Post-process a rendered configuration string to comment out optional key/values. The idea is @@ -68,12 +72,17 @@ def _comment_out_optional_configuration(rendered_config): required = False for line in rendered_config.split('\n'): + key = line.strip().split(':')[0] + + if key in REQUIRED_SECTION_NAMES: + lines.append(line) + continue + # Upon encountering a required configuration option, skip commenting out lines until the # next blank line. - stripped_line = line.strip() - if stripped_line in {'source_directories:', 'repositories:'} or line == 'location:': + if key in REQUIRED_KEYS: required = True - elif not stripped_line: + elif not key: required = False lines.append(_comment_out_line(line) if not required else line) diff --git a/setup.py b/setup.py index 355f762b..997c5201 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '1.2.5' +VERSION = '1.2.6' setup(