Esempio n. 1
0
def _process_entry(data):
    key = data.get("project-part")
    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()

    logger.debug("Processing part {!r}".format(key))

    # Get optional wiki entry fields.
    subparts = data.get("parts", [])
    origin_type = data.get("origin-type")

    # Get required wiki entry fields.
    try:
        origin = data["origin"]
        project_part = data["project-part"]
        maintainer = data["maintainer"]
        description = data["description"]
    except KeyError as e:
        raise InvalidEntryError("Missing key in wiki entry: {}".format(e))

    # TODO: this should really be based on the origin uri not
    # the part name to avoid the situation where there are multiple
    # parts being pulled from the same repo branch.
    origin_dir = os.path.join(BASE_DIR, key)
    os.makedirs(origin_dir, exist_ok=True)

    class Options:
        source = origin
        source_type = origin_type

    options = Options()
    sources.get(origin_dir, None, options)

    origin_data = _get_origin_data(origin_dir)

    parts = origin_data.get("parts", {})

    source_part = parts.get(project_part)
    if source_part:
        source_part = _update_source(source_part, origin)
        source_part["maintainer"] = maintainer
        source_part["description"] = description
        after = source_part.get("after", [])

        if after:
            after = _update_after_parts(project_part, after)
            after_parts.update(set(after))

        parts_list[project_part] = source_part
        subparts_list, subparts_after_list = _process_subparts(
            project_part, subparts, parts, origin, maintainer, description
        )
        parts_list.update(subparts_list)
        after_parts.update(subparts_after_list)

    return parts_list, after_parts
Esempio n. 2
0
    def test_get(self):

        class Options:
            source = '.'

        sources.get('src', 'useless-arg', Options())

        self.assertTrue(os.path.isdir('src'))
Esempio n. 3
0
    def test_get_bzr_source_from_uri(self, mock_pull):
        test_sources = ["lp:snapcraft_test_source", "bzr:dummy-source"]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir="dummy", builddir="dummy", options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 4
0
    def test_get_svn_source_from_uri(self, mock_pull):
        test_sources = ["svn://sylpheed.sraoss.jp/sylpheed/trunk"]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir="dummy", builddir="dummy", options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 5
0
    def test_get(self):
        open("file", "w").close()

        class Options:
            source = "."

        sources.get("src", "useless-arg", Options())

        self.assertTrue(os.path.isdir("src"))
        self.assertTrue(os.path.isfile(os.path.join("src", "file")))
Esempio n. 6
0
    def test_get(self):
        open('file', 'w').close()

        class Options:
            source = '.'

        sources.get('src', 'useless-arg', Options())

        self.assertTrue(os.path.isdir('src'))
        self.assertTrue(os.path.isfile(os.path.join('src', 'file')))
    def pull(self):
        super().pull()

        for src in self.options.sub_sources:
            [name] = src.keys()
            [values] = src.values()

            if 'source' in values:
                dest = values['dest'] if 'dest' in values else ''
                sources.get(os.path.join(self.sourcedir, dest),
                            os.path.join(self.build_basedir, dest),
                            Dict2Object(values))
Esempio n. 8
0
    def pull(self):
        super().pull()

        for src in self.options.sub_sources:
            [name] = src.keys()
            [values] = src.values()

            if 'source' in values:
                dest = values['dest'] if 'dest' in values else ''
                sources.get(os.path.join(self.sourcedir, dest),
                    os.path.join(self.build_basedir, dest),
                    Dict2Object(values))
Esempio n. 9
0
    def test_get_svn_source_from_uri(self, mock_pull):
        test_sources = ['svn://sylpheed.sraoss.jp/sylpheed/trunk']

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir='dummy',
                            builddir='dummy',
                            options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 10
