Peter Pentchev | b91fc93 | 2023-01-19 15:27:13 +0200 | [diff] [blame^] | 1 | # SPDX-FileCopyrightText: StorPool <support@storpool.com> |
| 2 | # SPDX-License-Identifier: BSD-2-Clause |
| 3 | """Common definitions for the gifn-apply routines.""" |
| 4 | |
| 5 | from __future__ import annotations |
| 6 | |
| 7 | import dataclasses |
| 8 | |
| 9 | from typing import TYPE_CHECKING |
| 10 | |
| 11 | if TYPE_CHECKING: |
| 12 | import logging |
| 13 | import pathlib |
| 14 | import urllib.parse as uparse |
| 15 | |
| 16 | |
| 17 | VERSION = "0.1.0" |
| 18 | |
| 19 | |
| 20 | class GApplyError(Exception): |
| 21 | """The base class for errors that occurred during the gifn-apply operation.""" |
| 22 | |
| 23 | |
| 24 | @dataclasses.dataclass(frozen=True, order=True) |
| 25 | class Repo: |
| 26 | """A repository split into the origin fragment and the name/path within.""" |
| 27 | |
| 28 | origin: str |
| 29 | repo: str |
| 30 | |
| 31 | @property |
| 32 | def path(self) -> str: |
| 33 | """Combine the origin and the repo path.""" |
| 34 | return f"{self.origin}/{self.repo}" |
| 35 | |
| 36 | |
| 37 | @dataclasses.dataclass(frozen=True) |
| 38 | class RepoURL: |
| 39 | """A parsed URL for a repo base.""" |
| 40 | |
| 41 | url: uparse.ParseResult |
| 42 | |
| 43 | |
| 44 | @dataclasses.dataclass(frozen=True) |
| 45 | class Config: |
| 46 | """Runtime configuration for the gifn-apply tool.""" |
| 47 | |
| 48 | log: logging.Logger |
| 49 | program: pathlib.Path |
| 50 | patches: pathlib.Path |
| 51 | series: pathlib.Path |
| 52 | repo_urls: dict[str, RepoURL] |