[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - loleaflet/Makefile.am loleaflet/unocommands.js scripts/unocommands.py

Jan Holesovsky kendy at collabora.com
Fri Dec 8 09:38:50 UTC 2017


 loleaflet/Makefile.am    |    1 
 loleaflet/unocommands.js |   18 ++++-----
 scripts/unocommands.py   |   87 ++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 77 insertions(+), 29 deletions(-)

New commits:
commit 457f929357adf7f52e0fc9281d41df3f29859467
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Dec 7 10:42:58 2017 +0100

    l10n: Implement --check to notice not covered .uno: commands early.
    
    Change-Id: I928f2cef8d9a869c10fa6c6370a7ce1c811631c8
    Reviewed-on: https://gerrit.libreoffice.org/46014
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 07209238..b64ca8d7 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -21,6 +21,7 @@ JQUERY_UI_DIST_IMAGES = $(patsubst $(JQUERY_UI_IMAGE_PATH)/%.png,dist/$(JQUERY_U
 EXTRA_DIST = $(shell find . -type f -not -path './.git/*' | sed 's/.\///')
 
 all-local: node_modules $(L10N_JSON) $(L10N_STYLES_JSON) $(JQUERY_UI_DIST_IMAGES)
+	$(abs_top_srcdir)/scripts/unocommands.py --check $(abs_top_srcdir)
 	rm -rf dist/plugins/draw-$(DRAW_VERSION) && mkdir -p dist/plugins/draw-$(DRAW_VERSION)
 	cd plugins/draw-$(DRAW_VERSION) && jake build && cp -ar dist ../../dist/plugins/draw-$(DRAW_VERSION)
 	jake build debug=$(ENABLE_DEBUG) minify=$(MINIFY)
diff --git a/loleaflet/unocommands.js b/loleaflet/unocommands.js
index 1670af79..b2c0c736 100644
--- a/loleaflet/unocommands.js
+++ b/loleaflet/unocommands.js
@@ -153,13 +153,13 @@ var unoCommandsArray = {
 };
 
 global._UNO = function(string) {
-        var text = unoCommandsArray[string.substr(5)];
-        if (text !== undefined) {
-            text = text.replace('~', '');
-        } else {
-            // we should avoid this, but when it happens, present at least
-            // somehow reasonable text
-            text = string.substr(5);
-        }
-        return text;
+    var text = unoCommandsArray[string.substr(5)];
+    if (text !== undefined) {
+        text = text.replace('~', '');
+    } else {
+        // we should avoid this, but when it happens, present at least
+        // somehow reasonable text
+        text = string.substr(5);
+    }
+    return text;
 }
diff --git a/scripts/unocommands.py b/scripts/unocommands.py
index 55d0e289..7146be69 100755
--- a/scripts/unocommands.py
+++ b/scripts/unocommands.py
@@ -14,7 +14,18 @@ import sys
 from lxml import etree
 
 def usage():
-    message = """usage: {program} loffice_srcdir online_srcdir"""
+    message = """usage: {program} [--check] online_srcdir [loffice_srcdir]
+
+Extracts .uno: command descriptions from the LibreOffice XCU files.
+Also it is used during build to check consistency of unocommands.js.
+
+loffice_srcdir does not have to be provided when --check param is
+specified.
+
+Example:
+    {program} --check /path/to/online
+    {program} /path/to/online /path/to/loffice > unocommands.js
+"""
     print(message.format(program = os.path.basename(sys.argv[0])))
 
 # Extract uno commands name from lines like "  'Command1', 'Command2',"
@@ -98,16 +109,10 @@ def printCommandsFromXCU(xcu, commands):
 
     return descriptions
 
-if __name__ == "__main__":
-    if len(sys.argv) != 3:
-        usage()
-        exit(1)
-
-    commands = extractCommands(sys.argv[2])
-
-    # build the uno descriptions from all the xcu files
+# Print commands from all the XCU files, and collect them too
+def printCommands(lofficeDir, commands):
     descriptions = {}
-    dir = sys.argv[1] + '/officecfg/registry/data/org/openoffice/Office/UI'
+    dir = lofficeDir + '/officecfg/registry/data/org/openoffice/Office/UI'
     for file in os.listdir(dir):
         if file.endswith(".xcu"):
             descriptions.update(printCommandsFromXCU(os.path.join(dir, file), commands))
@@ -123,20 +128,62 @@ var unoCommandsArray = {'''
     print '''};
 
 global._UNO = function(string) {
-        var text = unoCommandsArray[string.substr(5)];
-        if (text !== undefined) {
-            text = text.replace('~', '');
-        } else {
-            // we should avoid this, but when it happens, present at least
-            // somehow reasonable text
-            text = string.substr(5);
-        }
-        return text;
+    var text = unoCommandsArray[string.substr(5)];
+    if (text !== undefined) {
+        text = text.replace('~', '');
+    } else {
+        // we should avoid this, but when it happens, present at least
+        // somehow reasonable text
+        text = string.substr(5);
+    }
+    return text;
 }'''
 
+    return descriptions
+
+# Read the uno commands present in the unocommands.js for checking
+def parseUnocommandsJS(onlineDir):
+    descriptions = {}
+
+    f = open(onlineDir + '/loleaflet/unocommands.js', 'r')
+    readingCommands = False
+    for line in f:
+        m = re.match(r"    ([^:]*): _\('([^']*)'\),", line)
+        if m:
+            command = m.group(1)
+            text = m.group(2)
+            descriptions[command] = text
+
+    return descriptions
+
+if __name__ == "__main__":
+    if len(sys.argv) != 3:
+        usage()
+        exit(1)
+
+    check = False
+    onlineDir = ''
+    lofficeDir = ''
+    if (sys.argv[1] == '--check'):
+        check = True
+        onlineDir = sys.argv[2]
+    else:
+        onlineDir = sys.argv[1]
+        lofficeDir = sys.argv[2]
+
+    commands = extractCommands(onlineDir)
+
+    # build the uno descriptions from all the xcu files
+    descriptions = {}
+    if (check):
+        descriptions = parseUnocommandsJS(onlineDir)
+    else:
+        descriptions = printCommands(lofficeDir, commands)
+
     # check that we have translations for everything
     dif = commands - set(descriptions.keys())
     if len(dif) > 0:
-        sys.stderr.write("ERROR: The following commands are not covered:\n\n.uno:" + '\n.uno:'.join(dif) + "\n")
+        sys.stderr.write("ERROR: The following commands are not covered in unocommands.js:\n\n.uno:" + '\n.uno:'.join(dif) + "\n\n")
+        exit(1)
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list