2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # this tool rips out configuration pieces that are not useful for
9 # a mobile viewer / editing application without a full UI.
11 # ideally the postprocess/ makefile would cope with this but its
12 # already over-complicated by rampant conditionals.
15 import xml
.etree
.ElementTree
as ET
18 'org.openoffice.Office/TableWizard', # huge
20 'org.openoffice.Office/WebWizard',
21 'org.openoffice.Office.DataAccess/Drivers', # no database
22 'org.openoffice.Office/Addons', # no addons
24 # no conventional UI; reverse sorted by size
25 'org.openoffice.Office.UI/GenericCommands',
26 'org.openoffice.Office.UI/DrawImpressCommands',
27 'org.openoffice.Office.UI/Sidebar',
28 'org.openoffice.Office.UI/ChartCommands',
29 'org.openoffice.Office.UI/DbuCommands',
30 'org.openoffice.Office.UI/Controller',
31 'org.openoffice.Office.UI/StartModuleCommands',
32 'org.openoffice.Office.UI/BasicIDEWindowState',
33 'org.openoffice.Office.UI/GenericCategories',
34 'org.openoffice.Office.UI/ChartWindowState',
35 'org.openoffice.Office.UI/BaseWindowState',
36 'org.openoffice.Office.UI/BasicIDECommands',
37 'org.openoffice.Office.UI/BibliographyCommands',
38 'org.openoffice.Office.UI/DbQueryWindowState',
39 'org.openoffice.Office.UI/DbRelationWindowState',
40 'org.openoffice.Office.UI/DbTableWindowState',
41 'org.openoffice.Office.UI/DbTableDataWindowState',
42 'org.openoffice.Office.UI/DbBrowserWindowState',
43 'org.openoffice.Office.UI/WindowContentFactories',
44 'org.openoffice.Office.UI/StartModuleWindowState',
45 'org.openoffice.Office.UI/GlobalSettings',
46 'org.openoffice.Office.UI/BibliographyWindowState',
47 'org.openoffice.Office.UI/Category',
50 if __name__
== '__main__':
51 tree
= ET
.parse(sys
.argv
[1])
56 total
+= len(ET
.tostring(child
))
62 section
= child
.attrib
['{http://openoffice.org/2001/registry}name']
63 package
= child
.attrib
['{http://openoffice.org/2001/registry}package']
64 size
= len(ET
.tostring(child
));
65 key
= '%s/%s' % (package
, section
)
66 if key
in main_xcd_discard
:
67 print 'removed %s - saving %d' % (key
, size
)
69 to_remove
.append(child
)
71 for child
in to_remove
:
74 print "saved %d of %d bytes: %2.f%%" % (saved
, total
, saved
*100.0/total
)
76 # Don't do pointless Word -> Writer and similar conversions when we have no UI.
78 "component-schema": "{http://openoffice.org/2001/registry}component-schema",
79 "component-data": "{http://openoffice.org/2001/registry}component-data",
80 "name": "{http://openoffice.org/2001/registry}name",
82 microsoftImport
= '%(component-schema)s[@%(name)s="Common"]/component/group[@%(name)s="Filter"]/group[@%(name)s="Microsoft"]/group[@%(name)s="Import"]/prop' % nsDict
83 props
= root
.findall(microsoftImport
)
85 prop
.findall("value")[0].text
= "false"
87 # Disable View -> Text Boundaries
88 for prop
in root
.findall('%(component-schema)s[@%(name)s="UI"]/templates/group[@%(name)s="ColorScheme"]/group[@%(name)s="DocBoundaries"]/prop' % nsDict
):
89 for value
in prop
.findall("value"):
92 # Disable Table -> Table Boundaries
93 for prop
in root
.findall('%(component-schema)s[@%(name)s="UI"]/templates/group[@%(name)s="ColorScheme"]/group[@%(name)s="TableBoundaries"]/prop' % nsDict
):
94 for value
in prop
.findall("value"):
97 # Disable follow link with Ctrl+Click, use Click only for mobile app.
98 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
):
99 for value
in prop
.findall("value"):
102 # Disable Impress View -> Slide Pane
103 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
):
104 for value
in prop
.findall("value"):
107 # The namespace prefixes xs and oor are present in attribute *values*, and namespace
108 # declarations for them are needed, even if no actual elements or attributes with these
109 # namespace prefixes are present. Fun.
110 root
.set('xmlns:xs', 'http://www.w3.org/2001/XMLSchema')
111 root
.set('xmlns:oor', 'http://openoffice.org/2001/registry')
113 tree
.write(sys
.argv
[2], 'UTF-8', True)
115 # vim:set shiftwidth=4 softtabstop=4 expandtab: