plainbox.impl.providers.v1
– Implementation of V1 provider¶
Most of the implementation is available in
plainbox.impl.secure.providers.v1
-
class
plainbox.impl.providers.v1.
Provider1
(name, namespace, version, description, secure, gettext_domain, units_dir, jobs_dir, whitelists_dir, data_dir, bin_dir, locale_dir, base_dir, *, validate=False, validation_kwargs=None, check=True, context=None)[source]¶ Bases:
plainbox.abc.IProvider1
A v1 provider implementation.
A provider is a container of jobs and whitelists. It provides additional meta-data and knows about location of essential directories to both load structured data and provide runtime information for job execution.
Providers are normally loaded with
Provider1PlugIn
, due to the number of fields involved in basic initialization.-
CHECKBOX_SHARE
¶ required value of CHECKBOX_SHARE environment variable.
Note
This variable is only required by one script. It would be nice to remove this later on.
-
base_dir
¶ path of the directory with (perhaps) all of jobs_dir, whitelists_dir, data_dir, bin_dir, locale_dir. This may be None
-
bin_dir
¶ absolute path of the bin directory
Note
The programs in that directory may not work without setting PYTHONPATH and CHECKBOX_SHARE.
-
build_bin_dir
¶ absolute path of the build/bin directory
This value may be None. It depends on location/base_dir being set.
-
build_dir
¶ absolute path of the build directory
This value may be None. It depends on location/base_dir being set.
-
build_mo_dir
¶ absolute path of the build/mo directory
This value may be None. It depends on location/base_dir being set.
-
classify
¶ Exposed
ProviderContentClassifier.classify()
-
content_collection
¶ Exposed
ProviderContentEnumerator.content_collection()
-
data_dir
¶ absolute path of the data directory
-
description
¶ description of this provider
-
executable_list
¶ List of all the executables
-
extra_PYTHONPATH
¶ additional entry for PYTHONPATH, if needed.
This entry is required for CheckBox scripts to import the correct CheckBox python libraries.
Note
The result may be None
-
fake
¶ Bridge to
.content_collection.fake_plugins
that’s shorter to type.
-
classmethod
from_definition
(definition, secure, *, validate=False, validation_kwargs=None, check=True, context=None)[source]¶ Initialize a provider from Provider1Definition object
Parameters: - definition – A Provider1Definition object to use as reference
- secure – Value of the secure flag. This cannot be expressed by a definition object.
- validate – Enable job validation. Incorrect job definitions will not be loaded and will abort the process of loading of the remainder of the jobs. This is ON by default to prevent broken job definitions from being used. This is a keyword-only argument.
- validation_kwargs – Keyword arguments to pass to the JobDefinition.validate(). Note, this is a single argument. This is a keyword-only argument.
This method simplifies initialization of a Provider1 object where the caller already has a Provider1Definition object. Depending on the value of
definition.location
all of the directories are either None or initialized to a good (typical) value relative to locationThe only value that you may want to adjust, for working with source providers, is locale_dir, by default it would be
location/locale
butmanage.py i18n
createslocation/build/mo
-
get_translated_data
(msgid)[source]¶ Get a localized piece of data
Parameters: msgid – data to translate Returns: translated data obtained from the provider if msgid is not False (empty string and None both are) and this provider has a gettext_domain defined for it, msgid itself otherwise.
-
gettext_domain
¶ the name of the gettext domain associated with this provider
This value may be empty, in such case provider data cannot be localized for the user environment.
-
has_dedicated_namespace
¶ Flag set if namespace was defined by a dedicated field.
-
id_map
¶ A mapping from unit identifier to list of units with that identifier.
Note
Typically the list will be one element long but invalid providers may break that guarantee. Code defensively if you can.
-
job_list
¶ A sorted list of loaded job definition units.
-
jobs_dir
¶ absolute path of the jobs directory
-
locale_dir
¶ absolute path of the directory with locale data
The value is applicable as argument bindtextdomain()
-
name
¶ name of this provider
-
namespace
¶ namespace component of the provider name
This property defines the namespace in which all provider jobs are defined in. Jobs within one namespace do not need to be fully qualified by prefixing their partial identifier with provider namespace (so all stays ‘as-is’). Jobs that need to interact with other provider namespaces need to use the fully qualified job identifier instead.
The identifier is defined as the part of the provider name, up to the colon. This effectively gives organizations flat namespace within one year-domain pair and allows to create private namespaces by using sub-domains.
-
path_map
¶ A mapping from filename path to a list of units stored in that file.
Note
For
.pxu
files this will enumerate all units stored there. For other things it will typically be just the FileUnit.
-
po_dir
¶ absolute path of the po/ directory
This value may be None. It depends on location/base_dir set.
-
problem_list
¶ list of problems encountered by the loading process
-
secure
¶ flag indicating that this provider was loaded from the secure portion of PROVIDERPATH and thus can be used with the plainbox-trusted-launcher-1.
-
src_dir
¶ absolute path of the src/ directory
This value may be None. It depends on location/base_dir set.
-
tr_description
()[source]¶ Get the translated version of
description()
-
unit_list
¶ List of loaded units.
This list may contain units of various types. You should not assume all of them are
JobDefinition
instances. You may use filtering to obtain units of a given type.>>> [unit for unit in provider.unit_list ... if unit.Meta.name == 'job'] [...]
-
units_dir
¶ absolute path of the units directory
-
version
¶ version of this provider
-
whitelist_list
¶ List of loaded whitelists.
Warning
WhiteList
is currently deprecated. You should never need to access them in any new code. They are entirely replaced byTestPlan
. This property is provided for completeness and it will be removed once whitelists classes are no longer used.
-
whitelists_dir
¶ absolute path of the whitelist directory
-
-
class
plainbox.impl.providers.v1.
InsecureProvider1PlugInCollection
(**kwargs)[source]¶ Bases:
plainbox.impl.secure.plugins.FsPlugInCollection
A collection of v1 provider plugins.
This FsPlugInCollection subclass carries proper, built-in defaults, that make loading providers easier.
This particular class loads providers from both the system-wide managed locations and per-user location. In addition the list of locations searched can be changed by setting the
PROVIDERPATH
, which behaves just like PATH, but is used for looking up providers.-
discovery_time
¶ Time, in fractional seconds, that was required to discover all objects.
This time is separate from the load and wrap time of all each individual plug-in. Typically this is either a fixed cost or a predictable cost related to traversing the file system.
-
fake_plugins
(plugins, problem_list=None)¶ Context manager for using fake list of plugins
Parameters: - plugins – list of PlugIn-alike objects
- problem_list – list of problems (exceptions)
The provided list of plugins overrides any previously loaded plugins and prevent loading any other, real, plugins. After the context manager exits the previous state is restored.
-
get_all_items
()¶ Get a list of all the pairs of plugin name and plugin
Returns: a list of tuples (plugin.plugin_name, plugin)
-
get_all_names
()¶ Get a list of all the plug-in names
Returns: a list of plugin names
-
get_all_plugin_objects
()¶ Get an list of plug-in objects
-
get_all_plugins
()¶ Get a list of all the plug-ins
Returns: a list of plugin objects
-
get_by_name
(name)¶ Get the specified plug-in (by name)
Parameters: name – name of the plugin to locate Returns: PlugIn
like object associated with the nameRaises KeyError: if the specified name cannot be found
-
get_total_time
() → float¶ Get the sum of load and wrap time of each plugin object
Returns: The total number of fractional seconds of wall-clock time spent by loading this collection. This value doesn’t include some small overhead of this class but is representative of the load times of pluggable code.
-
load
()¶ Load all plug-ins.
This method loads all plug-ins from the search directories (as defined by the path attribute). Missing directories are silently ignored.
-
problem_list
¶ List of problems encountered while loading plugins
-
wrap_and_add_plugin
(plugin_name, plugin_obj, plugin_load_time)¶ Internal method of PlugInCollectionBase.
Parameters: - plugin_name – plugin name, some arbitrary string
- plugin_obj – plugin object, some arbitrary object.
- plugin_load_time – number of seconds it took to load this plugin
This method prepares a wrapper (PlugIn subclass instance) for the specified plugin name/object by attempting to instantiate the wrapper class. If a PlugInError exception is raised then it is added to the problem_list and the corresponding plugin is not added to the collection of plugins.
-
-
plainbox.impl.providers.v1.
get_insecure_PROVIDERPATH_list
()[source]¶ Computes the insecure value of PROVIDERPATH.
This value is not used by plainbox-trusted-launcher-1 executable since it would involve reading files outside of the control by the local administrator. This value is used for handing non-root jobs.
Returns: A list of three strings: * /usr/local/share/plainbox-providers-1 * /usr/share/plainbox-providers-1 * $XDG_DATA_HOME/plainbox-providers-1