Esempio n. 1
0
    def __init__(self, key):
        self.key = key

        self.pkg_resources = None

        self._extension_classes = {}
        self._extension_instances = {}
        self._load_errors = {}

        # State synchronization
        self._gen_sync = GenerationSynchronizer('extensionmgr:%s:gen' % key)
        self._load_lock = threading.Lock()
        self._shutdown_lock = threading.Lock()
        self._block_sync_gen = False

        self.dynamic_urls = DynamicURLResolver()

        # Extension middleware instances, ordered by dependencies.
        self.middleware = []

        # Wrap the INSTALLED_APPS and TEMPLATE_CONTEXT_PROCESSORS settings
        # to allow for ref-counted add/remove operations.
        self._installed_apps_setting = SettingListWrapper(
            'INSTALLED_APPS', 'installed app')
        self._context_processors_setting = SettingListWrapper(
            'TEMPLATE_CONTEXT_PROCESSORS', 'context processor')

        instance_id = id(self)
        _extension_managers[instance_id] = self
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        """Initialize the site configuration.

        Args:
            *args (tuple):
                Positional arguments to pass to the parent constructor.

            **kwargs (dict):
                Keyword arguments to pass to the parent constructor.
        """
        super(SiteConfiguration, self).__init__(*args, **kwargs)

        # Optimistically try to set the Site to the current site instance,
        # which either is cached now or soon will be. That way, we avoid
        # a lookup on the relation later.
        cur_site = Site.objects.get_current()

        if cur_site.pk == self.site_id:
            self.site = cur_site

        # Begin managing the synchronization of settings between all
        # SiteConfigurations.
        self._gen_sync = GenerationSynchronizer('%s:siteconfig:%s:generation' %
                                                (self.site.domain, self.pk))

        self.settings_wrapper = SiteConfigSettingsWrapper(self)
Esempio n. 3
0
    def test_is_expired_after_other_process_updates(self):
        """Testing IntegrationManager.is_expired after another process updates
        the configuration state
        """
        manager = IntegrationManager(IntegrationConfig)
        self.assertFalse(manager.is_expired())

        gen_sync = GenerationSynchronizer(manager._gen_sync.cache_key,
                                          normalize_cache_key=False)
        gen_sync.mark_updated()

        self.assertTrue(manager.is_expired())
Esempio n. 4
0
    def __init__(self, config_model):
        """Initialize the integration manager.

        Args:
            config_model (type):
                The model used to store configuration data. This must be a
                subclass of
                :py:class:`djblets.integrations.models.BaseIntegrationConfig`.
        """
        # Check that the Django environment is set up for integrations to
        # properly function.
        if 'djblets.integrations' not in settings.INSTALLED_APPS:
            raise ImproperlyConfigured(
                'IntegrationManager requires djblets.integrations to be '
                'listed in settings.INSTALLED_APPS.')

        middleware = 'djblets.integrations.middleware.IntegrationsMiddleware'

        if middleware not in settings.MIDDLEWARE_CLASSES:
            raise ImproperlyConfigured(
                'IntegrationManager requires %s to be listed in '
                'settings.MIDDLEWARE_CLASSES' % middleware)

        self.config_model = config_model

        key = ('integrationmgr:%s.%s' %
               (self.__class__.__module__, self.__class__.__name__))

        self._integration_classes = {}
        self._integration_configs = {}
        self._integration_instances = {}
        self._lock = threading.Lock()
        self._needs_recalc = False
        self._gen_sync = GenerationSynchronizer('%s:gen' % key)

        instance_id = id(self)
        _integration_managers[instance_id] = self

        # Listen for any config model saves/deletes, so we can mark whether
        # a reload of state is needed.
        dispatch_uid = '%s:%s' % (key, id(self))

        post_delete.connect(self._on_config_changes,
                            sender=config_model,
                            dispatch_uid=dispatch_uid)
        post_save.connect(self._on_config_changes,
                          sender=config_model,
                          dispatch_uid=dispatch_uid)
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        models.Model.__init__(self, *args, **kwargs)

        # Optimistically try to set the Site to the current site instance,
        # which either is cached now or soon will be. That way, we avoid
        # a lookup on the relation later.
        cur_site = Site.objects.get_current()

        if cur_site.pk == self.site_id:
            self.site = cur_site

        # Begin managing the synchronization of settings between all
        # SiteConfigurations.
        self._gen_sync = GenerationSynchronizer('%s:siteconfig:%s:generation' %
                                                (self.site.domain, self.pk))

        self.settings_wrapper = SiteConfigSettingsWrapper(self)
Esempio n. 6
0
    def setUp(self):
        super(GenerationSynchronizerTests, self).setUp()

        self.gen_sync = GenerationSynchronizer('test-synchronizer')