Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / bin / list-dispatch-commands.py
blob0b13f89e891b5b35ced9f884cf7e264bfb28e34d
1 #!/usr/bin/env python3
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 """
10 Script to generate https://wiki.documentfoundation.org/Development/DispatchCommands
11 """
13 import argparse
14 import os
15 import sys
18 def get_files_list(directory, extension):
19 array_items = []
21 dh = os.scandir(directory)
22 for entry in dh:
23 if entry.is_dir():
24 array_items += get_files_list(entry.path, extension)
25 elif entry.is_file():
26 if entry.name.endswith(extension):
27 array_items.append(entry.path)
29 return array_items
32 def analyze_file(filename, all_slots):
33 with open(filename) as fh:
34 for line in fh:
35 if not line.startswith('// Slot Nr. '):
36 continue
38 tmp = line.split(':')
39 slot_id = tmp[1].strip()
41 line = next(fh)
42 tmp = line.split(',')
43 slot_rid = tmp[1]
45 next(fh)
46 next(fh)
47 line = next(fh)
48 mode = 'C' if 'CACHABLE' in line else ' '
49 mode += 'U' if 'AUTOUPDATE' in line else ' '
50 mode += 'M' if 'MENUCONFIG' in line else ' '
51 mode += 'T' if 'TOOLBOXCONFIG' in line else ' '
52 mode += 'A' if 'ACCELCONFIG' in line else ' '
54 next(fh)
55 next(fh)
56 line = next(fh)
57 if '"' not in line:
58 line = next(fh)
59 tmp = line.split('"')
60 try:
61 slot_name = '.uno:' + tmp[1]
62 except IndexError:
63 print("Warning: expected \" in line '%s' from file %s" % (line.strip(), filename),
64 file=sys.stderr)
65 slot_name = '.uno:'
67 if slot_name not in all_slots:
68 all_slots[slot_name] = {'slot_id': slot_id,
69 'slot_rid': slot_rid,
70 'mode': mode,
71 'slot_description': ''}
74 def analyze_xcu(filename, all_slots):
75 with open(filename) as fh:
76 for line in fh:
77 if '<node oor:name=".uno:' not in line:
78 continue
80 tmp = line.split('"')
81 slot_name = tmp[1]
83 while '<value xml:lang="en-US">' not in line:
84 try:
85 line = next(fh)
86 except StopIteration:
87 print("Warning: couldn't find '<value xml:lang=\"en-US\">' line in %s" % filename,
88 file=sys.stderr)
89 break
91 line = line.replace('<value xml:lang="en-US">', '')
92 line = line.replace('</value>', '').strip()
94 if slot_name in all_slots:
95 all_slots[slot_name]['slot_description'] = line.replace('~', '')
98 def main():
99 modules = ['basslots', 'scslots', 'sdgslots', 'sdslots', 'sfxslots', 'smslots', 'svxslots', 'swslots']
100 sdi_dir = './workdir/SdiTarget'
101 sdi_ext = '.hxx'
102 xcu_dir = 'officecfg/registry/data/org/openoffice/Office/UI'
103 xcu_ext = '.xcu'
104 all_slots = {}
106 parser = argparse.ArgumentParser()
107 parser.add_argument('module', choices=modules)
108 args = parser.parse_args()
110 module_filename = args.module + sdi_ext
112 sdi_files = get_files_list(sdi_dir, sdi_ext)
113 for sdi_file in sdi_files:
114 sdi_file_basename = os.path.basename(sdi_file)
115 if sdi_file_basename == module_filename:
116 analyze_file(sdi_file, all_slots)
118 xcu_files = get_files_list(xcu_dir, xcu_ext)
119 for xcu_file in xcu_files:
120 analyze_xcu(xcu_file, all_slots)
122 for name in sorted(all_slots.keys()):
123 props = all_slots[name]
124 print('|-\n| %s' % name)
125 print('| %(slot_rid)s\n| %(slot_id)s\n| %(mode)s\n| %(slot_description)s' % props)
127 print("|-")
129 if __name__ == '__main__':
130 main()