utils/checkpackagelib: CommentsMenusPackagesOrder: separate comment/if/menu cases
authorJerzy Grzegorek <jerzy.m.grzegorek@gmail.com>
Sat, 5 Oct 2019 12:22:16 +0000 (14:22 +0200)
committerArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Mon, 7 Oct 2019 21:39:21 +0000 (23:39 +0200)
The handling of 'comment...', 'if ...' and 'menu ...' lines have almost
nothing in common, and subsequent patches will give them even less in
common. Therefore, completely separate their handling in top-level
conditions. The only code that gets duplicated in the different branches
is the 'self.initialize_level_elements(text)' call.

Signed-off-by: Jerzy Grzegorek <jerzy.m.grzegorek@gmail.com>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Reviewed-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
utils/checkpackagelib/lib_config.py

index 499660feb72abac421bb5a8168d45ea3d05bef2d..06c066c5ca92fbfee8a428f7df69553891cab509 100644 (file)
@@ -95,22 +95,22 @@ class CommentsMenusPackagesOrder(_CheckFunction):
 
         source_line = re.match(r'^\s*source ".*/([^/]*)/Config.in(.host)?"', text)
 
-        if text.startswith("comment ") or text.startswith("if ") or \
-           text.startswith("menu "):
+        if text.startswith("comment "):
+            if not self.state.endswith("-comment"):
+                self.state += "-comment"
 
-            if text.startswith("comment"):
-                if not self.state.endswith("-comment"):
-                    self.state += "-comment"
+            self.initialize_level_elements(text)
+
+        elif text.startswith("if "):
+            self.state += "-if"
 
-            elif text.startswith("if") or text.startswith("menu"):
-                if text.startswith("if"):
-                    self.state += "-if"
+            self.initialize_level_elements(text)
 
-                elif text.startswith("menu"):
-                    if self.state.endswith("-comment"):
-                        self.state = self.state[:-8]
+        elif text.startswith("menu "):
+            if self.state.endswith("-comment"):
+                self.state = self.state[:-8]
 
-                    self.state += "-menu"
+            self.state += "-menu"
 
             self.initialize_level_elements(text)