[Libreoffice-commits] core.git: bin/lint-ui.py

Rosemary rosemaryseb8 at gmail.com
Thu Jun 25 06:29:30 PDT 2015


 bin/lint-ui.py |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

New commits:
commit b4a224d1a91232a16b70be4531a3e6fd2d9bc9ae
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Tue Jun 23 14:34:06 2015 +0530

    tdf#80387 Extended lint-ui.py to check for UI title labels
    
    Change-Id: I47ab882b0d54711050da4fc8fa288b195949eb60
    Reviewed-on: https://gerrit.libreoffice.org/16425
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/bin/lint-ui.py b/bin/lint-ui.py
index 54e1d27..2ed80c2 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()


More information about the Libreoffice-commits mailing list