Skip to content

Commit

Permalink
Store the message plus better names
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 2, 2012
1 parent ad1785c commit 95a38b5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ckan/lib/maintain.py
Expand Up @@ -62,29 +62,31 @@ def deprecate_context_item(item_name, message=''):
# prevent a circular import
from ckan.lib.base import c

class Fake(object):
class WrappedContextItem(object):
''' This is a fake object that calls the methods of the object
contained. '''
def __init__(self, obj):
self._obj = obj
def __getattribute__(self,name):
def __init__(self, obj, message):
self._ckan_obj = obj
self._ckan_message = message
def __getattribute__(self, name):
message = object.__getattribute__(self, '_ckan_message')
log.warning('c.%s has been deprecated. %s', item_name, message)
obj = object.__getattribute__(self, '_obj')
obj = object.__getattribute__(self, '_ckan_obj')
# hack to get the actual object when needed
if name == '_obj':
if name == '_ckan_obj':
return obj
return getattr(obj, name)


# store the value in a fake object
setattr(c, item_name, Fake(getattr(c, item_name)))
setattr(c, item_name, WrappedContextItem(getattr(c, item_name), message))

# we need to store the origional __getattr__ and replace with our own one
if not hasattr(c.__class__, '__old_getattr__'):
def fake_attr(self, name):
obj = self.__class__.__dict__['__old_getattr__'](self, name)
if isinstance(obj, Fake):
return obj._obj
if isinstance(obj, WrappedContextItem):
return obj._ckan_obj
else:
return obj
get_attr = getattr(c.__class__, '__getattr__')
Expand Down

0 comments on commit 95a38b5

Please sign in to comment.