#!/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/. # # This script is used to generate the convertfilters.xhp file located # in helpcontent2/source/text/shared/guide. # # Run this script followed by the path of instdir/share/registry/ # i.e.: ./convertfilters.py /path/to/source/core/instdir/share/registry # # Requires Python 3.6 or greater. import os import sys import random import time from math import floor from lxml import etree output_file_path = os.path.join(os.path.dirname(sys.argv[0]), "convertfilters.xhp") try: registry_dir = sys.argv[1] except IndexError: print("Usage: ./convertfilters.py /path/to/source/core/instdir/share/registry") sys.exit(1) if not os.path.exists(registry_dir): print(f"{registry_dir} does not exist. Make sure you have built the core repo before running this script") sys.exit(1) modules = ["writer.xcd","calc.xcd","impress.xcd","draw.xcd","math.xcd","base.xcd","graphicfilter.xcd"] def gen_id(apiname): '''This function accepts module name and an API Name of the filter, and then generate a unique ID. API Names are used since they are unique within the page. Do not use random numbers or sequence-count numbers here since it will cause all words to be "fuzzy" in PO files when the xhp file is regenerated. ''' apiname = apiname.replace(" ", "_") apiname = apiname.replace("(", "_") apiname = apiname.replace(")", "_") apiname = apiname.replace("/", "_") return apiname output = ''' File Conversion Filters Tables /text/shared/guide/convertfilters.xhp
filters;document conversion document conversion;filters convert-to;filters command line document conversion;filters module file filters

File Conversion Filter Names

Tables with filter names for command line document conversion.
''' output += ''' Filter Name API Name Media Type (Extension) ''' for module in modules: print("\n-------" + module + "----------") module_path = os.path.join(registry_dir, module) tree = etree.parse(module_path) namespaces = tree.getroot().nsmap filternodes = tree.findall( 'oor:component-data[@oor:name="Filter"]/node', namespaces)[-1] filters = [] for filter_node in filternodes: uiname = str(filter_node.findtext('prop[@oor:name="UIName"]/value', namespaces=namespaces)) apiname = filter_node.attrib['{' + namespaces['oor'] + '}name'] filter_type = str(filter_node.findtext('prop[@oor:name="Type"]/value', namespaces=namespaces)) type_node = tree.find( f'oor:component-data[@oor:name="Types"]/node/node[@oor:name="{filter_type}"]', namespaces) try: mediatype = str(type_node.findtext('prop[@oor:name="MediaType"]/value', namespaces=namespaces)) extensions = str(type_node.findtext('prop[@oor:name="Extensions"]/value', namespaces=namespaces)) except AttributeError: continue filter_data = [uiname, apiname, mediatype, extensions] print(filter_data) filters.append(filter_data) output += f'\
\n\ \n\ command line document conversion; filters for {module[:-4].upper()}\n\ \n\

Filters for {module[:-4].upper()}

\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ ' for item in filters: uid = gen_id(item[1]) output += f'\ \n\ \n\ {item[0]}\n\ \n\ \n\ {item[1]}\n\ \n\ \n\ {item[2]} ({item[3]})\n\ \n\ \n' output += f'\
\n\
\n' output += f'\ \n\
' with open(output_file_path, "w") as f: f.write(output) print(f'\nDone. File saved at: {output_file_path}.') print(f'Please move this file into helpcontent2/source/text/shared/guide.')