You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/11/10 07:44:02 UTC
[buildstream] 01/02: types.py: Added _SourceMirror type to
represent a mirror
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/mirrors
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit f429c9a416c3e93bcec34e278dfc8437cb4ec1f4
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Wed Nov 10 16:29:19 2021 +0900
types.py: Added _SourceMirror type to represent a mirror
---
src/buildstream/types.py | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index 8c87b4f..6fa4fe8 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -28,6 +28,7 @@ Foundation types
from typing import Any, Dict, List, Union, Optional
import os
+from .node import MappingNode, SequenceNode
from ._types import MetaFastEnum
@@ -321,6 +322,48 @@ class _HostMount:
self.optional: bool = optional # Optional mounts do not incur warnings or errors
+# _SourceMirror()
+#
+# A simple object describing a source mirror
+#
+# Args:
+# name: The mirror name
+# aliases: A dictionary of URI lists, keyed by alias names
+#
+class _SourceMirror:
+ def __init__(self, name: str, aliases: Dict[str, List[str]]):
+ self.name: str = name
+ self.aliases: Dict[str, List[str]] = aliases
+
+ # new_from_node():
+ #
+ # Creates a _SourceMirror() from a YAML loaded node.
+ #
+ # Args:
+ # node: The configuration node describing the spec.
+ #
+ # Returns:
+ # The described _SourceMirror instance.
+ #
+ # Raises:
+ # LoadError: If the node is malformed.
+ #
+ @classmethod
+ def new_from_node(cls, node: MappingNode) -> "_SourceMirror":
+ node.validate_keys(["name", "aliases"])
+
+ name: str = node.get_str("name")
+ aliases: Dict[str, List[str]] = {}
+
+ alias_node: MappingNode = node.get_mapping("aliases")
+
+ for alias, uris in alias_node.items():
+ assert type(uris) is SequenceNode # pylint: disable=unidiomatic-typecheck
+ aliases[alias] = uris.as_str_list()
+
+ return cls(name, aliases)
+
+
########################################
# Type aliases #
########################################