From b4a224d1a91232a16b70be4531a3e6fd2d9bc9ae Mon Sep 17 00:00:00 2001 From: Rosemary Date: Tue, 23 Jun 2015 14:34:06 +0530 Subject: tdf#80387 Extended lint-ui.py to check for UI title labels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I47ab882b0d54711050da4fc8fa288b195949eb60 Reviewed-on: https://gerrit.libreoffice.org/16425 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- bin/lint-ui.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bin/lint-ui.py b/bin/lint-ui.py index 54e1d27fb19e..2ed80c2523fb 100755 --- a/bin/lint-ui.py +++ b/bin/lint-ui.py @@ -11,6 +11,7 @@ import sys import xml.etree.ElementTree as ET +import re DEFAULT_WARNING_STR = 'Lint assertion failed' @@ -23,6 +24,8 @@ ALIGNMENT_TOP_PADDING = '6' MESSAGE_BOX_SPACING = '24' MESSAGE_BORDER_WIDTH = '12' +IGNORED_WORDS = ['the', 'of', 'to', 'for', 'a', 'and', 'as', 'from', 'on', 'into', 'by', 'at', 'or', 'do', 'in', 'when'] + def lint_assert(predicate, warning=DEFAULT_WARNING_STR): if not predicate: print(" * " + warning) @@ -77,6 +80,19 @@ def check_alignment_top_padding(alignment): lint_assert(top_padding.text == ALIGNMENT_TOP_PADDING, "GtkAlignment 'top_padding' should be " + ALIGNMENT_TOP_PADDING) +def check_title_labels(root): + labels = root.findall(".//child[@type='label']") + titles = [label.find(".//property[@name='label']") for label in labels] + for title in titles: + if title is None: + continue + words = re.split(r'[^a-zA-Z0-9_-]', title.text) + first = True + for word in words: + if word[0].islower() and (word not in IGNORED_WORDS or first): + lint_assert(False, "The word '" + word + "' should be capitalized") + first = False + def main(): print(" == " + sys.argv[1] + " ==") tree = ET.parse(sys.argv[1]) @@ -102,5 +118,7 @@ def main(): check_frames(root) + check_title_labels(root) + if __name__ == "__main__": main() -- cgit