]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: lift generic indentation function to file level
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 4 Mar 2022 19:40:33 +0000 (14:40 -0500)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:01:35 +0000 (19:01 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit d791d5c2291970b750ec73aa8862dd9369b92da0)

src/pybind/mgr/nfs/ganesha_conf.py

index 8733545362eaeb0d77b42a22b14a248953e6f1d1..71ae5245cbe5f7f680f3d94ebd7e89148e9839f6 100644 (file)
@@ -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