mirror of
https://github.com/weewx/weewx.git
synced 2026-04-20 01:26:56 -04:00
Modified deep_copy() so it does not have to turn interpolation off.
Really fixes issue #579.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2018-2019 Tom Keffer <tkeffer@gmail.com>
|
||||
# Copyright (c) 2018-2020 Tom Keffer <tkeffer@gmail.com>
|
||||
#
|
||||
# See the file LICENSE.txt for your full rights.
|
||||
#
|
||||
@@ -229,18 +229,17 @@ def config_from_str(input_str):
|
||||
|
||||
|
||||
def deep_copy(old_dict):
|
||||
""" Return a deepcopy of a ConfigObj."""
|
||||
import copy
|
||||
""" Return a deep copy of a ConfigObj. This utility can only be used by a ConfigObj,
|
||||
not one of its Sections."""
|
||||
import io
|
||||
|
||||
# Turn off interpolation. It seems to interfere with the deep copying process.
|
||||
# Save the old interpolation value.
|
||||
old_interpolation = old_dict.main.interpolation
|
||||
old_dict.main.interpolation = False
|
||||
|
||||
new_dict = copy.deepcopy(old_dict)
|
||||
|
||||
# Restore the old interpolation value
|
||||
old_dict.main.interpolation = old_interpolation
|
||||
with io.BytesIO() as fd:
|
||||
old_dict.write(fd)
|
||||
fd.seek(0)
|
||||
new_dict = configobj.ConfigObj(fd,
|
||||
encoding=old_dict.encoding,
|
||||
default_encoding=old_dict.default_encoding,
|
||||
interpolation=old_dict.interpolation)
|
||||
|
||||
return new_dict
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestConfig(unittest.TestCase):
|
||||
}
|
||||
|
||||
c_in = configobj.ConfigObj(test_dict, encoding='utf-8')
|
||||
c_out = weeutil.config.deep_copy(c_in['Logging'])
|
||||
c_out = weeutil.config.deep_copy(c_in)['Logging']
|
||||
self.assertIsInstance(c_out, configobj.Section)
|
||||
self.assertEqual(c_out, test_dict['Logging'])
|
||||
# Try changing something and see if it's still equal:
|
||||
|
||||
@@ -134,11 +134,9 @@ class StdEngine(object):
|
||||
log.debug("No services in service group %s", service_group)
|
||||
continue
|
||||
log.debug("Loading service %s", svc)
|
||||
# Make sure each service gets its own copy of the config dictionary.
|
||||
config_dict_copy = weeutil.config.deep_copy(config_dict)
|
||||
# Get the class, then instantiate it with self and the new config dictionary as
|
||||
# Get the class, then instantiate it with self and the config dictionary as
|
||||
# arguments:
|
||||
obj = weeutil.weeutil.get_object(svc)(self,config_dict_copy)
|
||||
obj = weeutil.weeutil.get_object(svc)(self, config_dict)
|
||||
# Append it to the list of open services.
|
||||
self.service_obj.append(obj)
|
||||
log.debug("Finished loading service %s", svc)
|
||||
|
||||
@@ -246,7 +246,7 @@ class StdReportEngine(threading.Thread):
|
||||
if 'Defaults' in self.config_dict['StdReport']:
|
||||
# Because we will be modifying the results, make a deep copy of the [[Defaults]]
|
||||
# section.
|
||||
merge_dict = weeutil.config.deep_copy(self.config_dict['StdReport']['Defaults'])
|
||||
merge_dict = weeutil.config.deep_copy(self.config_dict)['StdReport']['Defaults']
|
||||
weeutil.config.merge_config(skin_dict, merge_dict)
|
||||
|
||||
# Inject any scalar overrides. This is for backwards compatibility. These options should now go
|
||||
|
||||
Reference in New Issue
Block a user