This decorator prints warning message each time decorated function
is called. Warning message contains name of the called method and
name of the class in which the method belongs.
For using the decorator, just add @deprecated before method definition
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Common/Utils.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py
index c283b99..b42fc86 100644
--- a/lnst/Common/Utils.py
+++ b/lnst/Common/Utils.py
@@ -9,6 +9,7 @@ published by the Free Software Foundation; see COPYING for details.
__autor__ = """
jzupka(a)redhat.com (Jiri Zupka)
"""
+import functools
import logging
import time
import re
@@ -263,3 +264,17 @@ def std_deviation(values):
s1 += val
s2 += val**2
return (math.sqrt(len(values)*s2 - s1**2))/len(values)
+
+def deprecated(func):
+ """
+ Decorator which marks the method as deprecated - meaning when used,
+ it logs warning message with name of the method and class it belongs to
+ """
+
+ @functools.wraps(func)
+ def log(self, *args, **kwargs):
+ logging.warning("Function %s from class %s is deprecated, please, "\
+ "check documentation for up-to-date method"
+ % (func.__name__, self.__class__.__name__))
+ return func(self, *args, **kwargs)
+ return log
--
2.4.3