comparison python/actions.py @ 256:f40a172512c6

more playing around
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 16 Dec 2012 22:51:18 -0800
parents 1f7325245dc8
children f4594857d606
comparison
equal deleted inserted replaced
255:1f7325245dc8 256:f40a172512c6
3 class Actions(object): 3 class Actions(object):
4 4
5 def __init__(self): 5 def __init__(self):
6 self.functions = {} 6 self.functions = {}
7 7
8 def __call__(self, function): 8 def __call__(self, function, *dependencies):
9 import pdb; pdb.set_trace()
9 self.functions[function.func_name] = function 10 self.functions[function.func_name] = function
10 return function 11 return function
11 12
12 def do(self, func_name, *args, **kwargs): 13 def do(self, func_name):
13 pass 14 self.functions[func_name]()
14 15
15 action = Actions() 16 action = Actions()
16 17
17 @action 18 @action
18 def foo(): 19 def foo():
19 print "hello" 20 print "hello"
20 21
21 @action 22 @action('foo')
22 def bar(): 23 def bar():
23 print "goodbye" 24 print "goodbye"
24 25
25 if __name__ == '__main__': 26 if __name__ == '__main__':
26 pass 27 pass
28
29 action.do('bar')