Beispiel #1
0
def _process_entry(data):
    parts_list = OrderedDict()
    # Store all the parts listed in 'after' for each included part so that
    # we can check later that we aren't missing any parts.
    # XXX: What do we do about 'after' parts that should be looked for in
    # the wiki?  They should be in the master parts list.
    after_parts = set()

    # Get optional wiki entry fields.
    origin_type = data.get('origin-type')
    origin_branch = data.get('origin-branch')
    origin_commit = data.get('origin-commit')
    origin_tag = data.get('origin-tag')

    # Get required wiki entry fields.
    try:
        entry_parts = data['parts']
        origin = data['origin']
        maintainer = data['maintainer']
        description = data['description']
    except KeyError as e:
        raise errors.InvalidWikiEntryError(
            'Missing key in wiki entry: {}'.format(e))

    logger.info('Processing origin {origin!r}'.format(origin=origin))
    origin_dir = os.path.join(_get_base_dir(), _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    source_handler = sources.get_source_handler(origin,
                                                source_type=origin_type)
    handler = source_handler(origin, source_dir=origin_dir)
    repo.check_for_command(handler.command)
    handler.source_branch = origin_branch
    handler.source_commit = origin_commit
    handler.source_tag = origin_tag
    handler.pull()

    try:
        origin_data = _get_origin_data(origin_dir)
    except MissingSnapcraftYAMLError:
        raise errors.InvalidWikiEntryError(
            'Origin {origin!r} is missing a snapcraft.yaml file.'.format(
                origin=origin))
    except BadSnapcraftYAMLError as e:
        raise errors.InvalidWikiEntryError(
            'snapcraft.yaml error: {}'.format(e))

    origin_parts = origin_data.get('parts', {})
    origin_name = origin_data.get('name')
    origin_version = origin_data.get('version')

    entry_parts_list, entry_parts_after_list = _process_entry_parts(
        entry_parts, origin_parts, origin, maintainer, description,
        origin_name, origin_version,
    )
    parts_list.update(entry_parts_list)
    after_parts.update(entry_parts_after_list)

    return parts_list, after_parts
Beispiel #2
0
def _process_entry(data):
    parts_list = OrderedDict()
    # Store all the parts listed in 'after' for each included part so that
    # we can check later that we aren't missing any parts.
    # XXX: What do we do about 'after' parts that should be looked for in
    # the wiki?  They should be in the master parts list.
    after_parts = set()

    # Get optional wiki entry fields.
    origin_type = data.get('origin-type')
    origin_branch = data.get('origin-branch')
    origin_commit = data.get('origin-commit')
    origin_tag = data.get('origin-tag')

    # Get required wiki entry fields.
    try:
        entry_parts = data['parts']
        origin = data['origin']
        maintainer = data['maintainer']
        description = data['description']
    except KeyError as e:
        raise errors.InvalidWikiEntryError(
            'Missing key in wiki entry: {}'.format(e))

    logger.info('Processing origin {origin!r}'.format(origin=origin))
    origin_dir = os.path.join(_get_base_dir(), _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    source_handler = sources.get_source_handler(origin,
                                                source_type=origin_type)
    handler = source_handler(origin, source_dir=origin_dir)
    repo.check_for_command(handler.command)
    handler.source_branch = origin_branch
    handler.source_commit = origin_commit
    handler.source_tag = origin_tag
    handler.pull()

    try:
        origin_data = _get_origin_data(origin_dir)
    except project_loader.errors.MissingSnapcraftYamlError as e:
        raise errors.InvalidWikiEntryError(
            'Origin {origin!r} is missing a snapcraft.yaml file.'.format(
                origin=origin)) from e
    except errors.SnapcraftEnvironmentError as e:
        raise errors.InvalidWikiEntryError(
            'snapcraft.yaml error: {}'.format(e)) from e

    origin_parts = origin_data.get('parts', {})
    origin_name = origin_data.get('name')
    origin_version = origin_data.get('version')

    entry_parts_list, entry_parts_after_list = _process_entry_parts(
        entry_parts, origin_parts, origin, maintainer, description,
        origin_name, origin_version,
    )
    parts_list.update(entry_parts_list)
    after_parts.update(entry_parts_after_list)

    return parts_list, after_parts
Beispiel #3
0
    def test_get_source_with_branch_and_tag_must_raise_error(self):
        handler = sources.get_source_handler('https://source.com',
                                             source_type=self.source_type)
        with self.assertRaises(sources.IncompatibleOptionsError) as raised:
            handler('https://source.com',
                    source_dir='.',
                    source_branch=self.source_branch,
                    source_tag=self.source_tag)

        self.assertEqual(
            str(raised.exception),
            'can\'t specify both source-tag and source-branch for a {} '
            'source'.format(self.source_type))
Beispiel #4
0
    def test_get_source_with_branch_and_tag_must_raise_error(self):
        handler = sources.get_source_handler('https://source.com',
                                             source_type=self.source_type)
        raised = self.assertRaises(
            sources.errors.SnapcraftSourceIncompatibleOptionsError,
            handler,
            'https://source.com',
            source_dir='.',
            source_branch=self.source_branch,
            source_tag=self.source_tag)

        self.assertThat(raised.source_type, Equals(self.source_type))
        self.assertThat(raised.options, Equals(['source-tag',
                                                'source-branch']))
Beispiel #5
0
    def test_get_source_with_branch_must_raise_error(self):
        handler = sources.get_source_handler('https://source.com',
                                             source_type=self.source_type)
        raised = self.assertRaises(
            sources.errors.SnapcraftSourceInvalidOptionError,
            handler,
            'https://source.com',
            source_dir='.',
            source_branch=self.source_branch,
            source_tag=self.source_tag,
            source_commit=self.source_commit)

        self.assertThat(raised.source_type, Equals(self.source_type))
        self.assertThat(raised.option, Equals(self.error))
Beispiel #6
0
    def test_get_source_with_branch_must_raise_error(self):
        handler = sources.get_source_handler('https://source.com',
                                             source_type=self.source_type)
        raised = self.assertRaises(sources.errors.IncompatibleOptionsError,
                                   handler,
                                   'https://source.com',
                                   source_dir='.',
                                   source_branch=self.source_branch,
                                   source_tag=self.source_tag,
                                   source_commit=self.source_commit)

        self.assertEqual(
            str(raised), 'can\'t specify a {} for a {} source'.format(
                self.error, self.source_type))
Beispiel #7
0
    def test_get_source_with_branch_and_tag_must_raise_error(self):
        handler = sources.get_source_handler(
            "https://source.com", source_type=self.source_type
        )
        raised = self.assertRaises(
            sources.errors.SnapcraftSourceIncompatibleOptionsError,
            handler,
            "https://source.com",
            source_dir=".",
            source_branch=self.source_branch,
            source_tag=self.source_tag,
        )

        self.assertThat(raised.source_type, Equals(self.source_type))
        self.assertThat(raised.options, Equals(["source-tag", "source-branch"]))
Beispiel #8
0
    def test_get_source_with_branch_and_tag_must_raise_error(self):
        handler = sources.get_source_handler('https://source.com',
                                             source_type=self.source_type)
        raised = self.assertRaises(
            sources.errors.IncompatibleOptionsError,
            handler,
            'https://source.com',
            source_dir='.',
            source_branch=self.source_branch,
            source_tag=self.source_tag)

        self.assertEqual(
            str(raised),
            'can\'t specify both source-tag and source-branch for a {} '
            'source'.format(self.source_type))
Beispiel #9
0
    def test_get_source_with_branch_must_raise_error(self):
        handler = sources.get_source_handler(
            "https://source.com", source_type=self.source_type
        )
        raised = self.assertRaises(
            sources.errors.SnapcraftSourceInvalidOptionError,
            handler,
            "https://source.com",
            source_dir=".",
            source_branch=self.source_branch,
            source_tag=self.source_tag,
            source_commit=self.source_commit,
        )

        self.assertThat(raised.source_type, Equals(self.source_type))
        self.assertThat(raised.option, Equals(self.error))
Beispiel #10
0
    def _get_source_handler(self, properties):
        """Returns a source_handler for the source in properties."""
        # TODO: we cannot pop source as it is used by plugins. We also make
        # the default '.'
        source_handler = None
        if properties['source']:
            handler_class = sources.get_source_handler(
                properties['source'], source_type=properties['source-type'])
            source_handler = handler_class(
                properties['source'],
                self.sourcedir,
                source_branch=properties['source-branch'],
                source_tag=properties['source-tag'],
                source_depth=properties['source-depth'],
                source_commit=properties['source-commit'],
            )

        return source_handler
Beispiel #11
0
    def _get_source_handler(self, properties):
        """Returns a source_handler for the source in properties."""
        # TODO: we cannot pop source as it is used by plugins. We also make
        # the default '.'
        source_handler = None
        if properties['source']:
            handler_class = sources.get_source_handler(
                properties['source'], source_type=properties['source-type'])
            source_handler = handler_class(
                properties['source'],
                self.sourcedir,
                source_branch=properties['source-branch'],
                source_tag=properties['source-tag'],
                source_depth=properties['source-depth'],
                source_commit=properties['source-commit'],
            )

        return source_handler
Beispiel #12
0
    def _get_source_handler(self, properties):
        """Returns a source_handler for the source in properties."""
        # TODO: we cannot pop source as it is used by plugins. We also make
        # the default '.'
        source_handler = None
        if self._source:
            handler_class = sources.get_source_handler(
                self._source, source_type=properties["source-type"])
            source_handler = handler_class(
                self._source,
                self.plugin.sourcedir,
                source_checksum=properties["source-checksum"],
                source_branch=properties["source-branch"],
                source_tag=properties["source-tag"],
                source_depth=properties["source-depth"],
                source_commit=properties["source-commit"],
            )

        return source_handler
Beispiel #13
0
    def _get_source_handler(self, properties):
        """Returns a source_handler for the source in properties."""
        # TODO: we cannot pop source as it is used by plugins. We also make
        # the default '.'
        source_handler = None
        if self._source:
            handler_class = sources.get_source_handler(
                self._source, source_type=properties["source-type"]
            )
            source_handler = handler_class(
                self._source,
                self.plugin.sourcedir,
                source_checksum=properties["source-checksum"],
                source_branch=properties["source-branch"],
                source_tag=properties["source-tag"],
                source_depth=properties["source-depth"],
                source_commit=properties["source-commit"],
            )

        return source_handler
Beispiel #14
0
def _process_entry(data):
    parts_list = OrderedDict()
    # Store all the parts listed in 'after' for each included part so that
    # we can check later that we aren't missing any parts.
    # XXX: What do we do about 'after' parts that should be looked for in
    # the wiki?  They should be in the master parts list.
    after_parts = set()

    # Get optional wiki entry fields.
    origin_type = data.get("origin-type")
    origin_branch = data.get("origin-branch")
    origin_commit = data.get("origin-commit")
    origin_tag = data.get("origin-tag")

    # Get required wiki entry fields.
    try:
        entry_parts = data["parts"]
        origin = data["origin"]
        maintainer = data["maintainer"]
        description = data["description"]
    except KeyError as e:
        raise errors.InvalidWikiEntryError(
            "Missing key in wiki entry: {}".format(e))

    logger.info("Processing origin {origin!r}".format(origin=origin))
    origin_dir = os.path.join(_get_base_dir(), _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    source_handler = sources.get_source_handler(origin,
                                                source_type=origin_type)
    handler = source_handler(origin, source_dir=origin_dir)
    repo.check_for_command(handler.command)
    handler.source_branch = origin_branch
    handler.source_commit = origin_commit
    handler.source_tag = origin_tag
    handler.pull()

    try:
        origin_data = _get_origin_data(origin_dir)
    except project.errors.MissingSnapcraftYamlError as e:
        raise errors.InvalidWikiEntryError(
            "Origin {origin!r} is missing a snapcraft.yaml file.".format(
                origin=origin)) from e
    except errors.SnapcraftEnvironmentError as e:
        raise errors.InvalidWikiEntryError(
            "snapcraft.yaml error: {}".format(e)) from e

    origin_parts = origin_data.get("parts", {})
    origin_name = origin_data.get("name")
    origin_version = origin_data.get("version")

    entry_parts_list, entry_parts_after_list = _process_entry_parts(
        entry_parts,
        origin_parts,
        origin,
        maintainer,
        description,
        origin_name,
        origin_version,
    )
    parts_list.update(entry_parts_list)
    after_parts.update(entry_parts_after_list)

    return parts_list, after_parts