Add pycadf + fix oslo.messaging requirement

Pycadf pulls in an older version of oslo.messaging, as
does most of the other packages. Since 1.3.0 is released
and we are building it allow the dependency resolver/adjuster
to correctly adjust those packages to use the specified
version instead of the one found in the requirements files.

Change-Id: I59b607839a8b65274a08a4903cafb98ab8900870
This commit is contained in:
Joshua Harlow
2014-04-07 15:00:00 -07:00
parent 6f47cd92e8
commit 38d0beb73e
12 changed files with 151 additions and 26 deletions

81
anvil/decorators.py Normal file
View File

@@ -0,0 +1,81 @@
# Copyright (C) 2014 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 time
# Various useful decorators...
#
# Copyright 2011 Christopher Arndt, MIT License
#
# https://wiki.python.org/moin/PythonDecoratorLibrary#Cached_Properties
# pylint: disable=C0103
class cached_property(object):
'''Decorator for read-only properties evaluated only once within TTL period.
It can be used to created a cached property like this::
import random
# the class containing the property must be a new-style class
class MyClass(object):
# create property whose value is cached for ten minutes
@cached_property(ttl=600)
def randint(self):
# will only be evaluated every 10 min. at maximum.
return random.randint(0, 100)
The value is cached in the '_cache' attribute of the object instance that
has the property getter method wrapped by this decorator. The '_cache'
attribute value is a dictionary which has a key for every property of the
object which is wrapped by this decorator. Each entry in the cache is
created only when the property is accessed for the first time and is a
two-element tuple with the last computed property value and the last time
it was updated in seconds since the epoch.
The default time-to-live (TTL) is 300 seconds (5 minutes). Set the TTL to
zero for the cached value to never expire.
To expire a cached property value manually just do::
del instance._cache[<property name>]
'''
def __init__(self, ttl=300):
self.ttl = ttl
self.fget = None
def __call__(self, fget, doc=None):
self.fget = fget
self.__doc__ = doc or fget.__doc__ # pylint: disable=W0201
self.__name__ = fget.__name__ # pylint: disable=W0201
self.__module__ = fget.__module__ # pylint: disable=W0201
return self
def __get__(self, inst, owner):
now = time.time()
try:
value, last_update = inst._cache[self.__name__]
if self.ttl > 0 and now - last_update > self.ttl:
raise AttributeError
except (KeyError, AttributeError):
value = self.fget(inst)
try:
cache = inst._cache
except AttributeError:
cache = inst._cache = {}
cache[self.__name__] = (value, now)
return value