[Libreoffice-commits] core.git: bin/list-dispatch-commands.php bin/list-dispatch-commands.py

Arkadiy Illarionov qarkai at gmail.com
Fri Mar 31 07:01:25 UTC 2017


 bin/list-dispatch-commands.php |  146 -----------------------------------------
 bin/list-dispatch-commands.py  |  130 ++++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 146 deletions(-)

New commits:
commit b57af3320fe7230dbcf5a0f6577e05bb5ec046cc
Author: Arkadiy Illarionov <qarkai at gmail.com>
Date:   Thu Mar 30 11:04:38 2017 +0300

    tdf#106737 Rewrite bin/list-dispatch-commands.php in Python
    
    Change-Id: I2f3830b23c874fad09bd5a5cc53d73a6a0368592
    Reviewed-on: https://gerrit.libreoffice.org/35897
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/bin/list-dispatch-commands.php b/bin/list-dispatch-commands.php
deleted file mode 100755
index b3e5262b0adc..000000000000
--- a/bin/list-dispatch-commands.php
+++ /dev/null
@@ -1,146 +0,0 @@
-#!/usr/bin/env php
-<?php
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-/// Script to generate https://wiki.documentfoundation.org/Development/DispatchCommands
-
-function getFilesList($directory, $extension) {
-    $arrayItems = array();
-    $skipByExclude = false;
-    $handle = opendir($directory);
-    if ($handle) {
-        while (false !== ($file = readdir($handle))) {
-            if ($file !== "." && $file !== "..") {
-                if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
-                    $arrayItems = array_merge($arrayItems, getFilesList($directory. DIRECTORY_SEPARATOR . $file, $extension));
-                } else {
-                    $file = $directory . DIRECTORY_SEPARATOR . $file;
-                    if (substr($file, -4) === $extension)
-                        $arrayItems[] = $file;
-                }
-            }
-        }
-    }
-    closedir($handle);
-    return $arrayItems;
-}
-
-function addMode(&$mode, $haystack, $needle, $letter) {
-    $mode .= (strpos($haystack, $needle) === FALSE) ? " " : $letter;
-}
-
-function analyseFile($fileName) {
-    global $allSlots;
-
-    $lines = file($fileName);
-    $index = 0;
-    $count = count($lines);
-    while ($index<$count) {
-        $aLine = $lines[$index];
-        if(substr($aLine, 0, 12) === "// Slot Nr. ") {
-            $tmp = explode(':', $aLine);
-            $slotId = trim($tmp[1]);
-            $index++;
-            $aLine = $lines[$index];
-            $tmp = explode(',', $aLine);
-            $slotRID = $tmp[1];
-
-            $index += 3;
-            $aLine = $lines[$index];
-            $mode = "";
-            addMode($mode, $aLine, "CACHABLE",      "C");
-            addMode($mode, $aLine, "AUTOUPDATE",    "U");
-            addMode($mode, $aLine, "MENUCONFIG",    "M");
-            addMode($mode, $aLine, "TOOLBOXCONFIG", "T");
-            addMode($mode, $aLine, "ACCELCONFIG",   "A");
-            $index += 3;
-            $aLine = $lines[$index];
-            if (strpos($aLine, '"') === FALSE) {
-                $index++;
-                $aLine = $lines[$index];
-            }
-            $tmp = explode('"', $aLine);
-            $slotName = ".uno:" . $tmp[1];
-            if (array_key_exists($slotName, $allSlots))
-                $slotDescription = $allSlots[$slotName];
-            else
-                $slotDescription = "No description";
-            if (!array_key_exists($slotName, $allSlots)) {
-                $allSlots[$slotName] = new StdClass;
-                $allSlots[$slotName]->slotId = $slotId;
-                $allSlots[$slotName]->slotRID = $slotRID;
-                $allSlots[$slotName]->mode = $mode;
-                $allSlots[$slotName]->slotDescription = "";
-            }
-        }
-        $index++;
-    }
-}
-
-function analyseXCU($fileName)
-{
-    global $allSlots;
-
-    $lines = file($fileName);
-    $index = 0;
-    $count = count($lines);
-
-    while ($index < $count)
-    {
-        $aLine = $lines[$index];
-        if (strpos($aLine, '<node oor:name=".uno:') !== FALSE) {
-            $tmp = explode( '"', $aLine );
-            $slotName = $tmp[1];
-            $found = false;
-            while ($index < $count
-                && strpos($aLine, '<value xml:lang="en-US">') === FALSE ) {
-                $index++;
-                $aLine = $lines[$index];
-            }
-            $aLine = str_replace('<value xml:lang="en-US">', '', $aLine);
-            $aLine = trim(str_replace('</value>', '', $aLine));
-            if (array_key_exists($slotName, $allSlots))
-                $allSlots[$slotName]->slotDescription = str_replace('~', '', $aLine);
-        }
-        $index++;
-    }
-}
-
-
-if (count($argv) != 2) {
-    print "Syntax error: ids.php module\n\n";
-    print "  Module is one of:\n";
-    print "     basslots\n";
-    print "     scslots\n";
-    print "     sdgslots\n";
-    print "     sdslots\n";
-    print "     sfxslots\n";
-    print "     smslots\n";
-    print "     svxslots\n";
-    print "     swslots\n";
-    exit(1);
-}
-
-$allSlots = array();
-
-foreach (getFilesList("./workdir/SdiTarget", ".hxx") as $sdiFile)
-    if (basename($sdiFile, ".hxx") === $argv[1])
-        analyseFile($sdiFile);
-
-foreach (getFilesList("officecfg/registry/data/org/openoffice/Office/UI", ".xcu") as $xcuFile)
-    analyseXCU($xcuFile);
-
-ksort($allSlots);
-foreach ($allSlots as $name => $props) {
-    printf("|-\n| %s\n| %s\n| %d\n| %s\n| %s\n",
-        $name, $props->slotRID, $props->slotId, $props->mode, $props->slotDescription);
-}
-print ("|-\n");
-
-?>
diff --git a/bin/list-dispatch-commands.py b/bin/list-dispatch-commands.py
new file mode 100755
index 000000000000..0b13f89e891b
--- /dev/null
+++ b/bin/list-dispatch-commands.py
@@ -0,0 +1,130 @@
+#!/usr/bin/env python3
+
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+"""
+Script to generate https://wiki.documentfoundation.org/Development/DispatchCommands
+"""
+
+import argparse
+import os
+import sys
+
+
+def get_files_list(directory, extension):
+    array_items = []
+
+    dh = os.scandir(directory)
+    for entry in dh:
+        if entry.is_dir():
+            array_items += get_files_list(entry.path, extension)
+        elif entry.is_file():
+            if entry.name.endswith(extension):
+                array_items.append(entry.path)
+
+    return array_items
+
+
+def analyze_file(filename, all_slots):
+    with open(filename) as fh:
+        for line in fh:
+            if not line.startswith('// Slot Nr. '):
+                continue
+
+            tmp = line.split(':')
+            slot_id = tmp[1].strip()
+
+            line = next(fh)
+            tmp = line.split(',')
+            slot_rid = tmp[1]
+
+            next(fh)
+            next(fh)
+            line = next(fh)
+            mode = 'C' if 'CACHABLE' in line else ' '
+            mode += 'U' if 'AUTOUPDATE' in line else ' '
+            mode += 'M' if 'MENUCONFIG' in line else ' '
+            mode += 'T' if 'TOOLBOXCONFIG' in line else ' '
+            mode += 'A' if 'ACCELCONFIG' in line else ' '
+
+            next(fh)
+            next(fh)
+            line = next(fh)
+            if '"' not in line:
+                line = next(fh)
+            tmp = line.split('"')
+            try:
+                slot_name = '.uno:' + tmp[1]
+            except IndexError:
+                print("Warning: expected \" in line '%s' from file %s" % (line.strip(), filename),
+                      file=sys.stderr)
+                slot_name = '.uno:'
+
+            if slot_name not in all_slots:
+                all_slots[slot_name] = {'slot_id': slot_id,
+                                        'slot_rid': slot_rid,
+                                        'mode': mode,
+                                        'slot_description': ''}
+
+
+def analyze_xcu(filename, all_slots):
+    with open(filename) as fh:
+        for line in fh:
+            if '<node oor:name=".uno:' not in line:
+                continue
+
+            tmp = line.split('"')
+            slot_name = tmp[1]
+
+            while '<value xml:lang="en-US">' not in line:
+                try:
+                    line = next(fh)
+                except StopIteration:
+                    print("Warning: couldn't find '<value xml:lang=\"en-US\">' line in %s" % filename,
+                          file=sys.stderr)
+                    break
+
+            line = line.replace('<value xml:lang="en-US">', '')
+            line = line.replace('</value>', '').strip()
+
+            if slot_name in all_slots:
+                all_slots[slot_name]['slot_description'] = line.replace('~', '')
+
+
+def main():
+    modules = ['basslots', 'scslots', 'sdgslots', 'sdslots', 'sfxslots', 'smslots', 'svxslots', 'swslots']
+    sdi_dir = './workdir/SdiTarget'
+    sdi_ext = '.hxx'
+    xcu_dir = 'officecfg/registry/data/org/openoffice/Office/UI'
+    xcu_ext = '.xcu'
+    all_slots = {}
+
+    parser = argparse.ArgumentParser()
+    parser.add_argument('module', choices=modules)
+    args = parser.parse_args()
+
+    module_filename = args.module + sdi_ext
+
+    sdi_files = get_files_list(sdi_dir, sdi_ext)
+    for sdi_file in sdi_files:
+        sdi_file_basename = os.path.basename(sdi_file)
+        if sdi_file_basename == module_filename:
+            analyze_file(sdi_file, all_slots)
+
+    xcu_files = get_files_list(xcu_dir, xcu_ext)
+    for xcu_file in xcu_files:
+        analyze_xcu(xcu_file, all_slots)
+
+    for name in sorted(all_slots.keys()):
+        props = all_slots[name]
+        print('|-\n| %s' % name)
+        print('| %(slot_rid)s\n| %(slot_id)s\n| %(mode)s\n| %(slot_description)s' % props)
+
+    print("|-")
+
+if __name__ == '__main__':
+    main()


More information about the Libreoffice-commits mailing list