def disable_extension(self, extension_id): """Disables an extension. Disabling an extension will remove any data files the extension installed and then shut down the extension and all of its hooks. It will not delete any data from the database. """ if extension_id not in self._extension_instances: # It's not enabled. return if extension_id not in self._extension_classes: raise InvalidExtensionError(extension_id) extension = self._extension_instances[extension_id] for dependent_id in self.get_dependent_extensions(extension_id): self.disable_extension(dependent_id) self._uninstall_extension(extension) self._uninit_extension(extension) extension.registration.enabled = False extension.registration.save() self._clear_template_cache() self._bump_sync_gen()
def disable_extension(self, extension_id): """Disables an extension. Disabling an extension will remove any data files the extension installed and then shut down the extension and all of its hooks. It will not delete any data from the database. """ has_load_error = extension_id in self._load_errors if not has_load_error: if extension_id not in self._extension_instances: # It's not enabled. return if extension_id not in self._extension_classes: raise InvalidExtensionError(extension_id) extension = self._extension_instances[extension_id] for dependent_id in self.get_dependent_extensions(extension_id): self.disable_extension(dependent_id) self._uninstall_extension(extension) self._uninit_extension(extension) self._unregister_static_bundles(extension) registration = extension.registration else: del self._load_errors[extension_id] if extension_id in self._extension_classes: # The class was loadable, so it just couldn't be instantiated. # Update the registration on the class. ext_class = self._extension_classes[extension_id] registration = ext_class.registration else: registration = RegisteredExtension.objects.get( class_name=extension_id) registration.enabled = False registration.save(update_fields=['enabled']) self._clear_template_cache() self._bump_sync_gen() self._recalculate_middleware()
def get_dependent_extensions(self, dependency_extension_id): """Returns a list of all extensions required by an extension.""" if dependency_extension_id not in self._extension_instances: raise InvalidExtensionError(dependency_extension_id) dependency = self.get_installed_extension(dependency_extension_id) result = [] for extension_id, extension in six.iteritems(self._extension_classes): if extension_id == dependency_extension_id: continue for ext_requirement in extension.info.requirements: if ext_requirement == dependency: result.append(extension_id) return result
def enable_extension(self, extension_id): """Enables an extension. Enabling an extension will install any data files the extension may need, any tables in the database, perform any necessary database migrations, and then will start up the extension. """ if extension_id in self._extension_instances: # It's already enabled. return if extension_id not in self._extension_classes: if extension_id in self._load_errors: raise EnablingExtensionError( _('There was an error loading this extension'), self._load_errors[extension_id], needs_reload=True) raise InvalidExtensionError(extension_id) ext_class = self._extension_classes[extension_id] # Enable extension dependencies for requirement_id in ext_class.requirements: self.enable_extension(requirement_id) try: self._install_extension(ext_class) except InstallExtensionError as e: raise EnablingExtensionError(e.message, e.load_error) extension = self._init_extension(ext_class) ext_class.registration.enabled = True ext_class.registration.save() self._clear_template_cache() self._bump_sync_gen() self._recalculate_middleware() return extension
def enable_extension(self, extension_id): """Enables an extension. Enabling an extension will install any data files the extension may need, any tables in the database, perform any necessary database migrations, and then will start up the extension. """ if extension_id in self._extension_instances: # It's already enabled. return if extension_id not in self._extension_classes: raise InvalidExtensionError(extension_id) ext_class = self._extension_classes[extension_id] # Enable extension dependencies for requirement_id in ext_class.requirements: self.enable_extension(requirement_id) try: self._install_extension(ext_class) except InstallExtensionError, e: raise EnablingExtensionError(e.message)
def get_installed_extension(self, extension_id): """Returns the installed extension with the given ID.""" if extension_id not in self._extension_classes: raise InvalidExtensionError(extension_id) return self._extension_classes[extension_id]