From 9b819f32f8682bb4b1fd03937189824c81ee0a5c Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 18 Nov 2020 15:01:10 -0800 Subject: [PATCH] Fix traceback when upgrading old INI-style configuration with upgrade-borgmatic-config (#367). --- NEWS | 1 + borgmatic/commands/convert_config.py | 4 +++- borgmatic/config/generate.py | 4 ++-- tests/integration/config/test_generate.py | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 0129c233..29c0d0eb 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ * #355: Fix traceback when a database hook value is null in a configuration file. * #361: Merge override values when specifying the "--override" flag multiple times. The previous behavior was to take the value of the last "--override" flag only. + * #367: Fix traceback when upgrading old INI-style configuration with upgrade-borgmatic-config. * #368: Fix signal forwarding from borgmatic to Borg resulting in recursion traceback. * #369: Document support for Borg placeholders in repository names. diff --git a/borgmatic/commands/convert_config.py b/borgmatic/commands/convert_config.py index 69568d9b..093d4e37 100644 --- a/borgmatic/commands/convert_config.py +++ b/borgmatic/commands/convert_config.py @@ -99,7 +99,9 @@ def main(): # pragma: no cover ) generate.write_configuration( - args.destination_config_filename, destination_config, mode=source_config_file_mode + args.destination_config_filename, + generate.render_configuration(destination_config), + mode=source_config_file_mode, ) display_result(args) diff --git a/borgmatic/config/generate.py b/borgmatic/config/generate.py index fd9ab65c..82dadeaa 100644 --- a/borgmatic/config/generate.py +++ b/borgmatic/config/generate.py @@ -99,7 +99,7 @@ def _comment_out_optional_configuration(rendered_config): return '\n'.join(lines) -def _render_configuration(config): +def render_configuration(config): ''' Given a config data structure of nested OrderedDicts, render the config as YAML and return it. ''' @@ -284,5 +284,5 @@ def generate_sample_configuration(source_filename, destination_filename, schema_ write_configuration( destination_filename, - _comment_out_optional_configuration(_render_configuration(destination_config)), + _comment_out_optional_configuration(render_configuration(destination_config)), ) diff --git a/tests/integration/config/test_generate.py b/tests/integration/config/test_generate.py index 0ff610f5..405beb33 100644 --- a/tests/integration/config/test_generate.py +++ b/tests/integration/config/test_generate.py @@ -87,8 +87,8 @@ def test_comment_out_optional_configuration_comments_optional_config_only(): assert module._comment_out_optional_configuration(config.strip()) == expected_config.strip() -def test_render_configuration_converts_configuration_to_yaml_string(): - yaml_string = module._render_configuration({'foo': 'bar'}) +def testrender_configuration_converts_configuration_to_yaml_string(): + yaml_string = module.render_configuration({'foo': 'bar'}) assert yaml_string == 'foo: bar\n' @@ -194,7 +194,7 @@ def test_generate_sample_configuration_does_not_raise(): flexmock(module.yaml).should_receive('round_trip_load') flexmock(module).should_receive('_schema_to_sample_configuration') flexmock(module).should_receive('merge_source_configuration_into_destination') - flexmock(module).should_receive('_render_configuration') + flexmock(module).should_receive('render_configuration') flexmock(module).should_receive('_comment_out_optional_configuration') flexmock(module).should_receive('write_configuration') @@ -208,7 +208,7 @@ def test_generate_sample_configuration_with_source_filename_does_not_raise(): flexmock(module.load).should_receive('load_configuration') flexmock(module).should_receive('_schema_to_sample_configuration') flexmock(module).should_receive('merge_source_configuration_into_destination') - flexmock(module).should_receive('_render_configuration') + flexmock(module).should_receive('render_configuration') flexmock(module).should_receive('_comment_out_optional_configuration') flexmock(module).should_receive('write_configuration')