Exemplo n.º 1
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, ae:
                logg.debug(str(ae))
                continue
            
            try:
                imp.find_module('signals', app.__path__)
            except ImportError, ie:
                logg.debug(str(app.__name__) +" "+ str(ie))
                continue
            
            modstring = "%s.signals" % appstring
            logg.debug("*** Import signals in '%s' ..." % (
                (modstring,)))
            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)
Exemplo n.º 2
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, ae:
                logg.debug(str(ae))
                continue

            try:
                imp.find_module('signals', app.__path__)
            except ImportError, ie:
                logg.debug(str(app.__name__) + " " + str(ie))
                continue

            modstring = "%s.signals" % appstring
            logg.debug("*** Import signals in '%s' ..." % ((modstring, )))
            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)
Exemplo n.º 3
0
def import_class(path):
    path_bits = path.split('.') # Cut off the class name at the end.
    class_name = path_bits.pop()
    module_path = '.'.join(path_bits)
    module_itself = import_module(module_path)
    if not hasattr(module_itself, class_name):
        raise ImportError("The Python module '%s' has no '%s' class." % (module_path, class_name))
    return getattr(module_itself, class_name)
Exemplo n.º 4
0
def import_class(path):
    path_bits = path.split('.')  # Cut off the class name at the end.
    class_name = path_bits.pop()
    module_path = '.'.join(path_bits)
    module_itself = import_module(module_path)
    if not hasattr(module_itself, class_name):
        raise ImportError("The Python module '%s' has no '%s' class." %
                          (module_path, class_name))
    return getattr(module_itself, class_name)
Exemplo n.º 5
0
                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))
Exemplo n.º 6
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()
Exemplo n.º 7
0
         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)
 
Exemplo n.º 8
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()