1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from libxyz.core import FSRule
18 from libxyz.core.utils import ustring
19 from libxyz.exceptions import XYZRuntimeError
20
22 """
23 Action rules handler
24 """
25
27 self.xyz = xyz
28 self._actions = []
29
30
31
33 """
34 Register function to be run upon matching rule
35 @param rule: String FS rule
36 @param fn: Action function. Function receives matched VFS object as
37 its only argument.
38 """
39
40 try:
41 _rule = FSRule(rule)
42 except Exception, e:
43 raise XYZRuntimeError(
44 _(u"Unable to register action: invalid rule: %s") %
45 ustring(str(e)))
46
47 self._actions.insert(0, (_rule, fn))
48
49
50
52 """
53 Loop through registered actions and return action assosiated
54 with the first matched rule. If no rule matched return None
55 """
56
57 for r, f in self._actions:
58 if r.match(vfsobj):
59 return f
60
61 return None
62