djblets.extensions.manager¶
-
class
SettingListWrapper
(setting_name, display_name)[source]¶ Bases:
object
Wraps list-based settings to provide management and ref counting.
This can be used instead of direct access to a list in Django settings to ensure items are never added more than once, and only removed when nothing needs it anymore.
Each item in the list is ref-counted. The initial items from the setting are populated and start with a ref count of 1. Adding items will increment a ref count for the item, adding it to the list if it doesn’t already exist. Removing items reduces the ref count, removing when it hits 0.
-
add
(item)[source]¶ Adds an item to the setting.
If the item is already in the list, it won’t be added again. The ref count will just be incremented.
If it’s a new item, it will be added to the list with a ref count of 1.
-
-
class
ExtensionManager
(key)[source]¶ Bases:
object
A manager for all extensions.
ExtensionManager manages the extensions available to a project. It can scan for new extensions, enable or disable them, determine dependencies, install into the database, and uninstall.
An installed extension is one that has been installed by a Python package on the system.
A registered extension is one that has been installed and information then placed in the database. This happens automatically after scanning for an installed extension. The registration data stores whether or not it’s enabled, and stores various pieces of information on the extension.
An enabled extension is one that is actively enabled and hooked into the project.
Each project should have one ExtensionManager.
-
get_url_patterns
()[source]¶ Returns the URL patterns for the Extension Manager.
This should be included in the root urlpatterns for the site.
-
is_expired
()[source]¶ Returns whether or not the extension state is possibly expired.
Extension state covers the lists of extensions and each extension’s configuration. It can expire if the state synchronization value falls out of cache or is changed.
Each ExtensionManager has its own state synchronization cache key.
-
get_dependent_extensions
(dependency_extension_id)[source]¶ Returns a list of all extensions required by an extension.
-
enable_extension
(extension_id)[source]¶ 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.
-
disable_extension
(extension_id)[source]¶ 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.
-
install_extension
(install_url, package_name)[source]¶ Install an extension from a remote source.
Installs an extension from a remote URL containing the extension egg. Installation may fail if a malformed install_url or package_name is passed, which will cause an InstallExtensionError exception to be raised. It is also assumed that the extension is not already installed.
-
load
(full_reload=False)[source]¶ Loads all known extensions, initializing any that are recorded as being enabled.
If this is called a second time, it will refresh the list of extensions, adding new ones and removing deleted ones.
If full_reload is passed, all state is cleared and we reload all extensions and state from scratch.
-
install_extension_media
(ext_class, force=False)[source]¶ Installs extension static media.
This method is a wrapper around _install_extension_media_internal to check whether we actually need to install extension media, and avoid contention among multiple threads/processes when doing so.
We need to install extension media if it hasn’t been installed yet, or if the version of the extension media that we installed is different from the current version of the extension.
-