1#!/usr/local/bin/python3.8 2 3# This file is part of the LibreOffice project. 4# 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/. 8 9""" 10Script to generate https://wiki.documentfoundation.org/Development/DispatchCommands 11""" 12 13import argparse 14import os 15import sys 16 17 18def get_files_list(directory, extension): 19 array_items = [] 20 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) 28 29 return array_items 30 31 32def 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 37 38 tmp = line.split(':') 39 slot_id = tmp[1].strip() 40 41 line = next(fh) 42 tmp = line.split(',') 43 slot_rid = tmp[1] 44 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 ' ' 53 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:' 66 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': ''} 72 73 74def 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 79 80 tmp = line.split('"') 81 slot_name = tmp[1] 82 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 90 91 line = line.replace('<value xml:lang="en-US">', '') 92 line = line.replace('</value>', '').strip() 93 94 if slot_name in all_slots: 95 all_slots[slot_name]['slot_description'] = line.replace('~', '') 96 97 98def 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 = {} 105 106 parser = argparse.ArgumentParser() 107 parser.add_argument('module', choices=modules) 108 args = parser.parse_args() 109 110 module_filename = args.module + sdi_ext 111 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) 117 118 xcu_files = get_files_list(xcu_dir, xcu_ext) 119 for xcu_file in xcu_files: 120 analyze_xcu(xcu_file, all_slots) 121 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) 126 127 print("|-") 128 129if __name__ == '__main__': 130 main() 131