Skip to content

Commit

Permalink
Resolve comments after abdger's review
Browse files Browse the repository at this point in the history
Addressed:
- components_map made global
- dependencies are specified separately for each component
- ternary expressions refactored

Not addressed:
- if no such component/version then this is logged as warning
  with empty list retured (originally an exception was requested,
  but imho that's an overkill, let's discuss though)
- no separate function for dependencies, it's still a parameter
  (also let's discuss)
  • Loading branch information
fernflower committed Dec 22, 2023
1 parent 9de7543 commit 6d1a08c
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions repos/system_upgrade/common/libraries/rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
from leapp.libraries.common.config.version import get_source_major_version
from leapp.models import InstalledRPM

LEAPP_PACKAGES_MAP = {
'framework': {'7': {'pkgs': ['leapp', 'python2-leapp'],
'deps': ['leapp-deps']},
'8': {'pkgs': ['leapp', 'python3-leapp'],
'deps': ['leapp-deps']}
},
'repository': {'7': {'pkgs': ['leapp-upgrade-el7toel8'],
'deps': ['leapp-upgrade-el7toel8-deps']},
'8': {'pkgs': ['leapp-upgrade-el8toel9'],
'deps': ['leapp-upgrade-el8toel9-deps']}
},
'cockpit': {'7': {'pkgs': ['cockpit-leapp']},
'8': {'pkgs': ['cockpit-leapp']}
},
'tools': {'7': {'pkgs': ['snactor']},
'8': {'pkgs': ['snactor']}
}
}
LEAPP_DEFAULT_COMPONENTS = ['framework', 'repository', 'tools']


def get_installed_rpms():
rpm_cmd = [
Expand Down Expand Up @@ -128,23 +148,24 @@ def get_leapp_packages(source_version=None, component=None, include_deps=False):
:param include_deps: a flag to control whether deps meta packages are to be filtered out.
"""
res = set()
# NOTE(ivasilev) mapping has the format component: {source_version: [pkg1, pkg2, ..]}
component_map = {'framework': {'7': ['leapp', 'leapp-deps', 'python2-leapp'],
'8': ['leapp', 'leapp-deps', 'python3-leapp']},
'repository': {'7': ['leapp-upgrade-el7toel8', 'leapp-upgrade-el7toel8-deps'],
'8': ['leapp-upgrade-el8toel9', 'leapp-upgrade-el8toel9-deps']},
'snactor': {'7': ['snactor'],
'8': ['snactor']}}
source_versions = [source_version] if isinstance(source_version, str) else (source_version or
[get_source_major_version()])
components = [component] if isinstance(component, str) else component or list(component_map.keys())
source_versions = [source_version] if isinstance(source_version, str) else source_version
if not source_versions:
# No source_version of interest specified -> treat as if only current source system version
# requested
source_versions = [get_source_major_version()]
components = [component] if isinstance(component, str) else component
if not component:
# No component of interest specified -> treat as if packages for all components are requested
components = LEAPP_DEFAULT_COMPONENTS
for comp in components:
for src_version in source_versions:
try:
res.update(component_map[comp][src_version])
res.update(LEAPP_PACKAGES_MAP[comp][src_version].get('pkgs', []))
if include_deps:
res.update(LEAPP_PACKAGES_MAP[comp][src_version].get('deps', []))
except KeyError:
stdlib.api.current_logger().warning(
"The requested component {comp} or source_version {ver} is unknown".format(
comp=component, ver=src_version))
continue
if not include_deps:
# filter out deps packages
return sorted([pkg for pkg in res if not pkg.endswith('-deps')])
return sorted(res)

0 comments on commit 6d1a08c

Please sign in to comment.