From c29e2a627e1a567562b7bc57b7cc477ee9b03503 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 4 Mar 2022 14:53:38 -0500 Subject: [PATCH] mgr/nfs: lift _format_val function to file level There's no advantage to having this function as a closure and it makes reading the code (and testing it) more challenging. Signed-off-by: John Mulligan (cherry picked from commit 1a7b7e35b261c9e227f0540ae5310e68a7e8bfe4) --- src/pybind/mgr/nfs/ganesha_conf.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pybind/mgr/nfs/ganesha_conf.py b/src/pybind/mgr/nfs/ganesha_conf.py index 382b91827e3a1..67bee5b44148a 100644 --- a/src/pybind/mgr/nfs/ganesha_conf.py +++ b/src/pybind/mgr/nfs/ganesha_conf.py @@ -14,6 +14,17 @@ def _indentation(depth: int, size: int = 4) -> str: return " " * (depth * size) +def _format_val(block_name: str, key: str, val: str) -> str: + if isinstance(val, list): + return ', '.join([_format_val(block_name, key, v) for v in val]) + if isinstance(val, bool): + return str(val).lower() + if isinstance(val, int) or (block_name == 'CLIENT' + and key == 'clients'): + return '{}'.format(val) + return '"{}"'.format(val) + + class RawBlock(): def __init__(self, block_name: str, blocks: List['RawBlock'] = [], values: Dict[str, Any] = {}): if not values: # workaround mutable default argument @@ -140,16 +151,6 @@ class GaneshaConfParser: @staticmethod def write_block_body(block: RawBlock, depth: int = 0) -> str: - def format_val(key: str, val: str) -> str: - if isinstance(val, list): - return ', '.join([format_val(key, v) for v in val]) - if isinstance(val, bool): - return str(val).lower() - if isinstance(val, int) or (block.block_name == 'CLIENT' - and key == 'clients'): - return '{}'.format(val) - return '"{}"'.format(val) - conf_str = "" for blo in block.blocks: conf_str += GaneshaConfParser.write_block(blo, depth) @@ -157,7 +158,8 @@ class GaneshaConfParser: for key, val in block.values.items(): if val is not None: conf_str += _indentation(depth) - conf_str += '{} = {};\n'.format(key, format_val(key, val)) + fval = _format_val(block.block_name, key, val) + conf_str += '{} = {};\n'.format(key, fval) return conf_str @staticmethod -- 2.39.5