Fix issue with installs into V4 config files

Requires patching WEEWX_ROOT at runtime
This commit is contained in:
Tom Keffer
2024-01-17 12:28:23 -08:00
parent 1691dc2fe1
commit b6e027d6ac
3 changed files with 16 additions and 11 deletions

View File

@@ -156,19 +156,23 @@ def read_config(config_path, args=None, locations=DEFAULT_LOCATIONS,
# Remember where we found the config file
config_dict['config_path'] = os.path.realpath(config_path)
# If there was a value for WEEWX_ROOT in the configuration file, remember it so we can
# restore it later.
if 'WEEWX_ROOT' in config_dict:
config_dict['WEEWX_ROOT_CONFIG'] = config_dict['WEEWX_ROOT']
# If WEEWX_ROOT is not in the configuration file, supply a default:
if 'WEEWX_ROOT' not in config_dict:
# Process WEEWX_ROOT
if 'WEEWX_ROOT' in config_dict:
# There is a value for WEEWX_ROOT. Save it.
config_dict['WEEWX_ROOT_CONFIG'] = config_dict['WEEWX_ROOT']
# Check for an older config file. If found, patch to new location
if config_dict['WEEWX_ROOT'] == '/':
config_dict['WEEWX_ROOT'] = '/etc/weewx'
else:
# No WEEWX_ROOT in the config dictionary. Supply a default.
config_dict['WEEWX_ROOT'] = os.path.dirname(config_path)
# In case WEEWX_ROOT is a relative path, join it with the location of the config file, then
# convert it to an absolute path.
config_dict['WEEWX_ROOT'] = os.path.abspath(os.path.join(os.path.dirname(config_path),
config_dict['WEEWX_ROOT']))
# If the result of all that is not an absolute path, join it with the location of the config
# file, which will make it into an absolute path.
if not os.path.abspath(config_dict['WEEWX_ROOT']):
config_dict['WEEWX_ROOT'] = os.path.normpath(os.path.join(os.path.dirname(config_path),
config_dict['WEEWX_ROOT']))
return config_path, config_dict

View File

@@ -280,7 +280,7 @@ class ExtensionEngine(object):
"""Generate tuples of (source, destination) from a file_list"""
# Go through all the files used by the extension. A "source tuple" is something like
# (bin, [user/myext.py, user/otherext.py]).
# (bin/user, [bin/user/myext.py, bin/user/otherext.py]).
for source_tuple in file_list:
# Expand the source tuple
dest_dir, source_files = source_tuple

View File

@@ -558,6 +558,7 @@ def update_to_v32(config_dict):
# with a trailing slash ('/'). Convert it to the normative form:
if 'WEEWX_ROOT_CONFIG' in config_dict:
config_dict['WEEWX_ROOT_CONFIG'] = os.path.normpath(config_dict['WEEWX_ROOT_CONFIG'])
config_dict['WEEWX_ROOT'] = os.path.normpath(config_dict['WEEWX_ROOT'])
# Add a default database-specific top-level stanzas if necessary
if 'DatabaseTypes' not in config_dict: