Working on voice command logic.
[kiosk.git] / decorators.py
1 #!/usr/bin/env python3
2
3 from datetime import datetime
4 import functools
5
6
7 def invocation_logged(func):
8     @functools.wraps(func)
9     def wrapper(*args, **kwargs):
10         now = datetime.now()
11         timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)")
12         print("%s(%s): Entered function" % (func.__name__, timestamp))
13         ret = func(*args, **kwargs)
14         now = datetime.now()
15         timestamp = now.strftime("%d-%b-%Y (%H:%M:%S.%f)")
16         print("%s(%s): Exited function" % (func.__name__, timestamp))
17         return ret
18
19     return wrapper
20
21
22 # Test
23 # @invocation_logged
24 # def f(x):
25 #    print(x * x)
26 #    return x * x
27 #
28 # q = f(10)
29 # print(q)