コード例 #1
0
ファイル: manifest.py プロジェクト: Rohitth007/dfetch
    def __init__(self, manifest: ManifestDict) -> None:
        """Create the manifest."""
        self.__version: str = manifest.get("version", self.CURRENT_VERSION)

        self._remotes, default_remotes = self._determine_remotes(
            manifest["remotes"])

        if not default_remotes:
            default_remotes = list(self._remotes.values())[0:1]

        self._projects: Dict[str, ProjectEntry] = {}
        for project in manifest["projects"]:
            if isinstance(project, dict):
                last_project = self._projects[
                    project["name"]] = ProjectEntry.from_yaml(
                        project, default_remotes[0])
            elif isinstance(project, ProjectEntry):
                last_project = self._projects[
                    project.name] = ProjectEntry.copy(project,
                                                      default_remotes[0])
            else:
                raise RuntimeError(f"{project} has unknown type")

            if last_project.remote:
                last_project.set_remote(self._remotes[last_project.remote])
コード例 #2
0
    def _init_projects(
        self, projects: Sequence[Union[ProjectEntryDict, ProjectEntry,
                                       Dict[str, str]]]
    ) -> Dict[str, ProjectEntry]:
        """Iterate over projects from manifest and initialize ProjectEntries from it.

        Args:
            projects (Sequence[Union[ProjectEntryDict, ProjectEntry, Dict[str, str]]]): Iterable with projects

        Raises:
            RuntimeError: Project unknown

        Returns:
            Dict[str, ProjectEntry]: Dictionary with key: Name of project, Value: ProjectEntry
        """
        _projects: Dict[str, ProjectEntry] = {}
        for project in projects:
            if isinstance(project, dict):
                last_project = _projects[
                    project["name"]] = ProjectEntry.from_yaml(
                        project, self._default_remote)
            elif isinstance(project, ProjectEntry):
                last_project = _projects[project.name] = ProjectEntry.copy(
                    project, self._default_remote)
            else:
                raise RuntimeError(f"{project} has unknown type")

            if last_project.remote:
                last_project.set_remote(self._remotes[last_project.remote])

        return _projects
コード例 #3
0
def test_check_overlapping_destinations(name, real_path, destinations):

    with pytest.raises(RuntimeError):
        Update._check_overlapping_destination(
            ProjectEntry.from_yaml({"name": "a"}), destinations, real_path)
コード例 #4
0
def test_check_path_traversal(name, real_path):

    with pytest.raises(RuntimeError):
        Update._check_path_traversal(ProjectEntry.from_yaml({"name": "a"}),
                                     real_path, "/somewhere/somewhere")