From b39b0cafd9ecbe6b1a18a196dcde91865cf1d3d0 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Sun, 3 Dec 2023 15:12:08 -0800 Subject: [PATCH] Upgrade WEEWX_ROOT for V5 --- src/weecfg/tests/test_upgrade_config.py | 2 +- src/weecfg/update_config.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/weecfg/tests/test_upgrade_config.py b/src/weecfg/tests/test_upgrade_config.py index 1f4c8507..77288ac5 100644 --- a/src/weecfg/tests/test_upgrade_config.py +++ b/src/weecfg/tests/test_upgrade_config.py @@ -129,7 +129,7 @@ class ConfigTest(unittest.TestCase): def test_upgrade_v43(self): """Test an upgrade of the stock v4.1 weewx.conf to V4.2""" - # Start with the Version 4.1 weewx.conf file: + # Start with the Version 4.2 weewx.conf file: config_dict = configobj.ConfigObj('weewx42.conf', encoding='utf-8') # Upgrade the V4.2 configuration dictionary to V4.3: diff --git a/src/weecfg/update_config.py b/src/weecfg/update_config.py index 5d5efdd8..f26be284 100644 --- a/src/weecfg/update_config.py +++ b/src/weecfg/update_config.py @@ -52,6 +52,8 @@ def update_config(config_dict): update_to_v43(config_dict) + update_to_v50(config_dict) + def merge_config(config_dict, template_dict): """Merge the template (distribution) dictionary into the user's dictionary. @@ -703,7 +705,7 @@ def update_to_v36(config_dict): 'et_period', 'wind_height', 'atc', 'nfac', 'max_delta_12h']: config_dict['StdWXCalculate']['Calculations'][scalar] = \ - config_dict['StdWXCalculate'][scalar] + config_dict['StdWXCalculate'][scalar] config_dict['StdWXCalculate'].pop(scalar) # Insert the old comment at the top of the new stanza: try: @@ -956,6 +958,19 @@ def update_to_v43(config_dict): config_dict['version'] = '4.3.0' +def update_to_v50(config_dict): + """Update a configuration file to V5.0 + + - If the config file uses '/' for WEEWX_ROOT, set it to '/etc/weewx' + """ + if 'WEEWX_ROOT' in config_dict and config_dict['WEEWX_ROOT'] == '/': + config_dict['WEEWX_ROOT'] = '/etc/weewx' + if 'WEEWX_ROOT_ORIG' in config_dict and config_dict['WEEWX_ROOT_ORIGIN'] == '/': + config_dict['WEEWX_ROOT_ORIG'] = '/etc/weewx' + + config_dict['version'] = '5.0.0' + + # ============================================================================== # Various config sections # ==============================================================================