Blame SOURCES/0025-report-client-Find-debuginfos-in-own-method.patch

fa18db
From f4a632838a453f168037257d0c48e9b0976d6321 Mon Sep 17 00:00:00 2001
fa18db
From: Matej Marusak <mmarusak@redhat.com>
fa18db
Date: Fri, 30 Nov 2018 11:40:09 +0100
fa18db
Subject: [PATCH] report-client: Find debuginfos in own method
fa18db
fa18db
This commit picks a piece of code responsible for looking up debuginfo
fa18db
packages into own method. For making sure that it works in any code that
fa18db
used it the old way, it checks if the method for finding packages was
fa18db
already called and if not, calls it directly.
fa18db
fa18db
Purpose of this change is to be able to get size of packages those are
fa18db
going to be installed before installing them. In that case anyone using
fa18db
these downloader classes is going to be able for example prepare enough
fa18db
space for the newly installed packages.
fa18db
fa18db
Related to #811978.
fa18db
fa18db
Signed-off-by: Matej Marusak <mmarusak@redhat.com>
fa18db
---
fa18db
 src/client-python/reportclient/debuginfo.py | 69 +++++++++++++--------
fa18db
 1 file changed, 43 insertions(+), 26 deletions(-)
fa18db
fa18db
diff --git a/src/client-python/reportclient/debuginfo.py b/src/client-python/reportclient/debuginfo.py
fa18db
index 4390304e..561de52f 100644
fa18db
--- a/src/client-python/reportclient/debuginfo.py
fa18db
+++ b/src/client-python/reportclient/debuginfo.py
fa18db
@@ -233,6 +233,17 @@ class DebugInfoDownload(object):
fa18db
         self.keeprpms = keep_rpms
fa18db
         self.noninteractive = noninteractive
fa18db
         self.repo_pattern = repo_pattern
fa18db
+        self.package_files_dict = {}
fa18db
+        self.not_found = []
fa18db
+        self.todownload_size = 0
fa18db
+        self.installed_size = 0
fa18db
+        self.find_packages_run = False
fa18db
+
fa18db
+    def get_download_size(self):
fa18db
+        return self.todownload_size
fa18db
+
fa18db
+    def get_install_size(self):
fa18db
+        return self.installed_size
fa18db
 
fa18db
     def mute_stdout(self):
fa18db
         """
fa18db
@@ -286,6 +297,26 @@ class DebugInfoDownload(object):
fa18db
     def download_package(self, pkg):
fa18db
         pass
fa18db
 
fa18db
+    def find_packages(self, files):
fa18db
+        self.find_packages_run = True;
fa18db
+        # nothing to download?
fa18db
+        if not files:
fa18db
+            return RETURN_FAILURE
fa18db
+
fa18db
+        print(_("Initializing package manager"))
fa18db
+        self.prepare()
fa18db
+
fa18db
+        # This takes some time, let user know what we are doing
fa18db
+        print(_("Setting up repositories"))
fa18db
+        self.initialize_repositories()
fa18db
+
fa18db
+        print(_("Looking for needed packages in repositories"))
fa18db
+        (self.package_files_dict,
fa18db
+         self.not_found,
fa18db
+         self.todownload_size,
fa18db
+         self.installed_size) = self.triage(files)
fa18db
+
fa18db
+
fa18db
     # return value will be used as exitcode. So 0 = ok, !0 - error
fa18db
     def download(self, files, download_exact_files=False):
fa18db
         """
fa18db
@@ -309,32 +340,18 @@ class DebugInfoDownload(object):
fa18db
         if retval != RETURN_OK:
fa18db
             return retval
fa18db
 
fa18db
-        print(_("Initializing package manager"))
fa18db
-        self.prepare()
fa18db
-        #if verbose == 0:
fa18db
-        #    # this suppress yum messages about setting up repositories
fa18db
-        #    mute_stdout()
fa18db
-
fa18db
-        # This takes some time, let user know what we are doing
fa18db
-        print(_("Setting up repositories"))
fa18db
-        self.initialize_repositories()
fa18db
-
fa18db
-        #if verbose == 0:
fa18db
-        #    # re-enable the output to stdout
fa18db
-        #    unmute_stdout()
fa18db
-
fa18db
-        print(_("Looking for needed packages in repositories"))
fa18db
-        package_files_dict, not_found, todownload_size, installed_size = self.triage(files)
fa18db
+        if not self.find_packages_run:
fa18db
+            self.find_packages(files)
fa18db
 
fa18db
-        if verbose != 0 or len(not_found) != 0:
fa18db
-            print(_("Can't find packages for {0} debuginfo files").format(len(not_found)))
fa18db
+        if verbose != 0 or len(self.not_found) != 0:
fa18db
+            print(_("Can't find packages for {0} debuginfo files").format(len(self.not_found)))
fa18db
 
fa18db
-        if verbose != 0 or len(package_files_dict) != 0:
fa18db
-            print(_("Packages to download: {0}").format(len(package_files_dict)))
fa18db
+        if verbose != 0 or len(self.package_files_dict) != 0:
fa18db
+            print(_("Packages to download: {0}").format(len(self.package_files_dict)))
fa18db
             question = _(
fa18db
                 "Downloading {0:.2f}Mb, installed size: {1:.2f}Mb. Continue?") \
fa18db
-                .format(todownload_size / (1024 * 1024),
fa18db
-                        installed_size / (1024 * 1024))
fa18db
+                .format(self.todownload_size / (1024 * 1024),
fa18db
+                        self.installed_size / (1024 * 1024))
fa18db
 
fa18db
             if not self.noninteractive and not ask_yes_no(question):
fa18db
                 print(_("Download cancelled by user"))
fa18db
@@ -343,7 +360,7 @@ class DebugInfoDownload(object):
fa18db
             # check if there is enough free space in both tmp and cache
fa18db
             res = os.statvfs(self.tmpdir)
fa18db
             tmp_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024)
fa18db
-            if (todownload_size / (1024 * 1024)) > tmp_space:
fa18db
+            if (self.todownload_size / (1024 * 1024)) > tmp_space:
fa18db
                 question = _("Warning: Not enough free space in tmp dir '{0}'"
fa18db
                              " ({1:.2f}Mb left). Continue?").format(
fa18db
                                  self.tmpdir, tmp_space)
fa18db
@@ -354,7 +371,7 @@ class DebugInfoDownload(object):
fa18db
 
fa18db
             res = os.statvfs(self.cachedir)
fa18db
             cache_space = float(res.f_bsize * res.f_bavail) / (1024 * 1024)
fa18db
-            if (installed_size / (1024 * 1024)) > cache_space:
fa18db
+            if (self.installed_size / (1024 * 1024)) > cache_space:
fa18db
                 question = _("Warning: Not enough free space in cache dir "
fa18db
                              "'{0}' ({1:.2f}Mb left). Continue?").format(
fa18db
                                  self.cachedir, cache_space)
fa18db
@@ -363,10 +380,10 @@ class DebugInfoDownload(object):
fa18db
                     print(_("Download cancelled by user"))
fa18db
                     return RETURN_CANCEL_BY_USER
fa18db
 
fa18db
-        progress_observer = DownloadProgress(len(package_files_dict))
fa18db
+        progress_observer = DownloadProgress(len(self.package_files_dict))
fa18db
         self.initialize_progress(progress_observer)
fa18db
 
fa18db
-        for pkg, files in package_files_dict.items():
fa18db
+        for pkg, files in self.package_files_dict.items():
fa18db
             # Download
fa18db
             package_full_path, err = self.download_package(pkg)
fa18db
 
fa18db
-- 
fa18db
2.24.1
fa18db