0
    def test_get_bzr_source_from_uri(self, mock_pull):
        test_sources = ['lp:snapcraft_test_source', 'bzr:dummy-source']

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir='dummy',
                            builddir='dummy',
                            options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 11
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')

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

    origin_dir = os.path.join(BASE_DIR, _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    class Options:
        source = origin
        source_type = origin_type

    options = Options()
    sources.get(origin_dir, None, options)

    try:
        origin_data = _get_origin_data(origin_dir)
    except (BadSnapcraftYAMLError, MissingSnapcraftYAMLError) as e:
        raise InvalidEntryError('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
Esempio n. 12
0
    def test_get_git_source_from_uri(self, mock_pull):
        test_sources = [
            "git://github.com:ubuntu-core/snapcraft.git",
            "[email protected]:ubuntu-core/snapcraft.git",
            "https://github.com:ubuntu-core/snapcraft.git",
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir="dummy", builddir="dummy", options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 13
0
    def test_get_git_source_from_uri(self, mock_pull):
        test_sources = [
            'git://github.com:ubuntu-core/snapcraft.git',
            '[email protected]:ubuntu-core/snapcraft.git',
            'https://github.com:ubuntu-core/snapcraft.git',
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir='dummy',
                            builddir='dummy',
                            options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 14
0
    def test_get_svn_source_from_uri(self, mock_pull, mock_check):
        mock_check.side_effect = None
        test_sources = [
            'svn://sylpheed.sraoss.jp/sylpheed/trunk'
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(
                    sourcedir='dummy',
                    builddir='dummy',
                    options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 15
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')

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

    origin_dir = os.path.join(_get_base_dir(), _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    class Options:
        source = origin
        source_type = origin_type

    options = Options()
    sources.get(origin_dir, None, options)

    try:
        origin_data = _get_origin_data(origin_dir)
    except (BadSnapcraftYAMLError, MissingSnapcraftYAMLError) as e:
        raise 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
Esempio n. 16
0
    def test_get_bzr_source_from_uri(self, mock_pull, mock_check):
        mock_check.side_effect = None
        test_sources = [
            'lp:snapcraft_test_source',
            'bzr:dummy-source'
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(
                    sourcedir='dummy',
                    builddir='dummy',
                    options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 17
0
    def test_get_git_source_from_uri(self, mock_pull, mock_check):
        mock_check.side_effect = None
        test_sources = [
            'git://github.com:ubuntu-core/snapcraft.git',
            '[email protected]:ubuntu-core/snapcraft.git',
            'https://github.com:ubuntu-core/snapcraft.git',
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(
                    sourcedir='dummy',
                    builddir='dummy',
                    options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Esempio n. 18
0
    def pull(self):
        """Pull the source code and/or internal prereqs to build the part.

        By default, the base implementation for pull will use the following
        part properties to retrieve source code:

        - source
        - source-branch
        - source-tag
        - source-type

        If source is empty or does not exist, the phase will be skipped.

        Override or inherit from this method if you need to implement or
        enhance with custom pull logic.
        """
        if getattr(self.options, 'source', None):
            sources.get(self.sourcedir, self.build_basedir, self.options)
Esempio n. 19
0
    def pull(self):
        """Pull the source code and/or internal prereqs to build the part.

        By default, the base implementation for pull will use the following
        part properties to retrieve source code:

        - source
        - source-branch
        - source-tag
        - source-type

        If source is empty or does not exist, the phase will be skipped.

        Override or inherit from this method if you need to implement or
        enhance with custom pull logic.
        """
        if getattr(self.options, "source", None):
            sources.get(self.sourcedir, self.build_basedir, self.options)
Esempio n. 20
0
def _process_index(output):
    # XXX: This can't remain in memory if the list gets very large, but it
    # should be okay for now.
    master_parts_list = {}

    all_data = yaml.load_all(output)
    for data in all_data:
        key = data.get('project-part')
        parts_list = {}
        # 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()

        logger.debug('Processing part {!r}'.format(key))
        origin = data.get('origin')
        origin_type = data.get('origin-type')
        project_part = data.get('project-part')
        subparts = data.get('parts', [])

        if origin:
            # TODO: this should really be based on the origin uri not
            # the part name to avoid the situation where there are multiple
            # parts being pulled from the same repo branch.
            origin_dir = os.path.join(BASE_DIR, key)
            try:
                os.makedirs(origin_dir)
            except FileExistsError:
                pass

            class Options():
                pass

            options = Options()
            setattr(options, 'source', origin)

            if origin_type:
                setattr(options, 'source_type', origin_type)

            sources.get(origin_dir, None, options)

            origin_data = _get_origin_data(origin_dir)

            parts = origin_data.get('parts', {})

            source_part = parts.get(project_part)
            if source_part:
                source_part = _update_source(source_part, origin)
                after = source_part.get('after', [])

                if after:
                    after = _update_after_parts(project_part, after)
                    after_parts.update(set(after))

                parts_list[project_part] = source_part
                subparts_list, subparts_after_list = _process_subparts(
                    project_part, subparts, parts, origin)
                parts_list.update(subparts_list)
                after_parts.update(subparts_after_list)

        if is_valid_parts_list(parts_list, after_parts):
            master_parts_list.update(parts_list)

    return master_parts_list
Esempio n. 21
0
def _process_entry(data):
    key = data.get('project-part')
    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()

    logger.debug('Processing part {!r}'.format(key))

    # Get optional wiki entry fields.
    subparts = data.get('parts', [])
    origin_type = data.get('origin-type')

    # Get required wiki entry fields.
    try:
        origin = data['origin']
        project_part = data['project-part']
        maintainer = data['maintainer']
        description = data['description']
    except KeyError as e:
        raise InvalidEntryError('Missing key in wiki entry: {}'.format(e))

    # TODO: this should really be based on the origin uri not
    # the part name to avoid the situation where there are multiple
    # parts being pulled from the same repo branch.
    origin_dir = os.path.join(BASE_DIR, _encode_origin(origin))
    os.makedirs(origin_dir, exist_ok=True)

    class Options:
        source = origin
        source_type = origin_type

    options = Options()
    sources.get(origin_dir, None, options)

    origin_data = _get_origin_data(origin_dir)

    parts = origin_data.get('parts', {})

    source_part = parts.get(project_part)
    if source_part:
        source_part = _update_source(source_part, origin)
        source_part['maintainer'] = maintainer
        source_part['description'] = description
        after = source_part.get('after', [])

        if after:
            after = _update_after_parts(project_part, after)
            after_parts.update(set(after))

        parts_list[project_part] = source_part
        subparts_list, subparts_after_list = _process_subparts(
            project_part,
            subparts,
            parts,
            origin,
            maintainer,
            description,
        )
        parts_list.update(subparts_list)
        after_parts.update(subparts_after_list)

    return parts_list, after_parts