def append_possible_lazy_revspec(cls, module_name, member_name):
        """Append a possible lazily loaded DWIM revspec.

        :param module_name: Name of the module with the revspec
        :param member_name: Name of the revspec within the module
        """
        cls._possible_revspecs.append(
            registry._LazyObjectGetter(module_name, member_name))
Beispiel #2
0
    def append_possible_lazy_revspec(cls, module_name, member_name):
        """Append a possible lazily loaded DWIM revspec.

        :param module_name: Name of the module with the revspec
        :param member_name: Name of the revspec within the module
        """
        cls._possible_revspecs.append(
            registry._LazyObjectGetter(module_name, member_name))
Beispiel #3
0
    def hook_lazy(self, callback_module, callback_member, callback_label):
        """Lazily register a callback to be called when this HookPoint fires.

        :param callback_module: Module of the callable to use when this
            HookPoint fires.
        :param callback_member: Member name of the callback.
        :param callback_label: A label to show in the UI while this callback is
            processing.
        """
        obj_getter = registry._LazyObjectGetter(callback_module,
                                                callback_member)
        self._callbacks.append((obj_getter, callback_label))
Beispiel #4
0
    def hook_lazy(self, callback_module, callback_member, callback_label):
        """Lazily register a callback to be called when this HookPoint fires.

        :param callback_module: Module of the callable to use when this
            HookPoint fires.
        :param callback_member: Member name of the callback.
        :param callback_label: A label to show in the UI while this callback is
            processing.
        """
        obj_getter = registry._LazyObjectGetter(callback_module,
            callback_member)
        self._callbacks.append((obj_getter, callback_label))
Beispiel #5
0
    def __init__(self,
                 name,
                 help,
                 registry=None,
                 converter=None,
                 value_switches=False,
                 title=None,
                 enum_switch=True,
                 lazy_registry=None,
                 short_name=None,
                 short_value_switches=None):
        """
        Constructor.

        :param name: The option name.
        :param help: Help for the option.
        :param registry: A Registry containing the values
        :param converter: Callable to invoke with the value name to produce
            the value.  If not supplied, self.registry.get is used.
        :param value_switches: If true, each possible value is assigned its
            own switch.  For example, instead of '--format knit',
            '--knit' can be used interchangeably.
        :param enum_switch: If true, a switch is provided with the option name,
            which takes a value.
        :param lazy_registry: A tuple of (module name, attribute name) for a
            registry to be lazily loaded.
        :param short_name: The short name for the enum switch, if any
        :param short_value_switches: A dict mapping values to short names
        """
        Option.__init__(self,
                        name,
                        help,
                        type=self.convert,
                        short_name=short_name)
        self._registry = registry
        if registry is None:
            if lazy_registry is None:
                raise AssertionError(
                    'One of registry or lazy_registry must be given.')
            self._lazy_registry = _mod_registry._LazyObjectGetter(
                *lazy_registry)
        if registry is not None and lazy_registry is not None:
            raise AssertionError(
                'registry and lazy_registry are mutually exclusive')
        self.name = name
        self.converter = converter
        self.value_switches = value_switches
        self.enum_switch = enum_switch
        self.short_value_switches = short_value_switches
        self.title = title
        if self.title is None:
            self.title = name
Beispiel #6
0
    def __init__(self, name, help, registry=None, converter=None,
        value_switches=False, title=None, enum_switch=True,
        lazy_registry=None, short_name=None, short_value_switches=None):
        """
        Constructor.

        :param name: The option name.
        :param help: Help for the option.
        :param registry: A Registry containing the values
        :param converter: Callable to invoke with the value name to produce
            the value.  If not supplied, self.registry.get is used.
        :param value_switches: If true, each possible value is assigned its
            own switch.  For example, instead of '--format knit',
            '--knit' can be used interchangeably.
        :param enum_switch: If true, a switch is provided with the option name,
            which takes a value.
        :param lazy_registry: A tuple of (module name, attribute name) for a
            registry to be lazily loaded.
        :param short_name: The short name for the enum switch, if any
        :param short_value_switches: A dict mapping values to short names
        """
        Option.__init__(self, name, help, type=self.convert,
                        short_name=short_name)
        self._registry = registry
        if registry is None:
            if lazy_registry is None:
                raise AssertionError(
                    'One of registry or lazy_registry must be given.')
            self._lazy_registry = _mod_registry._LazyObjectGetter(
                *lazy_registry)
        if registry is not None and lazy_registry is not None:
            raise AssertionError(
                'registry and lazy_registry are mutually exclusive')
        self.name = name
        self.converter = converter
        self.value_switches = value_switches
        self.enum_switch = enum_switch
        self.short_value_switches = short_value_switches
        self.title = title
        if self.title is None:
            self.title = name