Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_octint_dump(self):
output = io.StringIO()
yaml_utils.dump(dict(number=yaml_utils.OctInt(8)), stream=output)
output.seek(0)
self.assertThat(output.read().strip(), Equals("number: 0010"))
"travis",
"encrypt-file",
"--force",
"--add",
"after_success",
"--decrypt-to",
travis.LOCAL_CONFIG_FILENAME,
mock.ANY,
travis.ENCRYPTED_CONFIG_FILENAME,
],
stderr=subprocess.PIPE,
)
# '.travis.yml' updated only with the decrypt command.
with open(".travis.yml") as fd:
travis_conf = yaml_utils.load(fd)
self.assertThat(
travis_conf["after_success"], Equals([""])
)
# Descriptive logging ...
self.assertThat(
self.fake_logger.output,
Contains(
dedent(
"""\
Refreshing credentials to push and release "foo" snaps to edge channel in series 16
Acquiring specific authorization information ...
"""
)
),
)
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)
project_config = project_loader.load_config(project)
snap_name = project_config.data["name"]
logger.info(
"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)
logger.info(
'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:
services.append("docker")
# 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"},
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)
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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__(
self,
*,
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:
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)
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
[
unsquashfs_path,
"-d",
os.path.join(temp_dir, "squashfs-root"),
snap_path,
"-e",
os.path.join("meta", "snap.yaml"),
]
)
except subprocess.CalledProcessError:
raise SnapDataExtractionError(os.path.basename(snap_path))
logger.debug(output)
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