Jump to >

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.

__init__(setting_name, display_name)[source]
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.

add_list(items)[source]

Adds a list of items to the setting.

remove(item)[source]

Removes an item from the setting.

The item’s ref count will be decremented. If it hits 0, it will be removed from the list.

remove_list(items)[source]

Removes a list of items from the setting.

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.

VERSION_SETTINGS_KEY = u’_extension_installed_version’[source]
__init__(key)[source]
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.

clear_sync_cache()[source]
get_absolute_url()[source]
get_can_disable_extension(registered_extension)[source]
get_can_enable_extension(registered_extension)[source]
get_enabled_extension(extension_id)[source]

Returns an enabled extension with the given ID.

get_enabled_extensions()[source]

Returns the list of all enabled extensions.

get_installed_extensions()[source]

Returns the list of all installed extensions.

get_installed_extension(extension_id)[source]

Returns the installed extension with the given ID.

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.

shutdown()[source]

Shut down the extension manager and all of its extensions.

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.

get_extension_managers()[source]

Return all extension manager instances.

This will return all the extension managers that have been constructed. The order is not guaranteed.

Returns:The list of ExtensionManager instances.
Return type:list
shutdown_extension_managers()[source]

Shut down all extension managers.

This is called automatically when the process exits, but can be run manually.