How to use the snapcraft.yaml_utils function in snapcraft

To help you get started, we’ve selected a few snapcraft examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snapcore / snapcraft / tests / unit / View on Github external
def test_octint_dump(self):
        output = io.StringIO()
        yaml_utils.dump(dict(number=yaml_utils.OctInt(8)), stream=output)

        self.assertThat(, Equals("number: 0010"))
github snapcore / snapcraft / tests / unit / integrations / View on Github external

        # '.travis.yml' updated only with the decrypt command.
        with open(".travis.yml") as fd:
            travis_conf = yaml_utils.load(fd)
                travis_conf["after_success"], Equals([""])

        # Descriptive logging ...
                Refreshing credentials to push and release "foo" snaps to edge channel in series 16
                Acquiring specific authorization information ...
github snapcore / snapcraft / tests / unit / View on Github external
def test_load_yaml_file_bad_yaml(self):
        path = os.path.join(self.path, "test.yaml")
        with open(path, "w") as f:
            # Note the missing newlines...
            f.write("foo: bar")
            f.write("a-b-c: xyz")

        self.assertRaises(YamlValidationError, yaml_utils.load_yaml_file, path)
github snapcore / snapcraft / snapcraft / integrations / View on Github external
project_config = project_loader.load_config(project)
    snap_name =["name"]
        "Enabling Travis testbeds to push and release {!r} snaps "
        "to edge channel in series {!r}".format(snap_name, series)

    packages = [{"name": snap_name, "series": series}]
    channels = ["edge"]
    _acquire_and_encrypt_credentials(packages, channels)
        'Configuring "deploy" phase to build and release the snap in the ' "Store."
    with open(TRAVIS_CONFIG_FILENAME, "r+") as fd:
        travis_conf = yaml_utils.load(fd)
        # Enable 'sudo' capability and 'docker' service.
        travis_conf["sudo"] = "required"
        services = travis_conf.setdefault("services", [])
        if "docker" not in services:
        # Add a 'deploy' section with 'script' provider for building and
        # release the snap within a xenial docker container.
        travis_conf["deploy"] = {
            "skip_cleanup": True,
            "provider": "script",
            "script": (
                "docker run -v $(pwd):$(pwd) -t snapcore/snapcraft sh -c "
                '"apt update -qq && cd $(pwd) && '
                'snapcraft && snapcraft push *.snap --release edge"'
            "on": {"branch": "master"},
github snapcore / snapcraft / snapcraft / internal / build_providers / View on Github external
def _load_registry(registry_filepath: Optional[str]) -> Dict[str, List[Any]]:
    if registry_filepath is None or not os.path.exists(registry_filepath):
        return dict()

    with open(registry_filepath) as registry_file:
        return yaml_utils.load(registry_file)
github snapcore / snapcraft / snapcraft / extractors / View on Github external
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

from typing import Any, Dict, List, Optional, Set, Union

from snapcraft import yaml_utils

class ExtractedMetadata(yaml_utils.SnapcraftYAMLObject):
    """Collection of metadata extracted from a part."""

    yaml_tag = "!ExtractedMetadata"

    def __init__(
        common_id: Optional[str] = None,
        title: Optional[str] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        version: Optional[str] = None,
        grade: Optional[str] = None,
        icon: Optional[str] = None,
        desktop_file_paths: Optional[List[str]] = None
    ) -> None:
github snapcore / snapcraft / snapcraft / internal / build_providers / View on Github external
def _save_info(self, **data: Dict[str, Any]) -> None:
        filepath = os.path.join(self.provider_project_dir, "project-info.yaml")

        dirpath = os.path.dirname(filepath)
        if dirpath:
            os.makedirs(dirpath, exist_ok=True)

        with open(filepath, "w") as info_file:
            yaml_utils.dump(data, stream=info_file)
github snapcore / snapcraft / snapcraft / internal / states / View on Github external
def get_state(state_dir: str, step: steps.Step):
    state = None
    state_file = get_step_state_file(state_dir, step)
    if os.path.isfile(state_file):
        with open(state_file, "r") as f:
            state = yaml_utils.load(f)

    return state
github snapcore / snapcraft / snapcraft / View on Github external
                    os.path.join(temp_dir, "squashfs-root"),
                    os.path.join("meta", "snap.yaml"),
        except subprocess.CalledProcessError:
            raise SnapDataExtractionError(os.path.basename(snap_path))
        with open(
            os.path.join(temp_dir, "squashfs-root", "meta", "snap.yaml")
        ) as yaml_file:
            snap_yaml = yaml_utils.load(yaml_file)
    return snap_yaml