Skip to content

Commit

Permalink
Add 'print-revisions' command
Browse files Browse the repository at this point in the history
The 'print-revisions' command prints out a set or revision numbers for
projects from charmed-openstack-info. The can be filtered according to
bases, channels and architectures. This is handy to find a set of
revisions that supports a particular base/arch in a channel.
  • Loading branch information
ajkavanagh committed Nov 23, 2023
1 parent dc1d566 commit d00fa14
Show file tree
Hide file tree
Showing 3 changed files with 409 additions and 3 deletions.
46 changes: 43 additions & 3 deletions charmhub_lp_tools/charm_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,31 @@ def get_all_revisions(self) -> Set[int]:
all_revisions.add(revision_num)
return all_revisions

def get_revisions_for_bases_by_arch(
@property
def bases(self) -> List[str]:
"""Retrieve the bases registered against a channel.
:returns: a sorted unique list of bases.
"""
bases: Set[str] = set()
for channel_def in self.channel_map:
chan_track = channel_def['channel']['track']
chan_risk = channel_def['channel']['risk']
chan_base = channel_def['channel']['base']
logger.debug(
"base found: track: %s, risk: %s, arch: %s, release: %s",
chan_track, chan_risk,
chan_base['architecture'], chan_base['channel'])
if (chan_track, chan_risk) == (self.track, self.risk):
bases.add(chan_base['channel'])
return sorted(bases)

def get_all_revisions_for_bases_by_arch(
self,
bases: List[str],
arch: Optional[str] = None,
ignore_arches: Optional[List[str]] = None,
) -> Dict[str, int]:
) -> Dict[str, Set[int]]:
"""Decode the channel and return a set of {arch: revision}.
:param base: base channel.
Expand Down Expand Up @@ -444,10 +463,31 @@ def get_revisions_for_bases_by_arch(
delete = True
if delete:
del revisions_[all_arch]
return revisions_
# now just keep the highest revision for each arch.
highest_revisions: Dict[str, int] = {}
for k, v in revisions_.items():
highest_revisions[k] = list(sorted(revisions_[k]))[-1]
highest_revisions[k] = list(sorted(v))[-1]
return highest_revisions

def get_revisions_for_bases_by_arch(
self,
bases: List[str],
arch: Optional[str] = None,
ignore_arches: Optional[List[str]] = None,
) -> Dict[str, int]:
"""Decode the channel and return a set of {arch: revision}.
:param base: base channel.
:param arch: Filter by architecture
:param ignore_arches: Filter by ignoring the following list of arches.
:returns: The highest revision for each arch.
"""
# just keep the highest revision for each arch.
highest_revisions: Dict[str, int] = {}
for k, v in self.get_all_revisions_for_bases_by_arch(
bases, arch, ignore_arches).items():
highest_revisions[k] = list(sorted(v))[-1]
return highest_revisions

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions charmhub_lp_tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

from . import ensure_series
from . import osci_sync
from . import revisions
from .group_config import GroupConfig
from .launchpadtools import (
LaunchpadTools,
Expand Down Expand Up @@ -707,6 +708,7 @@ def parse_args(argv: Optional[List[str]],

osci_sync.setup_parser(subparser)
ensure_series.setup_parser(subparser)
revisions.setup_parser(subparser)

# finally, parse the args and return them.
args = parser.parse_args(argv)
Expand Down
Loading

0 comments on commit d00fa14

Please sign in to comment.