# # Copyright (C) 2023 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """Manifest discovery and parsing.
from dataclasses import dataclass from pathlib import Path from xml.etree import ElementTree
def find_manifest_xml_for_tree(root: Path) -> Path: """Returns the path to the manifest XML file for the tree."""
repo_path = root / ".repo/manifests/default.xml" if repo_path.exists(): return repo_path raise FileNotFoundError(f"Could not find manifest at {repo_path}")
@dataclass(frozen=True) class Project: """Data for a manifest <project /> field.
@staticmethod def from_xml_node(
node: ElementTree.Element, default_remote: str, default_revision: str
) -> Project: """Parses a Project from the given XML node.""" try: # Path is optional, defaults to project name per manifest spec
path = x if (x := node.attrib.get("path")) isnotNoneelse node.attrib["name"] except KeyError as ex: raise RuntimeError(
f"<project /> element missing required name attribute: {node}"
) from ex
def __init__(self, path: Path, remote: str, projects: list[Project]) -> None:
self.path = path
self.remote = remote
self.projects_by_path = {p.path: p for p in projects}
@staticmethod def for_tree(root: Path) -> Manifest: """Constructs a Manifest for the tree at `root`.""" return ManifestParser(find_manifest_xml_for_tree(root)).parse()
def project_with_path(self, path: str) -> Project: """Returns the Project with the given path, or raises KeyError.""" return self.projects_by_path[path]
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-06-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.