From 746428ed44f88b713820e5b6a8eeb51de3b34eff Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 29 Sep 2018 15:44:37 -0700 Subject: [PATCH] Fix generated configuration to also include a "keep_daily" value so pruning works out of the box. --- NEWS | 4 ++++ borgmatic/config/generate.py | 15 ++++++++++++--- setup.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 3a6aa62..59ea4c1 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 6cff0bc..74350d3 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 355f762..997c520 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(