From 86520a047041e43bfbeb50f77d2deb63693c2c3e Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 16 Mar 2012 15:00:43 -0700 Subject: [PATCH] Updating to have a decorator module that has any decorators we decide are good --- devstack/decorators.py | 35 +++++++++++++++++++++++++++++++++++ devstack/distro.py | 3 ++- devstack/log.py | 13 ------------- devstack/packager.py | 3 ++- devstack/persona.py | 3 ++- 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 devstack/decorators.py diff --git a/devstack/decorators.py b/devstack/decorators.py new file mode 100644 index 00000000..aba4a5e9 --- /dev/null +++ b/devstack/decorators.py @@ -0,0 +1,35 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import functools +import pprint + +from devstack import log as logging + +# Very useful example ones... +# See: http://wiki.python.org/moin/PythonDecoratorLibrary + +LOG = logging.getLogger("devstack.decorators") + + +def log_debug(f): + @functools.wraps(f) + def wrapper(*args, **kargs): + LOG.debug('%s(%s, %s) ->', f.func_name, str(args), str(kargs)) + rv = f(*args, **kargs) + LOG.debug("<- %s" % (pprint.pformat(rv, indent=2))) + return rv + return wrapper diff --git a/devstack/distro.py b/devstack/distro.py index df282b4a..4761f766 100644 --- a/devstack/distro.py +++ b/devstack/distro.py @@ -21,6 +21,7 @@ import re import yaml +from devstack import decorators from devstack import importer from devstack import log as logging from devstack import settings @@ -75,7 +76,7 @@ class Distro(object): 'No platform configuration data for %s (%s)' % (plt, distname)) - @logging.log_debug + @decorators.log_debug def __init__(self, name, distro_pattern, packager_name, commands, components): self.name = name self._distro_pattern = re.compile(distro_pattern, re.IGNORECASE) diff --git a/devstack/log.py b/devstack/log.py index 807ea542..b8082403 100644 --- a/devstack/log.py +++ b/devstack/log.py @@ -17,9 +17,7 @@ # License for the specific language governing permissions and limitations # under the License. -import functools import logging -import pprint from logging.handlers import SysLogHandler from logging.handlers import WatchedFileHandler @@ -76,14 +74,3 @@ class AuditAdapter(logging.LoggerAdapter): def getLogger(name='devstack'): return AuditAdapter(logging.getLogger(name)) - - -def log_debug(f): - @functools.wraps(f) - def wrapper(*args, **kargs): - logger = getLogger() - logger.debug('%s(%s, %s) ->', f.func_name, str(args), str(kargs)) - rv = f(*args, **kargs) - logger.debug("<- %s" % (pprint.pformat(rv, indent=2))) - return rv - return wrapper diff --git a/devstack/packager.py b/devstack/packager.py index c2822216..d2052bce 100644 --- a/devstack/packager.py +++ b/devstack/packager.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +from devstack import decorators from devstack import log as logging from devstack import utils @@ -22,7 +23,7 @@ LOG = logging.getLogger("devstack.packager") class Packager(object): - @logging.log_debug + @decorators.log_debug def __init__(self, distro, keep_packages): self.distro = distro self.keep_packages = keep_packages diff --git a/devstack/persona.py b/devstack/persona.py index c4403789..9c2041fb 100644 --- a/devstack/persona.py +++ b/devstack/persona.py @@ -16,6 +16,7 @@ import yaml +from devstack import decorators from devstack import exceptions as excp from devstack import log as logging from devstack import shell as sh @@ -46,7 +47,7 @@ class Persona(object): cls, cls_kvs, err) return instance - @logging.log_debug + @decorators.log_debug def __init__(self, description, supports, components,