Skip to content

Commit

Permalink
sqush: move things around to create true container
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Feb 15, 2024
1 parent 3817c29 commit 9d205c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
39 changes: 18 additions & 21 deletions newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,23 @@ class Event(Serializable):


@define
class Erratum(Cloneable, Serializable): # type: ignore[no-untyped-def]
class Erratum(Cloneable, Serializable):
""" An eratum """

event: Event = field( # type: ignore[var-annotated]
converter=lambda x: x if isinstance(x, Event) else Event(**x),
)

releases: list[str] = field(factory=list)

@property
def id(self) -> str:
return f'{self.event.id} @ {self.releases}'

@classmethod
def from_event(cls: type['Erratum'], event: Event) -> 'Erratum':
assert event.type_ is EventType.ERRATUM

return cls(event=event)
# builds: list[...] = ...

def fetch_details(self) -> None:
raise NotImplementedError


@define
class ErratumJob(Cloneable, Serializable): # type: ignore[no-untyped-def]
""" A single erratum job """
class Job(Cloneable, Serializable):
""" A single job """

event: Event = field( # type: ignore[var-annotated]
converter=lambda x: x if isinstance(x, Event) else Event(**x),
)
release: str

# builds: list[...] = ...

# issue: ...
# recipe: ...
Expand All @@ -129,4 +113,17 @@ class ErratumJob(Cloneable, Serializable): # type: ignore[no-untyped-def]

@property
def id(self) -> str:
return f'{self.event.id} @ {self.release}'
raise NotImplementedError


@define
class ErratumJob(Job):
""" A single *erratum* job """

erratum: Erratum = field( # type: ignore[var-annotated]
converter=lambda x: x if isinstance(x, Erratum) else Erratum(**x),
)

@property
def id(self) -> str:
return f'{self.event.id} @ {"+".join(self.erratum.releases)}'
18 changes: 12 additions & 6 deletions newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def load_erratum_jobs(self, filename_prefix: str) -> Iterator[ErratumJob]:
yield self.load_erratum_job(self.state_dirpath / child)

def save_erratum_job(self, filename_prefix: str, job: ErratumJob) -> None:
filepath = self.state_dirpath / f'{filename_prefix}{job.event.id}-{job.release}.yaml'
assert len(job.erratum.releases) == 1

filepath = self.state_dirpath / \
f'{filename_prefix}{job.event.id}-{job.erratum.releases[0]}.yaml'

job.to_yaml_file(filepath)
self.logger.info(f'Erratum job {job.id} written to {filepath}')
Expand Down Expand Up @@ -85,14 +88,17 @@ def cmd_event(ctx: CLIContext, errata_ids: tuple[str, ...]) -> None:

for erratum_id in errata_ids:
event = Event(type_=EventType.ERRATUM, id=erratum_id)
erratum = Erratum.from_event(event)
job = ErratumJob(event=event, erratum=Erratum())

# TODO: erratum.fetch_details()
# TODO: job.erratum.fetch_details()
# TODO: populate releases
erratum.releases += ['RHEL-8.10.0', 'RHEL-9.4.0']
job.erratum.releases += ['RHEL-8.10.0', 'RHEL-9.4.0']

for release in job.erratum.releases:
job_erratum = job.erratum.clone()
job_erratum.releases = [release]

for release in erratum.releases:
erratum_jobs.append(ErratumJob(event=erratum.event, release=release))
erratum_jobs.append(ErratumJob(event=event, erratum=job_erratum))

ctx.save_erratum_jobs('event-', erratum_jobs)

Expand Down

0 comments on commit 9d205c3

Please sign in to comment.