Updating to have a decorator module that has any decorators we decide are good
This commit is contained in:
parent
ef4a3c5497
commit
86520a0470
35
devstack/decorators.py
Normal file
35
devstack/decorators.py
Normal file
@ -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
|
@ -21,6 +21,7 @@ import re
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from devstack import decorators
|
||||||
from devstack import importer
|
from devstack import importer
|
||||||
from devstack import log as logging
|
from devstack import log as logging
|
||||||
from devstack import settings
|
from devstack import settings
|
||||||
@ -75,7 +76,7 @@ class Distro(object):
|
|||||||
'No platform configuration data for %s (%s)' %
|
'No platform configuration data for %s (%s)' %
|
||||||
(plt, distname))
|
(plt, distname))
|
||||||
|
|
||||||
@logging.log_debug
|
@decorators.log_debug
|
||||||
def __init__(self, name, distro_pattern, packager_name, commands, components):
|
def __init__(self, name, distro_pattern, packager_name, commands, components):
|
||||||
self.name = name
|
self.name = name
|
||||||
self._distro_pattern = re.compile(distro_pattern, re.IGNORECASE)
|
self._distro_pattern = re.compile(distro_pattern, re.IGNORECASE)
|
||||||
|
@ -17,9 +17,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
import pprint
|
|
||||||
|
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
from logging.handlers import WatchedFileHandler
|
from logging.handlers import WatchedFileHandler
|
||||||
@ -76,14 +74,3 @@ class AuditAdapter(logging.LoggerAdapter):
|
|||||||
|
|
||||||
def getLogger(name='devstack'):
|
def getLogger(name='devstack'):
|
||||||
return AuditAdapter(logging.getLogger(name))
|
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
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from devstack import decorators
|
||||||
from devstack import log as logging
|
from devstack import log as logging
|
||||||
from devstack import utils
|
from devstack import utils
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ LOG = logging.getLogger("devstack.packager")
|
|||||||
|
|
||||||
class Packager(object):
|
class Packager(object):
|
||||||
|
|
||||||
@logging.log_debug
|
@decorators.log_debug
|
||||||
def __init__(self, distro, keep_packages):
|
def __init__(self, distro, keep_packages):
|
||||||
self.distro = distro
|
self.distro = distro
|
||||||
self.keep_packages = keep_packages
|
self.keep_packages = keep_packages
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from devstack import decorators
|
||||||
from devstack import exceptions as excp
|
from devstack import exceptions as excp
|
||||||
from devstack import log as logging
|
from devstack import log as logging
|
||||||
from devstack import shell as sh
|
from devstack import shell as sh
|
||||||
@ -46,7 +47,7 @@ class Persona(object):
|
|||||||
cls, cls_kvs, err)
|
cls, cls_kvs, err)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
@logging.log_debug
|
@decorators.log_debug
|
||||||
def __init__(self, description,
|
def __init__(self, description,
|
||||||
supports,
|
supports,
|
||||||
components,
|
components,
|
||||||
|
Loading…
Reference in New Issue
Block a user