Skip to content

Show a progress bar when installing new container images #1164

@almet

Description

@almet

Right now, the way we integrate with container engines (e.g. Podman, Docker) is via a command-line interface, which gives us little margin for some operations.

For instance, when downloading a new image with podman pull image-name the way we have to track progress is via the command line, which is hard to leverage in a different way, if for instance we were to display a progress bar to the users instead, which would be a lot more UX-friendly.

We might want to have different "backends" for the container runtime, and the podman one could be done via podman-py, which provides way to handle this, like this (with Qt added):

from podman import PodmanClient
from dangerzone.container_utils import expected_image_name

from PySide6 import QtCore, QtGui, QtSvg, QtWidgets


class Window(QtWidgets.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 500, 300)

        self.progress = QtWidgets.QProgressBar(self)
        self.progress.setGeometry(200, 80, 250, 20)

        self.btn = QtWidgets.QPushButton("Download", self)
        self.btn.move(200, 120)
        self.btn.clicked.connect(self.download)
        self.show()

    def download(self):
        uri = "unix:///run/user/1000/podman/podman.sock"
        with PodmanClient(base_url=uri) as client:
            stream = client.images.pull(
                expected_image_name(),
                stream=True, # enables streaming
                decode=True # convert each chunk into a python dict
            )

        for chunk in stream:
            if chunk.get("status") == "Downloading":
                current = chunk.get("progressDetail")["current"]
                total = chunk.get("progressDetail")["total"]
                self.progress.setValue((current / total) * 100)

Metadata

Metadata

Assignees

Labels

icuIssues related with independent container updates

Type

No type
No fields configured for issues without a type.

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions