diff --git a/src/weecfg/__init__.py b/src/weecfg/__init__.py index 8129717b..fa3094e6 100644 --- a/src/weecfg/__init__.py +++ b/src/weecfg/__init__.py @@ -121,7 +121,7 @@ def read_config(config_path, args=None, locations=DEFAULT_LOCATIONS, This version also adds two entries to the returned ConfigObj: config_path: Location of the actual configuration file that was used. - WEEWX_ROOT_ORIG: The original value of WEEWX_ROOT, or None if there + WEEWX_ROOT_CONFIG: The original value of WEEWX_ROOT, or None if there was no original value Args: @@ -158,7 +158,7 @@ def read_config(config_path, args=None, locations=DEFAULT_LOCATIONS, config_dict['config_path'] = os.path.realpath(config_path) # Remember the original value for WEEWX_ROOT. In case we need to write this file out, we # can restore it. - config_dict['WEEWX_ROOT_ORIG'] = config_dict.get('WEEWX_ROOT') + config_dict['WEEWX_ROOT_CONFIG'] = config_dict.get('WEEWX_ROOT') if 'WEEWX_ROOT' not in config_dict: # If missing, set WEEWX_ROOT to the directory the config file is in @@ -194,10 +194,14 @@ def save(config_dict, config_path, backup=False): write_dict = weeutil.config.deep_copy(config_dict) write_dict.pop('config_path', None) write_dict.pop('entry_path', None) - if 'WEEWX_ROOT_ORIG' in write_dict: - # Reset WEEWX_ROOT to what it originally was, then delete WEEWX_ROOT_ORIG - write_dict['WEEWX_ROOT'] = write_dict['WEEWX_ROOT_ORIG'] - del write_dict['WEEWX_ROOT_ORIG'] + # If there was a value for WEEWX_ROOT in the config file, restore it + if 'WEEWX_ROOT_CONFIG' in write_dict: + write_dict['WEEWX_ROOT'] = write_dict['WEEWX_ROOT_CONFIG'] + # Add a comment if it doesn't already have one + if not write_dict.comments['WEEWX_ROOT']: + write_dict.comments['WEEWX_ROOT'] = ['', 'Path to the station data area, relative to ' + 'the configuration file.'] + del write_dict['WEEWX_ROOT_CONFIG'] # If the final path is just '.', get rid of it entirely --- that's the default. if 'WEEWX_ROOT' in write_dict and os.path.normpath(write_dict['WEEWX_ROOT']) == '.': del write_dict['WEEWX_ROOT'] diff --git a/src/weecfg/update_config.py b/src/weecfg/update_config.py index 75a97715..8269a27b 100644 --- a/src/weecfg/update_config.py +++ b/src/weecfg/update_config.py @@ -965,8 +965,8 @@ def update_to_v50(config_dict): """ 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_ORIG'] == '/': - config_dict['WEEWX_ROOT_ORIG'] = '/etc/weewx' + if 'WEEWX_ROOT_CONFIG' in config_dict and config_dict['WEEWX_ROOT_CONFIG'] == '/': + config_dict['WEEWX_ROOT_CONFIG'] = '/etc/weewx' config_dict['version'] = '5.0.0' diff --git a/src/weectllib/station_actions.py b/src/weectllib/station_actions.py index b435aa58..caaa28a3 100644 --- a/src/weectllib/station_actions.py +++ b/src/weectllib/station_actions.py @@ -75,7 +75,7 @@ def station_create(weewx_root=None, with weeutil.weeutil.get_resource_fd('weewx_data', 'weewx.conf') as fd: dist_config_dict = configobj.ConfigObj(fd, encoding='utf-8', file_error=True) - dist_config_dict['WEEWX_ROOT_ORIG'] = rel_weewx_root + dist_config_dict['WEEWX_ROOT_CONFIG'] = rel_weewx_root config_dir = os.path.dirname(config_path) dist_config_dict['WEEWX_ROOT'] = os.path.abspath(os.path.join(config_dir, rel_weewx_root)) @@ -158,7 +158,9 @@ def station_reconfigure(config_dict, """Reconfigure an existing station""" if weewx_root: - config_dict['WEEWX_ROOT'] = config_dict['WEEWX_ROOT_ORIG'] = weewx_root + config_dict['WEEWX_ROOT_CONFIG'] = weewx_root + config_dict['WEEWX_ROOT'] = os.path.abspath( + os.path.join(os.path.dirname(config_dict['config_path']), weewx_root)) config_config(config_dict, config_path=config_dict['config_path'], driver=driver, diff --git a/src/weectllib/tests/test_station_actions.py b/src/weectllib/tests/test_station_actions.py index 91ae0163..1bad37e1 100644 --- a/src/weectllib/tests/test_station_actions.py +++ b/src/weectllib/tests/test_station_actions.py @@ -305,7 +305,7 @@ class TestCreateStation(unittest.TestCase): # Retrieve the config file that was created and check it: config_dict = configobj.ConfigObj(config_path, encoding='utf-8') self.assertNotIn('WEEWX_ROOT', config_dict) - self.assertNotIn('WEEWX_ROOT_ORIG', config_dict) + self.assertNotIn('WEEWX_ROOT_CONFIG', config_dict) self.assertEqual(config_dict['Station']['station_type'], 'Simulator') self.assertEqual(config_dict['Simulator']['driver'], 'weewx.drivers.simulator') self.assertEqual(config_dict['StdReport']['SKIN_ROOT'], 'skins') @@ -349,7 +349,7 @@ class TestReconfigureStation(unittest.TestCase): config_dict = configobj.ConfigObj(config_path, encoding='utf-8') # Check it out. self.assertEqual(config_dict['WEEWX_ROOT'], '/etc/weewx') - self.assertNotIn('WEEWX_ROOT_ORIG', config_dict) + self.assertNotIn('WEEWX_ROOT_CONFIG', config_dict) self.assertEqual(config_dict['Station']['station_type'], 'Vantage') self.assertEqual(config_dict['Vantage']['driver'], 'weewx.drivers.vantage') self.assertEqual(config_dict['StdReport']['SKIN_ROOT'], 'skins')