Exemplo n.º 1
0
    def run(self, path):
        '''Executes the given file within the sandbox, and ensure the overall
        consistency of the executed script.'''
        self.exec_file(path)

        # All command line arguments should have been removed (handled) by now.
        for arg in self._helper:
            without_value = arg.split('=', 1)[0]
            if arg in self._implied_options:
                frameinfo, reason = self._implied_options[arg]
                raise ConfigureError(
                    '`%s`, emitted from `%s` line `%d`, was not handled.' %
                    (without_value, frameinfo[1], frameinfo[2]))
            raise InvalidOptionError('Unknown option: %s' % without_value)

        # All options must be referenced by some @depends function
        for option in self._options.itervalues():
            if option not in self._seen:
                raise ConfigureError(
                    'Option `%s` is not handled ; reference it with a @depends'
                    % option.option)

        if self._help:
            with LineIO(self.log_impl.info) as out:
                self._help.usage(out)
Exemplo n.º 2
0
    def run(self, path=None):
        '''Executes the given file within the sandbox, as well as everything
        pending from any other included file, and ensure the overall
        consistency of the executed script(s).'''
        if path:
            self.include_file(path)

        for option in six.itervalues(self._options):
            # All options must be referenced by some @depends function
            if option not in self._seen:
                raise ConfigureError(
                    'Option `%s` is not handled ; reference it with a @depends'
                    % option.option)

            self._value_for(option)

        # All implied options should exist.
        for implied_option in self._implied_options:
            value = self._resolve(implied_option.value)
            if value is not None:
                # There are two ways to end up here: either the implied option
                # is unknown, or it's known but there was a dependency loop
                # that prevented the implication from being applied.
                option = self._options.get(implied_option.name)
                if not option:
                    raise ConfigureError(
                        '`%s`, emitted from `%s` line %d, is unknown.' %
                        (implied_option.option, implied_option.caller[1],
                         implied_option.caller[2]))
                # If the option is known, check that the implied value doesn't
                # conflict with what value was attributed to the option.
                option_value = self._value_for_option(option)
                if value != option_value:
                    reason = implied_option.reason
                    if isinstance(reason, Option):
                        reason = self._raw_options.get(reason) or reason.option
                        reason = reason.split('=', 1)[0]
                    value = OptionValue.from_(value)
                    raise InvalidOptionError(
                        "'%s' implied by '%s' conflicts with '%s' from the %s"
                        % (value.format(option.option), reason,
                           option_value.format(
                               option.option), option_value.origin))

        # All options should have been removed (handled) by now.
        for arg in self._helper:
            without_value = arg.split('=', 1)[0]
            msg = 'Unknown option: %s' % without_value
            if self._help:
                self._logger.warning(msg)
            else:
                raise InvalidOptionError(msg)

        # Run the execution queue
        for func, args in self._execution_queue:
            func(*args)

        if self._help:
            with LineIO(self.log_impl.info) as out:
                self._help.usage(out)
Exemplo n.º 3
0
    def test_lineio_contextmanager(self):
        lines = []
        with LineIO(lambda l: lines.append(l)) as l:
            l.write('a\nb\nc')

            self.assertEqual(lines, ['a', 'b'])

        self.assertEqual(lines, ['a', 'b', 'c'])
Exemplo n.º 4
0
    def run(self, path=None):
        '''Executes the given file within the sandbox, as well as everything
        pending from any other included file, and ensure the overall
        consistency of the executed script(s).'''
        if path:
            self.include_file(path)

        for option in self._options.itervalues():
            # All options must be referenced by some @depends function
            if option not in self._seen:
                raise ConfigureError(
                    'Option `%s` is not handled ; reference it with a @depends'
                    % option.option
                )

            self._value_for(option)

        # All implied options should exist.
        for implied_option in self._implied_options:
            value = self._resolve(implied_option.value,
                                  need_help_dependency=False)
            if value is not None:
                raise ConfigureError(
                    '`%s`, emitted from `%s` line %d, is unknown.'
                    % (implied_option.option, implied_option.caller[1],
                       implied_option.caller[2]))

        # All options should have been removed (handled) by now.
        for arg in self._helper:
            without_value = arg.split('=', 1)[0]
            msg = 'Unknown option: %s' % without_value
            if self._help:
                self._logger.warning(msg)
            else:
                raise InvalidOptionError(msg)

        # Run the execution queue
        for func, args in self._execution_queue:
            func(*args)

        if self._help:
            with LineIO(self.log_impl.info) as out:
                self._help.usage(out)
Exemplo n.º 5
0
    def test_lineio(self):
        lines = []
        l = LineIO(lambda l: lines.append(l))

        l.write('a')
        self.assertEqual(lines, [])

        l.write('b')
        self.assertEqual(lines, [])

        l.write('\n')
        self.assertEqual(lines, ['ab'])

        l.write('cdef')
        self.assertEqual(lines, ['ab'])

        l.write('\n')
        self.assertEqual(lines, ['ab', 'cdef'])

        l.write('ghi\njklm')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi'])

        l.write('nop\nqrst\nuv\n')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv'])

        l.write('wx\nyz')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv',
                                 'wx'])

        l.close()
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv',
                                 'wx', 'yz'])
Exemplo n.º 6
0
    def test_lineio(self):
        lines = []
        l = LineIO(lambda l: lines.append(l))

        l.write('a')
        self.assertEqual(lines, [])

        l.write('b')
        self.assertEqual(lines, [])

        l.write('\n')
        self.assertEqual(lines, ['ab'])

        l.write('cdef')
        self.assertEqual(lines, ['ab'])

        l.write('\n')
        self.assertEqual(lines, ['ab', 'cdef'])

        l.write('ghi\njklm')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi'])

        l.write('nop\nqrst\nuv\n')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv'])

        l.write('wx\nyz')
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv',
                                 'wx'])

        l.close()
        self.assertEqual(lines, ['ab', 'cdef', 'ghi', 'jklmnop', 'qrst', 'uv',
                                 'wx', 'yz'])