Source

fabulator / src / decorators.py

Full commit
# -*- coding: latin-1 -*-
"""



"""
import traceback


from mexceptions import ImproperlyConfigured


# how it sux !
class Decorate(object):
    def __init__(self):
        pass
        
    def __call__(self, func):
        pass


class Permissions(Decorate):
    def __init__(self, username, env):
        self.username = username
        self.env = env
        
    def __call__(self, func):
        def _wrapper(*args, **kwargs):
            try:
                self.env.user = self.env.yaml.get('project').get(self.username)
            except Exception, e:
                raise ImproperlyConfigured("did you configured the 'project' part of your settings ?")
            if not self.env.user:
                raise ImproperlyConfigured("did you configured the 'project' part of your settings ?")
            print func
            return func(*args, **kwargs)

        return _wrapper

class ConfChecker(Decorate):
    def __init__(self, conf, env):
        self.conf = conf
        self.env = env
    
    def __call__(self, func):
        def _wrapper(*args, **kwargs):
            conf = self.env.yaml
            if not self.conf in conf:
                raise ImproperlyConfigured("does %s exists in your configuration file ?" % self.conf)
            return func(*args, **kwargs)

        return _wrapper