File: example_plugin.rst

package info (click to toggle)
paperwork 2.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 166,660 kB
  • sloc: python: 44,775; makefile: 992; sh: 625; xml: 135
file content (61 lines) | stat: -rw-r--r-- 2,298 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Plugin Example
==============


.. code-block:: python

    import openpaperwork_core

    class Plugin(openpaperwork_core.PluginBase):
        # callbacks will always be run before those of priority <= 21
        # but after those of priority >= 23
        PRIORITY = 22

        def __init__(self):
            # do something, but the least possible
            # cannot rely on any dependencies here.
            pass

        def get_interfaces(self):
           # indicates which interfaces this plugin satisfies.
           # note that this is only used for controlling that dependencies are
           # satisfied (see get_deps()). There are no checks at all to ensure
           # that the methods corresponding to each interface are actually
           # implemented.
           return ['interface_name_toto', 'interface_name_tutu']

        def get_deps(self):
            # specify that we are looking for plugins implementing the
            # specified interface(s).
            # Provide also some default plugins to load if no plugins provide
            # the requested interface yet.
            # Note that plugins may be loaded in any order. Dependencies may
            # not be satisfied yet when they are loaded.
            # When initializing plugins, the core will make sure that
            # all dependencies are satisfied, loaded and initialized before
            # calling the method `init()` of this plugin.
            return [
                {
                    'interface': 'interface_name_a',
                    'defaults': [
                        'suggested_default_plugin_a',
                        'suggested_default_plugin_b',
                    ],
                },
                {
                   'interface': 'inteface_name_b',
                    'defaults': [
                        'suggested_default_plugin_d',
                        'suggested_default_plugin_e',
                    ],
                }
            ]

        def init(self, core):
            # all the dependencies have loaded and initialized.
            # we can safely rely on them here.
            super().init(core)

        def some_method_a(self, arg_a):
            # do something
            self.core.call_all("some_method_of_other_plugins", "arg_a", 22)