Skip to content

Commit

Permalink
Add new API for Flatpak to CalculateSizeWithTask
Browse files Browse the repository at this point in the history
This API is used from UI code just after new package selection is
resolved. This will allow us to react on package selection in Flatpak
immediately.

Also move CalculateFlatpaksSizeTask to initialization because this task
is not used for installation.
  • Loading branch information
jkonecny12 committed Feb 7, 2025
1 parent 8748222 commit 3d25810
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
10 changes: 5 additions & 5 deletions pyanaconda/modules/payloads/payload/flatpak/flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from pyanaconda.modules.payloads.payload.flatpak.flatpak_interface import FlatpakInterface
from pyanaconda.modules.payloads.payload.flatpak.flatpak_manager import FlatpakManager
from pyanaconda.modules.payloads.payload.flatpak.installation import (
CalculateFlatpaksSizeTask,
CleanUpDownloadLocationTask,
DownloadFlatpaksTask,
InstallFlatpaksTask,
PrepareDownloadLocationTask,
)
from pyanaconda.modules.payloads.payload.flatpak.initialization import CalculateFlatpaksSizeTask
from pyanaconda.modules.payloads.payload.payload_base import PayloadBase

log = get_module_logger(__name__)
Expand Down Expand Up @@ -87,21 +87,21 @@ def calculate_required_space(self):
:return: required size in bytes
:rtype: int
"""
self._flatpak_manager.calculate_size()
download_size = self._flatpak_manager.download_size
install_size = self._flatpak_manager.install_size
size = calculate_required_space(download_size, install_size)
log.debug("Flatpak size required to download: %s to install: %s required: %s",
download_size, install_size, size)
return size

def calculate_size_with_task(self):
"""Refresh size requirement with task."""
return CalculateFlatpaksSizeTask(flatpak_manager=self._flatpak_manager)

def install_with_tasks(self):
"""Install the payload with tasks."""

tasks = [
CalculateFlatpaksSizeTask(
flatpak_manager=self._flatpak_manager,
),
PrepareDownloadLocationTask(
flatpak_manager=self._flatpak_manager,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
# Red Hat, Inc.
#
from dasbus.server.interface import dbus_interface
from dasbus.typing import * # pylint: disable=wildcard-import

from pyanaconda.modules.common.constants.interfaces import PAYLOAD_FLATPAK
from pyanaconda.modules.common.containers import TaskContainer
from pyanaconda.modules.payloads.payload.payload_base_interface import PayloadBaseInterface


@dbus_interface(PAYLOAD_FLATPAK.interface_name)
class FlatpakInterface(PayloadBaseInterface):
"""DBus interface for Flatpak payload module."""


def CalculateSizeWithTask(self) -> ObjPath:
"""Calculate required size based on the software selection with task."""
return TaskContainer.to_object_path(
self.implementation.calculate_size_with_task()
)
37 changes: 37 additions & 0 deletions pyanaconda/modules/payloads/payload/flatpak/initialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright (C) 2025 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#

from pyanaconda.modules.common.task import Task
from pyanaconda.modules.payloads.payload.flatpak.flatpak_manager import FlatpakManager


class CalculateFlatpaksSizeTask(Task):
"""Task to determine space needed for Flatpaks"""

def __init__(self, flatpak_manager: FlatpakManager):
"""Create a new task."""
super().__init__()
self._flatpak_manager = flatpak_manager

@property
def name(self):
"""Name of the task."""
return "Calculate needed space for Flatpaks"

def run(self):
self._flatpak_manager.calculate_size()
17 changes: 0 additions & 17 deletions pyanaconda/modules/payloads/payload/flatpak/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@
FLATPAK_MIRROR_DIR_SUFFIX = 'flatpak.mirror'


class CalculateFlatpaksSizeTask(Task):
"""Task to determine space needed for Flatpaks"""

def __init__(self, flatpak_manager: FlatpakManager):
"""Create a new task."""
super().__init__()
self._flatpak_manager = flatpak_manager

@property
def name(self):
"""Name of the task."""
return "Calculate needed space for Flatpaks"

def run(self):
self._flatpak_manager.calculate_size()


class PrepareDownloadLocationTask(Task):
"""The installation task for setting up the download location."""

Expand Down
8 changes: 8 additions & 0 deletions pyanaconda/payload/dnf/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ def check_software_selection(self, selection):
result = unwrap_variant(task_proxy.GetResult())
report = ValidationReport.from_structure(result)

# Start side payload processing if report is valid
if report.is_valid():
side_payload_path = self.proxy.SidePayload
if side_payload_path:
side_payload = PAYLOADS.get_proxy(side_payload_path)
side_task_proxy = PAYLOADS.get_proxy(side_payload.CalculateSizeWithTask())
sync_run_task(side_task_proxy)

# This validation is no longer required.
self._software_validation_required = False

Expand Down

0 comments on commit 3d25810

Please sign in to comment.