utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
PATCH 1/1 utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
To be "future-proof" append elements to arrays if needed. Also change order of variables.
--- utils/checkpackagelib/lib_config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
utils/checkpackagelib/lib_config.py +10 -4
@@ -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 = [True] def before(self): self.state = ""
@@ -87,9 +87,15 @@ class CommentsMenusPackagesOrder(_CheckFunction): self.state += "-menu" level = self.get_level() + + if level > len(self.package) - 1: + self.menu_of_packages.append("") + self.package.append("") + self.print_package_warning.append(True) + + self.menu_of_packages[level] = text[:-1] self.package[level] = "" self.print_package_warning[level] = True - self.menu_of_packages[level] = text[:-1] elif text.startswith("endif") or text.startswith("endmenu"): if self.state.endswith("comment"):
Signature · 1 line
2.17.1
PATCH 1/1 utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
Jerzy, All,
On 2019-07-15 10:32 +0200, Jerzy Grzegorek spake thusly:
Quoted 2 lines
To be "future-proof" append elements to arrays if needed. Also change order of variables.
Is that a fix for the existing issues, or just an improvement/cleanup?
Quoted 10 lines
Signed-off-by Jerzy Grzegorek <[email protected]>--- utils/checkpackagelib/lib_config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)utils/checkpackagelib/lib_config.py +0
-0
utils/checkpackagelib/lib_config.py class AttributesOrder(_CheckFunction): · line 66
Quoted 9 lines
utils/checkpackagelib/lib_config.py +3
-3@@ -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 = [True]
Why do we need an initial value in the arrays? Can't we do something like:
package = []
...
if level > len(self.package):
append the stuff here.
Of course, that is not very nice either... All of that because we can't assigne to an index that does not already exists. In python, the moto is "easier to ask for forgiveness than permission". So:
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)Regards,
Yann E. MORIN.
Quoted 26 lines
utils/checkpackagelib/lib_config.py +7
-1def before(self): self.state = ""@@ -87,9 +87,15 @@ class CommentsMenusPackagesOrder(_CheckFunction): self.state += "-menu" level = self.get_level() + + if level > len(self.package) - 1: + self.menu_of_packages.append("") + self.package.append("") + self.print_package_warning.append(True) + + self.menu_of_packages[level] = text[:-1] self.package[level] = "" self.print_package_warning[level] = True - self.menu_of_packages[level] = text[:-1] elif text.startswith("endif") or text.startswith("endmenu"): if self.state.endswith("comment"):Signature · 6 lines
2.17.1 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
Hi Yann,
Quoted 6 lines
Jerzy, All,
On 2019-07-15 10:32 +0200, Jerzy Grzegorek spake thusly:
Quoted 2 lines
To be "future-proof" append elements to arrays if needed. Also change order of variables.
Is that a fix for the existing issues, or just an improvement/cleanup?
That is just improvement.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Jerzy Grzegorek <[email protected]>--- utils/checkpackagelib/lib_config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)utils/checkpackagelib/lib_config.py +0
-0@@ -61,9 +61,9 @@ class AttributesOrder(_CheckFunction):
Quoted 8 lines
utils/checkpackagelib/lib_config.py class AttributesOrder(_CheckFunction): · line 66
Quoted 7 lines
utils/checkpackagelib/lib_config.py +3
-3class CommentsMenusPackagesOrder(_CheckFunction): - print_package_warning = [True, True, True, True, True, True] - menu_of_packages = ["", "", "", "", "", ""] - package = ["", "", "", "", "", ""] + menu_of_packages = [""] + package = [""] + print_package_warning = [True]Why do we need an initial value in the arrays? Can't we do something
We don't need it.
Quoted 11 lines
like:
package = []
...
if level > len(self.package):
append the stuff here.Of course, that is not very nice either... All of that because we can't assigne to an index that does not already exists. In python, the moto is "easier to ask for forgiveness than permission". So:
Quoted 8 lines
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)I'm fine with your suggestion too.
I'll send a new version in a couple of days.
Thanks for the review.
Regards,
Jerzy
Quoted 30 lines
Regards,
Yann E. MORIN.Quoted 26 lines
utils/checkpackagelib/lib_config.py +7
-1def before(self): self.state = ""@@ -87,9 +87,15 @@ class CommentsMenusPackagesOrder(_CheckFunction): self.state += "-menu" level = self.get_level() + + if level > len(self.package) - 1: + self.menu_of_packages.append("") + self.package.append("") + self.print_package_warning.append(True) + + self.menu_of_packages[level] = text[:-1] self.package[level] = "" self.print_package_warning[level] = True - self.menu_of_packages[level] = text[:-1] elif text.startswith("endif") or text.startswith("endmenu"): if self.state.endswith("comment"):Signature · 6 lines
2.17.1 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot