refactor getPref to use uniform printing logic

We add a local helper function to print a single setting. This is a
preparation to correctly print non-trivial types. The existing code
in getPref is ported over to use that function. By that, the output
of "wholeField" is changed slightly to always print the full path for
each setting (e.g. "security.serialEnabled" instead of
"security:\nserialEnabled"). This improves support for grepping on the
output.
This commit is contained in:
Felix Moessbauer
2024-10-25 14:30:53 +02:00
committed by Felix Moessbauer
parent 7fcbbe9b80
commit 1abb9fb213

View File

@@ -87,6 +87,10 @@ def checkChannel(interface: MeshInterface, channelIndex: int) -> bool:
def getPref(node, comp_name):
"""Get a channel or preferences value"""
def _printSetting(config_type, uni_name, pref_value):
"""Pretty print the setting"""
print(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
logging.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
name = splitCompoundName(comp_name)
wholeField = name[0] == name[1] # We want the whole field
@@ -114,7 +118,7 @@ def getPref(node, comp_name):
if not found:
print(
f"{localConfig.__class__.__name__} and {moduleConfig.__class__.__name__} do not have an attribute {uni_name}."
f"{localConfig.__class__.__name__} and {moduleConfig.__class__.__name__} do not have attribute {uni_name}."
)
print("Choices are...")
printConfig(localConfig)
@@ -127,11 +131,10 @@ def getPref(node, comp_name):
config_values = getattr(config, config_type.name)
if not wholeField:
pref_value = getattr(config_values, pref.name)
print(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
logging.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
_printSetting(config_type, uni_name, pref_value)
else:
print(f"{str(config_type.name)}:\n{str(config_values)}")
logging.debug(f"{str(config_type.name)}: {str(config_values)}")
for field in config_values.ListFields():
_printSetting(config_type, field[0].name, field[1])
else:
# Always show whole field for remote node
node.requestConfig(config_type)