From: John Mulligan Date: Fri, 4 Mar 2022 19:40:33 +0000 (-0500) Subject: mgr/nfs: lift generic indentation function to file level X-Git-Tag: v17.2.1~48^2~50 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c34fc8c0878a4e4f5fb0590f05df74f2036095cc;p=ceph.git mgr/nfs: lift generic indentation function to file level Tucking a private method away as a staticmethod makes it harder to reuse and less obvious that it can be resused. Signed-off-by: John Mulligan (cherry picked from commit d791d5c2291970b750ec73aa8862dd9369b92da0) --- diff --git a/src/pybind/mgr/nfs/ganesha_conf.py b/src/pybind/mgr/nfs/ganesha_conf.py index 8733545362e..71ae5245cbe 100644 --- a/src/pybind/mgr/nfs/ganesha_conf.py +++ b/src/pybind/mgr/nfs/ganesha_conf.py @@ -10,6 +10,13 @@ if TYPE_CHECKING: from nfs.module import Module +def _indentation(depth: int, size: int = 4) -> str: + conf_str = "" + for _ in range(0, depth * size): + conf_str += " " + return conf_str + + class RawBlock(): def __init__(self, block_name: str, blocks: List['RawBlock'] = [], values: Dict[str, Any] = {}): if not values: # workaround mutable default argument @@ -134,13 +141,6 @@ class GaneshaConfParser: blocks.append(self.parse_block_or_section()) return blocks - @staticmethod - def _indentation(depth: int, size: int = 4) -> str: - conf_str = "" - for _ in range(0, depth * size): - conf_str += " " - return conf_str - @staticmethod def write_block_body(block: RawBlock, depth: int = 0) -> str: def format_val(key: str, val: str) -> str: @@ -159,7 +159,7 @@ class GaneshaConfParser: for key, val in block.values.items(): if val is not None: - conf_str += GaneshaConfParser._indentation(depth) + conf_str += _indentation(depth) conf_str += '{} = {};\n'.format(key, format_val(key, val)) return conf_str @@ -169,11 +169,11 @@ class GaneshaConfParser: return '%url "{}"\n\n'.format(block.values['value']) conf_str = "" - conf_str += GaneshaConfParser._indentation(depth) + conf_str += _indentation(depth) conf_str += format(block.block_name) conf_str += " {\n" conf_str += GaneshaConfParser.write_block_body(block, depth + 1) - conf_str += GaneshaConfParser._indentation(depth) + conf_str += _indentation(depth) conf_str += "}\n" return conf_str