예제 #1
0
 def write_snapcraft_yaml(self):
     self.snapcraft_yaml_file_path = os.path.join(
         self.path, "snap", "snapcraft.yaml"
     )
     os.makedirs(os.path.join(self.path, "snap"), exist_ok=True)
     with open(self.snapcraft_yaml_file_path, "w") as snapcraft_yaml_file:
         yaml_utils.dump(self.data, stream=snapcraft_yaml_file)
예제 #2
0
 def save(self, **data: Any) -> None:
     dirpath = os.path.dirname(self._path)
     if dirpath:
         os.makedirs(dirpath, exist_ok=True)
     with open(self._path, "w") as info_file:
         data.update(dict(self))
         yaml_utils.dump(data, stream=info_file)
예제 #3
0
    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)
예제 #4
0
def _save_registry(registry_data: Dict[str, List[Any]],
                   registry_filepath: Optional[str]) -> None:
    if registry_filepath is None:
        return

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

    with open(registry_filepath, "w") as registry_file:
        yaml_utils.dump(registry_data, stream=registry_file)
예제 #5
0
def expand_extensions(**kwargs):
    """Display snapcraft.yaml with all extensions applied."""
    if kwargs.get("enable_experimental_extensions"):
        os.environ["SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS"] = "True"

    project = get_project(**kwargs)
    yaml_with_extensions = project_loader.apply_extensions(
        project.info.get_raw_snapcraft())

    # Loading the config applied all the extensions, so just dump it back out
    yaml_utils.dump(yaml_with_extensions, stream=sys.stdout)
예제 #6
0
    def _record_manifest_and_source_snapcraft_yaml(self):
        prime_snap_dir = os.path.join(self._prime_dir, "snap")
        recorded_snapcraft_yaml_path = os.path.join(prime_snap_dir,
                                                    "snapcraft.yaml")
        if os.path.isfile(recorded_snapcraft_yaml_path):
            os.unlink(recorded_snapcraft_yaml_path)
        manifest_file_path = os.path.join(prime_snap_dir, "manifest.yaml")
        if os.path.isfile(manifest_file_path):
            os.unlink(manifest_file_path)

        # FIXME hide this functionality behind a feature flag for now
        if distutils.util.strtobool(os.environ.get("SNAPCRAFT_BUILD_INFO",
                                                   "n")):
            os.makedirs(prime_snap_dir, exist_ok=True)
            shutil.copy2(self._snapcraft_yaml_path,
                         recorded_snapcraft_yaml_path)
            annotated_snapcraft = _manifest.annotate_snapcraft(
                self._project_config.project, copy.deepcopy(self._config_data))
            with open(manifest_file_path, "w") as manifest_file:
                yaml_utils.dump(annotated_snapcraft, stream=manifest_file)
예제 #7
0
    def test_yaml_conversion(self, init_spy):
        state_string = yaml_utils.dump(self.state)

        # Verify that the dumped tag was correct
        self.assertThat(state_string.splitlines()[0], Equals("!PrimeState"))

        # Now verify the conversion
        state_from_yaml = yaml_utils.load(state_string)
        self.assertThat(state_from_yaml, Equals(self.state))

        # Verify that init was not called
        init_spy.assert_not_called()
예제 #8
0
    def prepare_repository(self) -> str:
        """Prepare source tree for launchpad build. Returns repo directory."""
        # Copy project assets.
        self._copy_assets()

        # Create sources directory for source archives.
        os.makedirs(self._repo_sources_dir, exist_ok=True)

        # Process each part with sources.
        for part_name, part_config in self._snapcraft_config["parts"].items():
            part_config = self._process_part_sources(part_name, part_config)
            self._prepared_snapcraft_config["parts"][part_name] = part_config

        # Set version.
        self._set_prepared_project_version()

        # Write updated snapcraft yaml config.
        snapcraft_yaml_path = os.path.join(self._repo_snap_dir,
                                           "snapcraft.yaml")
        with open(snapcraft_yaml_path, "w") as f:
            yaml_utils.dump(self._prepared_snapcraft_config, stream=f)

        return self._repo_dir
