xref: /trunk/test/aoo-test/src/aootest/oxt.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
1################################################################
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20################################################################
21
22"""Builds a small extension (a Python UNO component) with zipfile, so installing one needs no compiler or JRE."""
23import zipfile
24from pathlib import Path
25
26IDENTIFIER = "org.apache.openoffice.aootest.testextension"
27SERVICE = "com.sun.star.comp.smoketest.TestExtension"
28IMPLEMENTATION = "com.sun.star.comp.smoketest.TestExtension$_TestExtension"
29FILE_NAME = "TestExtension.oxt"
30
31COMPONENT = """import unohelper
32from com.sun.star.lang import XServiceInfo
33
34IMPL = %(impl)r
35SERVICE = %(service)r
36
37
38class TestExtension(unohelper.Base, XServiceInfo):
39    def __init__(self, ctx):
40        self.ctx = ctx
41
42    def getImplementationName(self):
43        return IMPL
44
45    def supportsService(self, name):
46        return name == SERVICE
47
48    def getSupportedServiceNames(self):
49        return (SERVICE,)
50
51
52g_ImplementationHelper = unohelper.ImplementationHelper()
53g_ImplementationHelper.addImplementation(TestExtension, IMPL, (SERVICE,))
54""" % {"impl": IMPLEMENTATION, "service": SERVICE}
55
56MANIFEST = """<?xml version="1.0" encoding="UTF-8"?>
57<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
58 <manifest:file-entry manifest:full-path="testextension.py" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
59</manifest:manifest>
60"""
61
62DESCRIPTION = """<?xml version="1.0" encoding="UTF-8"?>
63<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink">
64 <identifier value="%s"/>
65 <version value="1.0"/>
66 <display-name><name lang="en">AOO test suite extension</name></display-name>
67</description>
68""" % IDENTIFIER
69
70
71def build(directory):
72    """Writes TestExtension.oxt into `directory` and returns its path."""
73    path = Path(directory) / FILE_NAME
74    with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:
75        z.writestr("META-INF/manifest.xml", MANIFEST)
76        z.writestr("description.xml", DESCRIPTION)
77        z.writestr("testextension.py", COMPONENT)
78    return path
79