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 - def __init__(self, xyz, *args, **kwargs):
55 self.xyz = xyz
56
57
58 self.intversion = 0
59
60
61
62 self.public = {}
63
64
65
66 self.public_data = {}
67
68 self.ns = Namespace(u":".join(("", self.NAMESPACE, self.NAME)))
69
70 try:
71 self.conf = self.xyz.conf[u"plugins"][self.ns.pfull]
72 except KeyError:
73 self.conf = {}
74
75
76
78 """
79 Provide transparent access to public methods
80 """
81
82 try:
83 return self.public[method]
84 except KeyError:
85 raise AttributeError(_(u"%s is not a public method" % method))
86
87
88
90 """
91 Provide transparent access to public data
92 """
93
94 try:
95 return self.public_data[obj]
96 except KeyError:
97 raise AttributeError(_(u"%s is not a public data object " % obj))
98
99
100
101 - def prepare(self, *args, **kwargs):
102 """
103 Plugin constructor
104 """
105
106 pass
107
108
109
111 """
112 Plugin destructor
113 """
114
115 pass
116
117
118
120 """
121 Export method
122 """
123
124 _name = func.im_func.__name__
125
126 func.im_func.ns = u"%s:%s" % (self.ns.full, _name)
127
128 self.public[_name] = func
129
130
131
133 """
134 Export data
135 """
136
137 self.public_data[name] = data
138
139
140
141 - def run_hook(self, hook, *args, **kwargs):
142 """
143 Run hook
144 """
145
146 self.xyz.hm.dispatch("hook%s:%s" % (self.ns.pfull, hook),
147 *args, **kwargs)
148