[Buildroot] [PATCH v3 2/3] utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
Arnout Vandecappelle (Essensium/Mind)
arnout at mind.be
Thu Aug 1 08:02:36 UTC 2019
From: Jerzy Grzegorek <jerzy.m.grzegorek at gmail.com>
In the future, the nesting level of menus, comments and conditions may
increase. The fixed array length used now is not appropriate. Therefore,
append elements to the arrays if needed.
Also change order of variables.
Signed-off-by: Jerzy Grzegorek <jerzy.m.grzegorek at gmail.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout at mind.be>
---
Changes v2 -> v3:
- Initialize arrays to empty
- Rewrite commit log
Changes v1 -> v2:
- use try/except statement instead of if one (Yann)
At the beginning self.state is empty and variable level (index of arrays)
is equal 0. We append elements to arrays for the first time when a line
begining with "comment ", "if " or "menu ". At that moment level is equal 1
and each array should have two elements (index 0 and 1). To achieve this
we can use empty arrays or arrays with an initial value (index 0).
1. Arrays with an initial value and if statement (previous version)
...
if level > len(array) - 1
append elements
...
2. Empty arrays and while statement
...
while level > len(array) - 1
append elements
...
3. Arrays with an initial value and try/except statement (this version)
...
try:
assigment staff
except IndexError:
append elements
...
---
utils/checkpackagelib/lib_config.py | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py
index b42760396e..6cbdc209c8 100644
--- a/utils/checkpackagelib/lib_config.py
+++ b/utils/checkpackagelib/lib_config.py
@@ -61,9 +61,9 @@ class AttributesOrder(_CheckFunction):
class CommentsMenusPackagesOrder(_CheckFunction):
- print_package_warning = [True, True, True, True, True, True]
- menu_of_packages = ["", "", "", "", "", ""]
- package = ["", "", "", "", "", ""]
+ menu_of_packages = []
+ package = []
+ print_package_warning = []
def before(self):
self.state = ""
@@ -92,9 +92,15 @@ class CommentsMenusPackagesOrder(_CheckFunction):
self.state += "-menu"
level = self.get_level()
- self.package[level] = ""
- self.print_package_warning[level] = True
- self.menu_of_packages[level] = text[:-1]
+
+ try:
+ self.menu_of_packages[level] = text[:-1]
+ self.package[level] = ""
+ self.print_package_warning[level] = True
+ except IndexError:
+ self.menu_of_packages.append(text[:-1])
+ self.package.append("")
+ self.print_package_warning.append(True)
elif text.startswith("endif") or text.startswith("endmenu"):
if self.state.endswith("comment"):
--
2.21.0
More information about the buildroot
mailing list