From 58313278cf4383a49c403d6f861cf19360dfacb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Fri, 16 Feb 2024 13:00:14 +0100 Subject: [PATCH] squash: undo single erratum --- newa/__init__.py | 14 ++++++++++++++ newa/cli.py | 49 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/newa/__init__.py b/newa/__init__.py index 4a25f62..c92646c 100644 --- a/newa/__init__.py +++ b/newa/__init__.py @@ -87,6 +87,20 @@ class Event(Serializable): id: 'ErratumId' +@define +class InitialErratum(Serializable): + """ + An initial erratum as an input. + + It does not track releases, just the initial event. It will be expanded + into corresponding :py:class:`ErratumJob` instances. + """ + + event: Event = field( # type: ignore[var-annotated] + converter=lambda x: x if isinstance(x, Event) else Event(**x), + ) + + @define class Erratum(Cloneable, Serializable): """ An eratum """ diff --git a/newa/cli.py b/newa/cli.py index fb87edb..f4694a5 100644 --- a/newa/cli.py +++ b/newa/cli.py @@ -6,7 +6,7 @@ import click from attrs import define -from . import ErratumJob +from . import Erratum, ErratumJob, Event, EventType, InitialErratum logging.basicConfig( format='%(asctime)s %(message)s', @@ -28,6 +28,20 @@ def enter_command(self, command: str) -> None: f'[%(asctime)s] [{command.ljust(8, " ")}] %(message)s', ) + def load_initial_erratum(self, filepath: Path) -> InitialErratum: + erratum = InitialErratum.from_yaml_file(filepath) + + self.logger.info(f'Discovered initial erratum {erratum.event.id} in {filepath}') + + return erratum + + def load_initial_errata(self, filename_prefix: str) -> Iterator[InitialErratum]: + for child in self.state_dirpath.iterdir(): + if not child.name.startswith(filename_prefix): + continue + + yield self.load_initial_erratum(self.state_dirpath / child) + def load_erratum_job(self, filepath: Path) -> ErratumJob: job = ErratumJob.from_yaml_file(filepath) @@ -73,18 +87,35 @@ def main(click_context: click.Context, state_dir: str) -> None: @main.command(name='event') -# @click.option( -# '-e', '--erratum', 'errata_ids', -# multiple=True, -# required=True, -# ) +@click.option( + '-e', '--erratum', 'errata_ids', + multiple=True, + ) @click.pass_obj -def cmd_event(ctx: CLIContext) -> None: +def cmd_event(ctx: CLIContext, errata_ids: tuple[str, ...]) -> None: ctx.enter_command('event') - for erratum_job in ctx.load_erratum_jobs('erratum-'): + if errata_ids: + for erratum_id in errata_ids: + event = Event(type_=EventType.ERRATUM, id=erratum_id) + + # fetch erratum details, namely releases + releases = ['RHEL-8.10.0', 'RHEL-9.4.0'] + + for release in releases: + erratum_job = ErratumJob(event=event, erratum=Erratum(release=release)) + + ctx.save_erratum_job('event-', erratum_job) + + else: + for erratum in ctx.load_initial_errata('init-'): + # fetch erratum details, namely releases + releases = ['RHEL-8.10.0', 'RHEL-9.4.0'] + + for release in releases: + erratum_job = ErratumJob(event=erratum.event, erratum=Erratum(release=release)) - ctx.save_erratum_job('event-', erratum_job) + ctx.save_erratum_job('event-', erratum_job) @main.command(name='jira')