예제 #1
0
        if hasattr(settings, "SQ_ADDITIONAL_SIGNALS"):
            if isinstance(settings.SQ_ADDITIONAL_SIGNALS, (list, tuple)):

                logg.debug(
                    "*** Registering signals from %s SQ_ADDITIONAL_SIGNALS modules ..."
                    % (len(settings.SQ_ADDITIONAL_SIGNALS), ))

                for addendumstring in settings.SQ_ADDITIONAL_SIGNALS:

                    try:
                        addendum = import_module(addendumstring)
                    except AttributeError, err:
                        # TODO: log this in a reliably sane manner
                        logg.warning(
                            "--- SQ_ADDITIONAL_SIGNALS module '%s' import failure: %s"
                            % (addendumstring, err))
                        continue

                    logg.debug("*** Searching for signals in '%s' ..." %
                               ((addendumstring, )))

                    for name, thing in addendum.__dict__.items():
                        if isinstance(thing, AsyncSignal):
                            logg.debug("*** Registering %s: %s.%s ..." %
                                       (thing.__class__.__name__,
                                        addendumstring, name))
                            register(thing, name, addendumstring)

    finally:
        autodiscover.lock.release()
예제 #2
0
                        thing.__class__.__name__, modstring, name))
                    register(thing, name, modstring)
        
        if hasattr(settings, "SQ_ADDITIONAL_SIGNALS"):
            if isinstance(settings.SQ_ADDITIONAL_SIGNALS, (list, tuple)):
                
                logg.debug("*** Registering signals from %s SQ_ADDITIONAL_SIGNALS modules ..." % (
                    len(settings.SQ_ADDITIONAL_SIGNALS),))
                
                for addendumstring in settings.SQ_ADDITIONAL_SIGNALS:
                    
                    try:
                        addendum = import_module(addendumstring)
                    except AttributeError, err:
                        # TODO: log this in a reliably sane manner
                        logg.warning("--- SQ_ADDITIONAL_SIGNALS module '%s' import failure: %s" % (
                            addendumstring, err))
                        continue
                    
                    logg.debug("*** Searching for signals in '%s' ..." % (
                        (addendumstring,)))
                    
                    for name, thing in addendum.__dict__.items():
                        if isinstance(thing, AsyncSignal):
                            logg.debug("*** Registering %s: %s.%s ..." % (
                                thing.__class__.__name__, addendumstring, name))
                            register(thing, name, addendumstring)
    
    finally:
        autodiscover.lock.release()
        logg.debug("*** signalqueue > WORKER autodiscover done ")
예제 #3
0
def autodiscover():
    """
    Auto-discover signals.py modules in the apps in INSTALLED_APPS;
    and fail silently when not present.
    
    N.B. this autdiscover() implementation is based on dajaxice_autodiscover in the
    Dajaxice module:
    
        https://github.com/jorgebastida/django-dajaxice/blob/master/dajaxice/core/Dajaxice.py#L155
    
    ... which in turn was inspired/copied from django.contrib.admin.autodiscover().
    One key modification is our use of threading.Lock instead of the global state variables
    used by Dajaxice.
    
    """
    
    autodiscover.lock.acquire()
    
    try:
        import imp
        from django.conf import settings
        from signalqueue.dispatcher import AsyncSignal
        
        # Gather signals that any of the installed apps define in
        # their respective signals.py files:
        logg.debug("*** Looking for AsyncSignal instances in %s apps..." % len(settings.INSTALLED_APPS))
        
        for appstring in settings.INSTALLED_APPS:
            
            try:
                app = import_module(appstring)
            except AttributeError:
                continue
            
            try:
                imp.find_module('signals', app.__path__)
            except ImportError:
                continue
            
            modstring = "%s.signals" % appstring
            mod = import_module(modstring)
            
            for name, thing in mod.__dict__.items():
                if isinstance(thing, AsyncSignal):
                    logg.debug("*** Registering signal to %s: %s" % (modstring, thing))
                    thing.name = name
                    thing.regkey = modstring
                    SQ_DMV[modstring].add(thing)
        
        if hasattr(settings, "SQ_ADDITIONAL_SIGNALS"):
            if isinstance(settings.SQ_ADDITIONAL_SIGNALS, (list, tuple)):
                
                logg.debug("*** Registering additional signals from module: %s" % str(settings.SQ_ADDITIONAL_SIGNALS))
                
                for addendumstring in settings.SQ_ADDITIONAL_SIGNALS:
                    
                    try:
                        addendum = import_module(addendumstring)
                    except AttributeError, err:
                        # TODO: log this in a reliably sane manner
                        logg.warning("xxx Got AttributeError when loading an additional signal module: %s" % err)
                    
                    for name, thing in addendum.__dict__.items():
                        if isinstance(thing, AsyncSignal):
                            logg.debug("*** Adding additional signal to %s: %s" % (addendumstring, thing))
                            thing.name = name
                            thing.regkey = addendumstring
                            SQ_DMV[addendumstring].add(thing)
    
    finally:
        autodiscover.lock.release()
