File: download_callbacks.py

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (32 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class PackageDownloadCallbacks(libdnf5.repo.DownloadCallbacks):
    # List of descriptions of downloads.
    download_descriptions = []

    def add_new_download(self, user_data, description, total_to_download):
        print(f"Started downloading: {description}, size: {total_to_download}")

        # Store the message describing the new download and return its index in the list.
        self.download_descriptions.append(description)
        return len(self.download_descriptions) - 1

    def end(self, user_cb_data, status, msg):
        # Get the description based on the index passed in user_cb_data.
        description = self.download_descriptions[user_cb_data]

        if status is libdnf5.repo.DownloadCallbacks.TransferStatus_SUCCESSFUL:
            print(f"Downloaded: {description}")
        elif status is libdnf5.repo.DownloadCallbacks.TransferStatus_ALREADYEXISTS:
            print(f"Skipped to download: {description}: {msg}")
        else:
            print(f"Failed to download: {description}: {msg}")

        return 0


# Set the download callbacks.
downloader_callbacks = PackageDownloadCallbacks()
base.set_download_callbacks(
    libdnf5.repo.DownloadCallbacksUniquePtr(downloader_callbacks))

# Download the packages.
transaction.download()