예제 #9
0
def edit_validation_sets(account_id: str, set_name: str, sequence: int,
                         key_name: str):
    """Edit the list of validations for <set-name>.

    Refer to https://snapcraft.io/docs/validation-sets for further information
    on Validation Sets.
    """
    store_client = StoreClientCLI()

    asserted_validation_sets = store_client.get_validation_sets(
        name=set_name, sequence=str(sequence))

    try:
        # assertions should only have one item since a specific
        # sequence was requested.
        revision = asserted_validation_sets.assertions[0].revision
        snaps = yaml_utils.dump({
            "snaps": [
                s.marshal()
                for s in asserted_validation_sets.assertions[0].snaps
            ]
        })
    except IndexError:
        # If there is no assertion for a given sequence, the store API
        # will return an empty list.
        revision = "0"
        snaps = _VALIDATIONS_SETS_SNAPS_TEMPLATE

    unverified_validation_sets = _VALIDATION_SETS_TEMPLATE.format(
        account_id=account_id,
        set_name=set_name,
        sequence=sequence,
        revision=revision,
        snaps=snaps,
    )

    edited_validation_sets = _edit_validation_sets(unverified_validation_sets)
    if edited_validation_sets == yaml_utils.load(unverified_validation_sets):
        echo.warning("No changes made.")
    else:
        build_assertion = store_client.post_validation_sets_build_assertion(
            validation_sets=edited_validation_sets)
        signed_validation_sets = _sign_assertion(build_assertion.marshal(),
                                                 key_name=key_name)
        store_client.post_validation_sets(
            signed_validation_sets=signed_validation_sets)
예제 #10
0
    def write_snap_yaml(self, path: str) -> None:
        """Write snap.yaml contents to specified path."""
        snap_dict = self.to_snap_yaml_dict()

        with open(path, "w") as f:
            yaml_utils.dump(snap_dict, stream=f, sort_keys=False)
예제 #11
0
 def save(self, *, filepath: str) -> None:
     dirpath = os.path.dirname(filepath)
     if dirpath:
         os.makedirs(dirpath, exist_ok=True)
     with open(filepath, "w") as state_file:
         yaml_utils.dump(self, stream=state_file)
예제 #12
0
 def do_GET(self):
     logger.debug("Handling getting parts")
     if "If-Modified-Since" in self.headers:
         ims_date = datetime.strptime(
             self.headers["If-Modified-Since"], self._date_format
         )
     else:
         ims_date = None
     if ims_date is not None and ims_date >= self._parts_date:
         self.send_response(304)
         response = {}
     elif "CUSTOM_PARTS" in os.environ:
         self.send_response(200)
         response = OrderedDict(
             (
                 (
                     "curl-custom",
                     OrderedDict(
                         (
                             ("plugin", "autotools"),
                             ("source", "http://curl.org"),
                             ("description", "custom curl part"),
                             ("maintainer", "none"),
                         )
                     ),
                 ),
             )
         )
     else:
         self.send_response(200)
         response = OrderedDict(
             (
                 (
                     "curl",
                     OrderedDict(
                         (
                             ("plugin", "autotools"),
                             ("source", "http://curl.org"),
                             ("description", "test entry for curl"),
                             ("maintainer", "none"),
                         )
                     ),
                 ),
                 (
                     "part1",
                     OrderedDict(
                         (
                             ("plugin", "go"),
                             ("source", "http://source.tar.gz"),
                             ("description", "test entry for part1"),
                             ("maintainer", "none"),
                         )
                     ),
                 ),
                 (
                     "long-described-part",
                     OrderedDict(
                         (
                             ("plugin", "go"),
                             ("source", "http://source.tar.gz"),
                             (
                                 "description",
                                 "this is a repetitive description " * 3,
                             ),
                             ("maintainer", "none"),
                         )
                     ),
                 ),
                 (
                     "multiline-part",
                     OrderedDict(
                         (
                             ("plugin", "go"),
                             ("source", "http://source.tar.gz"),
                             (
                                 "description",
                                 "this is a multiline description\n" * 3,
                             ),
                             ("maintainer", "none"),
                         )
                     ),
                 ),
             )
         )
     self.send_header("Content-Type", "text/plain")
     if "NO_CONTENT_LENGTH" not in os.environ:
         self.send_header("Content-Length", "1000")
     self.send_header("Last-Modified", self._parts_date.strftime(self._date_format))
     self.send_header("ETag", "1111")
     self.end_headers()
     self.wfile.write(yaml_utils.dump(response).encode())
예제 #13
0
def test_dump_octint(tmp_path):
    output = io.StringIO()
    yaml_utils.dump(dict(number=yaml_utils.OctInt(8)), stream=output)
    output.seek(0)

    assert output.read().strip() == "number: 0010"