Liron Ar has uploaded a new change for review.
Change subject: utils ......................................................................
utils
Change-Id: Icbd049360a02ae98fa21756dc734c1da8ac3d11a Signed-off-by: Liron Aravot laravot@redhat.com --- M lib/vdsm/utils.py 1 file changed, 26 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/30/23130/1
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index d593a73..e39a245 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -52,6 +52,7 @@ import threading import time import zombiereaper +import inspect
from cpopen import CPopen from . import constants @@ -643,6 +644,31 @@ return False
+def traced(on=""): + + def func_decorator(func, log): + def wrapper(self, *a, **kw): + log.debug("executing %s with a= %s,kw= %s", func.func_name, a, kw) + return func(self, *a, **kw) + return wrapper + + def decorator(cls): + log = logging.getLogger(on) + log.debug("aasd") + for name in dir(cls): + value = getattr(cls, name) + log.debug(name) + log.debug(type(value)) + + if inspect.ismethod(value): + setattr(cls, name, func_decorator(value, log)) + log.debug("name = %s , value = %s was wrapped", name, value) + + return cls + + return decorator + + def _getAllMacs():
# (
oVirt Jenkins CI Server has posted comments on this change.
Change subject: utils ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/6679/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/6592/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/5786/ : SUCCESS
Nir Soffer has posted comments on this change.
Change subject: utils ......................................................................
Patch Set 1:
(9 comments)
.................................................... Commit Message Line 3: AuthorDate: 2014-01-10 14:18:10 +0200 Line 4: Commit: Liron Aravot laravot@redhat.com Line 5: CommitDate: 2014-01-10 14:22:06 +0200 Line 6: Line 7: utils Explain what this does and show a usage example. Line 8: Line 9: Change-Id: Icbd049360a02ae98fa21756dc734c1da8ac3d11a
.................................................... File lib/vdsm/utils.py Line 643: except: Line 644: return False Line 645: Line 646: Line 647: def traced(on=""): Add a docstring that explain what this does and show a usage example. Line 648: Line 649: def func_decorator(func, log): Line 650: def wrapper(self, *a, **kw): Line 651: log.debug("executing %s with a= %s,kw= %s", func.func_name, a, kw)
Line 645: Line 646: Line 647: def traced(on=""): Line 648: Line 649: def func_decorator(func, log): You mark wrapper as function that wraps func:
@functools.wraps(func) Line 650: def wrapper(self, *a, **kw): Line 651: log.debug("executing %s with a= %s,kw= %s", func.func_name, a, kw) Line 652: return func(self, *a, **kw) Line 653: return wrapper
Line 647: def traced(on=""): Line 648: Line 649: def func_decorator(func, log): Line 650: def wrapper(self, *a, **kw): Line 651: log.debug("executing %s with a= %s,kw= %s", func.func_name, a, kw) I think *a=%s, **kw=%s would be more clear. Line 652: return func(self, *a, **kw) Line 653: return wrapper Line 654: Line 655: def decorator(cls):
Line 651: log.debug("executing %s with a= %s,kw= %s", func.func_name, a, kw) Line 652: return func(self, *a, **kw) Line 653: return wrapper Line 654: Line 655: def decorator(cls): Should be class_decorator, to make it easier to understand. Line 656: log = logging.getLogger(on) Line 657: log.debug("aasd") Line 658: for name in dir(cls): Line 659: value = getattr(cls, name)
Line 653: return wrapper Line 654: Line 655: def decorator(cls): Line 656: log = logging.getLogger(on) Line 657: log.debug("aasd") ?! Line 658: for name in dir(cls): Line 659: value = getattr(cls, name) Line 660: log.debug(name) Line 661: log.debug(type(value))
Line 657: log.debug("aasd") Line 658: for name in dir(cls): Line 659: value = getattr(cls, name) Line 660: log.debug(name) Line 661: log.debug(type(value)) Can be on the same line: log.debug("name: %s type: %s", name, value) Line 662: Line 663: if inspect.ismethod(value): Line 664: setattr(cls, name, func_decorator(value, log)) Line 665: log.debug("name = %s , value = %s was wrapped", name, value)
Line 660: log.debug(name) Line 661: log.debug(type(value)) Line 662: Line 663: if inspect.ismethod(value): Line 664: setattr(cls, name, func_decorator(value, log)) If we define func_decorator inside class_decorator, we can remove the log parameter, which can be accessed from the class_decorator context. Line 665: log.debug("name = %s , value = %s was wrapped", name, value) Line 666: Line 667: return cls Line 668:
Line 661: log.debug(type(value)) Line 662: Line 663: if inspect.ismethod(value): Line 664: setattr(cls, name, func_decorator(value, log)) Line 665: log.debug("name = %s , value = %s was wrapped", name, value) name=%s, value=%s would be more clear. Line 666: Line 667: return cls Line 668: Line 669: return decorator
Itamar Heim has posted comments on this change.
Change subject: utils ......................................................................
Patch Set 1:
ping
Itamar Heim has abandoned this change.
Change subject: utils ......................................................................
Abandoned
no activity, restore if relevant
vdsm-patches@lists.fedorahosted.org