Skip to content

Commit

Permalink
squash: undo single erratum
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Feb 16, 2024
1 parent e9802b4 commit 5831327
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
14 changes: 14 additions & 0 deletions newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
49 changes: 40 additions & 9 deletions newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5831327

Please sign in to comment.