Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/callabletask.py: 50%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 17:39 +0000

1import functools 

2import inspect 

3 

4from casatasks import casalog 

5 

6 

7def log_origin_setter(func): 

8 """ 

9 This is a decorator function for a casatask calling other casatasks. 

10 

11 This decorator is intended to be used on a "super" casatask calling "sub" casatasks. 

12 Its effect is to set the origin of messages logged by the "sub" tasks called by the "super" task to "super" 

13 For example: 

14 super_casatask::casa "Msg from super task" 

15 super_casatask::casa "Msg from sub-task1 called by super task" 

16 super_casatask::casa "Msg from sub-task1 called by super task" 

17 

18 Usage: 

19 

20 @log_origin_setter 

21 def sometask(..) 

22 pass 

23 

24 def othertask(..) 

25 sometask(*args, **kwargs) # logged "othertask::..." 

26 """ 

27 @functools.wraps(func) 

28 def wrapper(*args, **kwargs): 

29 __set_origin(inspect.stack(), casalog.getOrigin(), func.__name__) 

30 

31 retval = func(*args, **kwargs) 

32 

33 return retval 

34 

35 return wrapper 

36 

37 

38def __set_origin(callstack, origin, funcname): 

39 for frame_info in callstack: 

40 if frame_info.function == origin: 

41 casalog.origin(origin) 

42 return 

43 casalog.origin(funcname)