[Yum-devel] [PATCH 2/2] If we are only installing, display the amount of disk space used. BZ 487623

James Antill james at and.org
Tue Dec 22 21:18:43 UTC 2009


---
 cli.py    |    7 +++++--
 output.py |   16 +++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/cli.py b/cli.py
index f787968..c563e63 100644
--- a/cli.py
+++ b/cli.py
@@ -375,8 +375,11 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         # Check which packages have to be downloaded
         downloadpkgs = []
         stuff_to_download = False
+        install_only = True
         for txmbr in self.tsInfo.getMembers():
-            if txmbr.ts_state in ['i', 'u']:
+            if txmbr.ts_state not in ('i', 'u'):
+                install_only = False
+            else:
                 stuff_to_download = True
                 po = txmbr.po
                 if po:
@@ -390,7 +393,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         # Report the total download size to the user, so he/she can base
         # the answer on this info
         if stuff_to_download:
-            self.reportDownloadSize(downloadpkgs)
+            self.reportDownloadSize(downloadpkgs, install_only)
         
         # confirm with user
         if self._promptWanted():
diff --git a/output.py b/output.py
index 7f92701..e1062d7 100755
--- a/output.py
+++ b/output.py
@@ -864,10 +864,11 @@ class YumOutput:
     def matchcallback_verbose(self, po, values, matchfor=None):
         return self.matchcallback(po, values, matchfor, verbose=True)
         
-    def reportDownloadSize(self, packages):
+    def reportDownloadSize(self, packages, installonly=False):
         """Report the total download size for a set of packages"""
         totsize = 0
         locsize = 0
+        insize  = 0
         error = False
         for pkg in packages:
             # Just to be on the safe side, if for some reason getting
@@ -881,6 +882,15 @@ class YumOutput:
                         locsize += size
                 except:
                     pass
+
+                if not installonly:
+                    continue
+
+                try:
+                    size = int(pkg.installedsize)
+                except:
+                    pass
+                insize += size
             except:
                 error = True
                 self.logger.error(_('There was an error calculating total download size'))
@@ -893,6 +903,10 @@ class YumOutput:
             if locsize != totsize:
                 self.verbose_logger.log(logginglevels.INFO_1, _("Total download size: %s"), 
                                         self.format_number(totsize - locsize))
+            if installonly:
+                self.verbose_logger.log(logginglevels.INFO_1,
+                                        _("Installed size: %s"),
+                                        self.format_number(insize))
             
     def listTransaction(self):
         """returns a string rep of the  transaction in an easy-to-read way."""
-- 
1.6.5.2



More information about the Yum-devel mailing list