[cp] Flag a few more import filters as EXOTIC
[LibreOffice.git] / android / mobile-config.py
blob5998e5d1f9b71f95449eaedc5a8c9931aa5e4f2c
1 #!/usr/bin/env python3
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # this tool rips out configuration pieces that are not useful for
11 # a mobile viewer / editing application without a full UI.
13 # ideally the postprocess/ makefile would cope with this but its
14 # already over-complicated by rampant conditionals.
16 import sys
17 import xml.etree.ElementTree as ET
19 main_xcd_discard = [
20 'org.openoffice.Office/TableWizard', # huge
22 'org.openoffice.Office.DataAccess/Drivers', # no database
23 'org.openoffice.Office/Addons', # no addons
25 # no conventional UI; reverse sorted by size
26 'org.openoffice.Office.UI/GenericCommands',
27 'org.openoffice.Office.UI/DrawImpressCommands',
28 'org.openoffice.Office.UI/Sidebar',
29 'org.openoffice.Office.UI/ChartCommands',
30 'org.openoffice.Office.UI/DbuCommands',
31 'org.openoffice.Office.UI/Controller',
32 'org.openoffice.Office.UI/StartModuleCommands',
33 'org.openoffice.Office.UI/BasicIDEWindowState',
34 'org.openoffice.Office.UI/GenericCategories',
35 'org.openoffice.Office.UI/ChartWindowState',
36 'org.openoffice.Office.UI/BaseWindowState',
37 'org.openoffice.Office.UI/BasicIDECommands',
38 'org.openoffice.Office.UI/BibliographyCommands',
39 'org.openoffice.Office.UI/DbQueryWindowState',
40 'org.openoffice.Office.UI/DbRelationWindowState',
41 'org.openoffice.Office.UI/DbTableWindowState',
42 'org.openoffice.Office.UI/DbTableDataWindowState',
43 'org.openoffice.Office.UI/DbBrowserWindowState',
44 'org.openoffice.Office.UI/WindowContentFactories',
45 'org.openoffice.Office.UI/StartModuleWindowState',
46 'org.openoffice.Office.UI/GlobalSettings',
47 'org.openoffice.Office.UI/BibliographyWindowState',
48 'org.openoffice.Office.UI/Category',
51 if __name__ == '__main__':
52 tree = ET.parse(sys.argv[1])
53 root = tree.getroot()
55 total = 0
56 for child in root:
57 total += len(ET.tostring(child))
59 saved = 0
60 to_remove = []
62 for child in root:
63 section = child.attrib['{http://openoffice.org/2001/registry}name']
64 package = child.attrib['{http://openoffice.org/2001/registry}package']
65 size = len(ET.tostring(child));
66 key = '%s/%s' % (package, section)
67 if key in main_xcd_discard:
68 print('removed %s - saving %d' % (key, size))
69 saved = saved + size
70 to_remove.append(child)
72 for child in to_remove:
73 root.remove(child)
75 print("saved %d of %d bytes: %2.f%%" % (saved, total, saved*100.0/total))
77 # Don't do pointless Word -> Writer and similar conversions when we have no UI.
78 nsDict = {
79 "component-schema": "{http://openoffice.org/2001/registry}component-schema",
80 "component-data": "{http://openoffice.org/2001/registry}component-data",
81 "name": "{http://openoffice.org/2001/registry}name",
83 microsoftImport = '%(component-schema)s[@%(name)s="Common"]/component/group[@%(name)s="Filter"]/group[@%(name)s="Microsoft"]/group[@%(name)s="Import"]/prop' % nsDict
84 props = root.findall(microsoftImport)
85 for prop in props:
86 prop.findall("value")[0].text = "false"
88 # Disable View -> Text Boundaries
89 for prop in root.findall('%(component-schema)s[@%(name)s="UI"]/templates/group[@%(name)s="ColorScheme"]/group[@%(name)s="DocBoundaries"]/prop' % nsDict):
90 for value in prop.findall("value"):
91 value.text = "false"
93 # Disable Table -> Table Boundaries
94 for prop in root.findall('%(component-schema)s[@%(name)s="UI"]/templates/group[@%(name)s="ColorScheme"]/group[@%(name)s="TableBoundaries"]/prop' % nsDict):
95 for value in prop.findall("value"):
96 value.text = "false"
98 # Disable follow link with Ctrl+Click, use Click only for mobile app.
99 for prop in root.findall('%(component-schema)s[@%(name)s="Common"]/component/group[@%(name)s="Security"]/group[@%(name)s="Scripting"]/prop[@%(name)s="HyperlinksWithCtrlClick"]' % nsDict):
100 for value in prop.findall("value"):
101 value.text = "false"
103 # Disable Impress View -> Slide Pane
104 for prop in root.findall('%(component-data)s[@%(name)s="Impress"]/node[@%(name)s="MultiPaneGUI"]/node[@%(name)s="SlideSorterBar"]/node[@%(name)s="Visible"]/prop[@%(name)s="ImpressView"]' % nsDict):
105 for value in prop.findall("value"):
106 value.text = "false"
108 # The namespace prefixes xs and oor are present in attribute *values*, and namespace
109 # declarations for them are needed, even if no actual elements or attributes with these
110 # namespace prefixes are present. Fun.
111 root.set('xmlns:xs', 'http://www.w3.org/2001/XMLSchema')
112 root.set('xmlns:oor', 'http://openoffice.org/2001/registry')
114 tree.write(sys.argv[2], 'UTF-8', True)
116 # vim: set shiftwidth=4 softtabstop=4 expandtab: