Skip to content
Snippets Groups Projects
ids.py 2.59 KiB
Newer Older
import six

Stefano Borini's avatar
Stefano Borini committed
    """The envisage extension points ids for the factories ExtensionPoints.
    These are populated by the envisage plugins.

    The plugin developer generally does not have to handle these identifiers,
    as they just have to reimplement the plugin base class and implement
    the appropriate default methods.
    """
    MCO_FACTORIES = 'force.bdss.mco.factories'
    DATA_SOURCE_FACTORIES = 'force.bdss.data_source.factories'
    KPI_CALCULATOR_FACTORIES = 'force.bdss.kpi_calculator.factories'
Stefano Borini's avatar
Stefano Borini committed
    NOTIFICATION_LISTENER_FACTORIES = \
        'force.bdss.notification_listener.factories'
Stefano Borini's avatar
Stefano Borini committed
    UI_HOOKS_FACTORIES = 'force.bdss.ui_hooks.factories'
def factory_id(producer, identifier):
    """Creates an id for the factory.

    Parameters
    ----------
    producer: str
        the company or research institute unique identifier (e.g. "enthought")
    identifier: str
        A unique identifier for the factory. The producer has authority and
        control over the uniqueness of this identifier.

    Returns
    -------
Stefano Borini's avatar
Stefano Borini committed
    str: an identifier to be used in the factory.
    return _string_id(producer, "factory", identifier)
Stefano Borini's avatar
Stefano Borini committed
def mco_parameter_id(producer, mco_identifier, parameter_identifier):
Stefano Borini's avatar
Stefano Borini committed
    """Creates an ID for an MCO parameter, so that it can be identified
    uniquely."""
Stefano Borini's avatar
Stefano Borini committed
    return _string_id(producer,
Stefano Borini's avatar
Stefano Borini committed
                      mco_identifier,
                      "parameter",
                      parameter_identifier)
def plugin_id(producer, identifier):
Stefano Borini's avatar
Stefano Borini committed
    """Creates an ID for the plugins. These must be defined, otherwise
Stefano Borini's avatar
Stefano Borini committed
    the envisage system will complain (but not break)
    """
Stefano Borini's avatar
Stefano Borini committed
    return _string_id(producer, "plugin", identifier)
Stefano Borini's avatar
Stefano Borini committed
def _string_id(*args):
    """Creates an id for a generic entity.

    Parameters
    ----------
    entity_namespace: str
Stefano Borini's avatar
Stefano Borini committed
        A namespace for the entity we want to address (e.g. "factory")
    producer: str
        the company or research institute unique identifier (e.g. "enthought")
    identifier: str
Stefano Borini's avatar
Stefano Borini committed
        A unique identifier for the factory. The producer has authority and
        control over the uniqueness of this identifier.

    Returns
    -------
Stefano Borini's avatar
Stefano Borini committed
    str: an identifier to be used in the factory.
    """
    def is_valid(entry):
        return (
            isinstance(entry, six.string_types) and
            " " not in entry and
            len(entry) != 0)

Stefano Borini's avatar
Stefano Borini committed
    if not all(map(is_valid, args)):
        raise ValueError("One or more of the specified parameters was "
                         "invalid: {}".format(str(args)))
Stefano Borini's avatar
Stefano Borini committed
    return ".".join(["force", "bdss"]+list(args))