예제 #4
0
def autodiscover():
    """
    Auto-discover signals.py modules in the apps in INSTALLED_APPS;
    and fail silently when not present.
    
    N.B. this autdiscover() implementation is based on dajaxice_autodiscover in the
    Dajaxice module:
    
        https://github.com/jorgebastida/django-dajaxice/blob/master/dajaxice/core/Dajaxice.py#L155
    
    ... which in turn was inspired/copied from django.contrib.admin.autodiscover().
    One key modification is our use of threading.Lock instead of the global state variables
    used by Dajaxice.
    
    """
    
    autodiscover.lock.acquire()
    
    try:
        import imp
        from django.conf import settings
        from signalqueue.dispatcher import AsyncSignal
        from signalqueue.utils import logg
        
        # Gather signals that any of the installed apps define in
        # their respective signals.py files:
        logg.debug("*** Registering signals in %s installed apps ..." % (
            len(settings.INSTALLED_APPS),))
        
        from signalqueue.utils import import_module
        
        for appstring in settings.INSTALLED_APPS:
            
            try:
                app = import_module(appstring)
            except AttributeError:
                continue
            
            try:
                imp.find_module('signals', app.__path__)
            except ImportError:
                continue
            
            modstring = "%s.signals" % appstring
            mod = import_module(modstring)
            
            logg.debug("*** Searching for signals in '%s' ..." % (
                (modstring,)))
            
            for name, thing in mod.__dict__.items():
                if isinstance(thing, AsyncSignal):
                    logg.debug("*** Registering %s: %s.%s ..." % (
                        thing.__class__.__name__, modstring, name))
                    register(thing, name, modstring)
        
        if hasattr(settings, "SQ_ADDITIONAL_SIGNALS"):
            if isinstance(settings.SQ_ADDITIONAL_SIGNALS, (list, tuple)):
                
                logg.debug("*** Registering signals from %s SQ_ADDITIONAL_SIGNALS modules ..." % (
                    len(settings.SQ_ADDITIONAL_SIGNALS),))
                
                for addendumstring in settings.SQ_ADDITIONAL_SIGNALS:
                    
                    try:
                        addendum = import_module(addendumstring)
                    except AttributeError, err:
                        # TODO: log this in a reliably sane manner
                        logg.warning("--- SQ_ADDITIONAL_SIGNALS module '%s' import failure: %s" % (
                            addendumstring, err))
                        continue
                    
                    logg.debug("*** Searching for signals in '%s' ..." % (
                        (addendumstring,)))
                    
                    for name, thing in addendum.__dict__.items():
                        if isinstance(thing, AsyncSignal):
                            logg.debug("*** Registering %s: %s.%s ..." % (
                                thing.__class__.__name__, addendumstring, name))
                            register(thing, name, addendumstring)
    
    finally:
        autodiscover.lock.release()