Exemplo n.º 1
0
    def __init__(self, check=None):
        """
        :class:`~`

        :param check: Specify an initial dependency checking method.
        """
        members = inspect.getmembers(self, inspect.ismethod)

        self.checks = {}
        """A dictionary mapping the kinds of dependency checks to the functions
        that implement the dependency test."""

        for member in members:
            if is_function(member[1]):
                if member[1].__name__.startswith('_'):
                    pass
                else:
                    self.checks[member[0]] = member

        if check is None and 'mtime' in self.checks:
            self._check = 'mtime'
            """The current default dependency check. Defaults to ``mtime`` if it
            exists, otherwise uses the first available method."""
        else:
            self._check = members[0][0]
Exemplo n.º 2
0
    def generate_job(spec, funcs):
        """
        :param dict spec: A *job* specification.

        :param dict funcs: A dictionary mapping names (i.e. ``spec.job`` to
            functions.)

        :returns: A tuple where the first item is a callable and the second item
           is either a dict or a tuple of arguments, depending on the type of
           the ``spec.args`` value.

        :raises: :exc:`~err.InvalidStage` if ``spec.args`` is neither a
           ``dict``, ``list``, or ``tuple``.
        """

        if isinstance(spec['args'], dict):
            args = spec['args']
        elif isinstance(spec['args'], list):
            args = tuple(spec['args'])
        elif isinstance(spec['args'], tuple):
            args = spec['args']
        else:
            raise InvalidJob('args are malformed.')

        if is_function(spec['job']):
            action = spec['job']
        else:
            try:
                action = funcs[spec['job']]
            except KeyError:
                msg = "{0} not in function specification with: {0} keys".format(spec['job'], funcs.keys())
                logger.critical(msg)
                raise InvalidJob(msg)

        return action, args
Exemplo n.º 3
0
    def __init__(self, check=None):
        """
        :class:`~`

        :param check: Specify an initial dependency checking method.
        """
        members = inspect.getmembers(self, inspect.ismethod)

        self.checks = {}
        """A dictionary mapping the kinds of dependency checks to the functions
        that implement the dependency test."""

        for member in members:
            if is_function(member[1]):
                if member[1].__name__.startswith('_'):
                    pass
                else:
                    self.checks[member[0]] = member

        if check is None and 'mtime' in self.checks:
            self._check = 'mtime'
            """The current default dependency check. Defaults to ``mtime`` if it
            exists, otherwise uses the first available method."""
        else:
            self._check = members[0][0]
Exemplo n.º 4
0
    def validate(stage, strict=False):
        """
        :param iterable stage: A stage object to validate.

        :param bool strict: Defaults to ``False``. When ``True``,
           :meth:`~stages.BuildSteps.validate()` raises exceptions when it
           detects an invalid object. Otherwise,
           :meth:`~stages.BuildSteps.validate()` returns ``False`` for invalid
           stage objects and ``True`` for valid stage objects

        :raises: :exc:`~err.InvalidStage` in strict-mode.

        Used internally to ensure that stage objects are well formed before
        inserting them into the build :class:~stages.BuildSteps` object.
        """

        if len(stage) < 2:
            logger.critical(
                'the stage object is malformed and has too few elements.')

            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('malformed stage')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        if not is_function(stage[0]):
            logger.critical('the  in the stage is not callable.')

            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('not a callable')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        if not isinstance(stage[1], tuple) and not isinstance(
                stage[1], dict) and not isinstance(stage[1], list):
            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('not a tuple or dict')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        return True
Exemplo n.º 5
0
    def add_task(self, name, func):
        """
        :param string name: The identifier of a callable.

        :param callable func: A callable object.

        :raises: :exc:`~err.InvaidJob` if ``func`` is not callable.

        Adds a callable object to the :attr:`~system.BuildSystemGenerator.funcs`
        attribute with the identifier ``name``.
        """
        if not is_function(func):
            logger.critical('cannot add tasks that are not callables ({0}).'.format(name))
            raise InvalidJob("{0} is not callable.".format(func))

        logger.debug('adding task named {0}'.format(name))
        self.funcs[name] = func
Exemplo n.º 6
0
    def validate(stage, strict=False):
        """
        :param iterable stage: A stage object to validate.

        :param bool strict: Defaults to ``False``. When ``True``,
           :meth:`~stages.BuildSteps.validate()` raises exceptions when it
           detects an invalid object. Otherwise,
           :meth:`~stages.BuildSteps.validate()` returns ``False`` for invalid
           stage objects and ``True`` for valid stage objects

        :raises: :exc:`~err.InvalidStage` in strict-mode.

        Used internally to ensure that stage objects are well formed before
        inserting them into the build :class:~stages.BuildSteps` object.
        """

        if len(stage) < 2:
            logger.critical('the stage object is malformed and has too few elements.')

            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('malformed stage')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        if not is_function(stage[0]):
            logger.critical('the  in the stage is not callable.')

            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('not a callable')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        if not isinstance(stage[1], tuple) and not isinstance(stage[1], dict) and not isinstance(stage[1], list):
            if strict:
                logger.warning('strict mode, error causing an exception.')
                raise InvalidStage('not a tuple or dict')
            else:
                logger.warning('in permissive mode, error  returning false.')
                return False

        return True
Exemplo n.º 7
0
    def add_task(self, name, func):
        """
        :param string name: The identifier of a callable.

        :param callable func: A callable object.

        :raises: :exc:`~err.InvaidJob` if ``func`` is not callable.

        Adds a callable object to the :attr:`~system.BuildSystemGenerator.funcs`
        attribute with the identifier ``name``.
        """
        if not is_function(func):
            logger.critical(
                'cannot add tasks that are not callables ({0}).'.format(name))
            raise InvalidJob("{0} is not callable.".format(func))

        logger.debug('adding task named {0}'.format(name))
        self.funcs[name] = func
Exemplo n.º 8
0
    def generate_job(spec, funcs):
        """
        :param dict spec: A *job* specification.

        :param dict funcs: A dictionary mapping names (i.e. ``spec.job`` to
            functions.)

        :returns: A tuple where the first item is a callable and the second item
           is either a dict or a tuple of arguments, depending on the type of
           the ``spec.args`` value.

        :raises: :exc:`~err.InvalidStage` if ``spec.args`` is neither a
           ``dict``, ``list``, or ``tuple``.
        """

        if isinstance(spec['args'], dict):
            args = spec['args']
        elif isinstance(spec['args'], list):
            args = tuple(spec['args'])
        elif isinstance(spec['args'], tuple):
            args = spec['args']
        else:
            raise InvalidJob('args are malformed.')

        if is_function(spec['job']):
            action = spec['job']
        else:
            try:
                action = funcs[spec['job']]
            except KeyError:
                msg = "{0} not in function specification with: {0} keys".format(
                    spec['job'], funcs.keys())
                logger.critical(msg)
                raise InvalidJob(msg)

        return action, args