checkpackagelib/lib_config.py: check packages alphabetical order in {Config.in, Config.in.host}
Signed-off-by: Jerzy Grzegorek <jerzy.m.grzegorek@gmail.com> [Arnout: - calculate level by counting - instead of with a static array; - new_package is only used locally, so don't make it a class member; - do indentation according to length of prefix; - don't split string in the middle of a line; - report first wrong package per menu; - do replace() only once; - add comment why we do replace(). ] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
parent
4e655134cd
commit
e36a63cf6b
|
@ -60,6 +60,72 @@ class AttributesOrder(_CheckFunction):
|
|||
text]
|
||||
|
||||
|
||||
class CommentsMenusPackagesOrder(_CheckFunction):
|
||||
print_package_warning = [True, True, True, True, True, True]
|
||||
menu_of_packages = ["", "", "", "", "", ""]
|
||||
package = ["", "", "", "", "", ""]
|
||||
|
||||
def before(self):
|
||||
self.state = ""
|
||||
|
||||
def get_level(self):
|
||||
return len(self.state.split('-')) - 1
|
||||
|
||||
def check_line(self, lineno, 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"
|
||||
|
||||
elif text.startswith("if") or text.startswith("menu"):
|
||||
if text.startswith("if"):
|
||||
self.state += "-if"
|
||||
|
||||
elif text.startswith("menu"):
|
||||
self.state += "-menu"
|
||||
|
||||
level = self.get_level()
|
||||
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"):
|
||||
self.state = self.state[:-8]
|
||||
|
||||
if text.startswith("endif"):
|
||||
self.state = self.state[:-3]
|
||||
|
||||
elif text.startswith("endmenu"):
|
||||
self.state = self.state[:-5]
|
||||
|
||||
elif text.startswith('\tsource "package/'):
|
||||
level = self.get_level()
|
||||
new_package = text[17: -(len(self.filename)-5):]
|
||||
|
||||
# We order _ before A, so replace it with .
|
||||
new_package_ord = new_package.replace('_', '.')
|
||||
|
||||
if self.package[level] != "" and \
|
||||
self.print_package_warning[level] and \
|
||||
new_package_ord < self.package[level]:
|
||||
self.print_package_warning[level] = False
|
||||
prefix = "{}:{}: ".format(self.filename, lineno)
|
||||
spaces = " " * len(prefix)
|
||||
return ["{prefix}Packages in: {menu},\n"
|
||||
"{spaces}are not alphabetically ordered;\n"
|
||||
"{spaces}correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
"{spaces}first incorrect package: {package}"
|
||||
.format(prefix=prefix, spaces=spaces,
|
||||
menu=self.menu_of_packages[level],
|
||||
package=new_package),
|
||||
text]
|
||||
|
||||
self.package[level] = new_package_ord
|
||||
|
||||
|
||||
class HelpText(_CheckFunction):
|
||||
HELP_TEXT_FORMAT = re.compile("^\t .{,62}$")
|
||||
URL_ONLY = re.compile("^(http|https|git)://\S*$")
|
||||
|
|
Loading…
Reference in a new issue