1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from libxyz.exceptions import PluginError
18 from libxyz.core.plugins import Namespace
19
21 """
22 Parent class for all xyz-plugins
23 """
24
25
26 NAME = None
27
28
29 AUTHOR = None
30
31
32 VERSION = None
33
34
35 BRIEF_DESCRIPTION = None
36
37
38 FULL_DESCRIPTION = None
39
40
41
42 NAMESPACE = None
43
44
45
46 MIN_XYZ_VERSION = None
47
48
49 DOC = None
50
51
52 HOMEPAGE = None
53
54
55
56 EVENTS = None
57
58 - def __init__(self, xyz, *args, **kwargs):
59 self.xyz = xyz
60
61
62 self.intversion = 0
63
64
65
66 self.public = {}
67
68
69
70 self.public_data = {}
71
72 self.ns = Namespace(u":".join(("", self.NAMESPACE, self.NAME)))
73
74 try:
75 self.conf = self.xyz.conf[u"plugins"][self.ns.pfull]
76 except KeyError:
77 self.conf = {}
78
79
80
82 """
83 Provide transparent access to public methods
84 """
85
86 try:
87 return self.public[method]
88 except KeyError:
89 raise AttributeError(_(u"%s is not a public method" % method))
90
91
92
94 """
95 Provide transparent access to public data
96 """
97
98 try:
99 return self.public_data[obj]
100 except KeyError:
101 raise AttributeError(_(u"%s is not a public data object " % obj))
102
103
104
105 - def prepare(self, *args, **kwargs):
106 """
107 Plugin constructor
108 """
109
110 pass
111
112
113
115 """
116 Plugin destructor
117 """
118
119 pass
120
121
122
124 """
125 Export method
126 """
127
128 _name = func.im_func.__name__
129
130 func.im_func.ns = u"%s:%s" % (self.ns.full, _name)
131
132 self.public[_name] = func
133
134
135
137 """
138 Export data
139 """
140
141 self.public_data[name] = data
142
143
144
151
152
153
155 """
156 Return full event name
157 """
158
159 return "event%s:%s" % (self.ns.pfull, short)
160