From: Michael Tremer Date: Tue, 22 Feb 2011 17:18:16 +0000 (+0100) Subject: Fix calculation of total download size. X-Git-Tag: 0.9.3~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edd6a268e77688d035950c53c2d5ea7387825b72;p=pakfire.git Fix calculation of total download size. --- diff --git a/pakfire/depsolve.py b/pakfire/depsolve.py index 133b4c8e1..5653cf670 100644 --- a/pakfire/depsolve.py +++ b/pakfire/depsolve.py @@ -235,9 +235,11 @@ class DependencySet(object): s.append(format % (_("Remove"), len(self.ts.removes + self.ts.remove_deps), _("Package(s)"))) - download_size = sum([p.size for p in self.ts.installs + \ - self.ts.install_deps + self.ts.updates + self.ts.update_deps]) - s.append(_("Total download size: %s") % util.format_size(download_size)) + # Calculate the size of all files that need to be downloaded this this + # transaction. + download_size = sum([p.size for p in self.ts.downloads]) + if download_size: + s.append(_("Total download size: %s") % util.format_size(download_size)) s.append("") for line in s: diff --git a/pakfire/packages/base.py b/pakfire/packages/base.py index 7159cb20b..c2f8db92f 100644 --- a/pakfire/packages/base.py +++ b/pakfire/packages/base.py @@ -106,6 +106,14 @@ class Package(object): """ return 0 + @property + def local(self): + """ + Indicates whether a package is located "local" means on disk + and has not be downloaded. + """ + return False + ### META INFORMATION ### @property diff --git a/pakfire/packages/file.py b/pakfire/packages/file.py index 1f73b6273..1f819fd1c 100644 --- a/pakfire/packages/file.py +++ b/pakfire/packages/file.py @@ -41,6 +41,11 @@ class FilePackage(Package): if self._archive: self._archive.close() + @property + def local(self): + # A file package is always local. + return True + @property def archive(self): if not self._archive: diff --git a/pakfire/transaction.py b/pakfire/transaction.py index 9ff29b60c..90bdfc9ff 100644 --- a/pakfire/transaction.py +++ b/pakfire/transaction.py @@ -101,6 +101,18 @@ class TransactionSet(object): self.removes = [] self.remove_deps = [] + @property + def downloads(self): + """ + Return a list containing all packages that need to be downloaded. + """ + for pkg in self.installs + self.install_deps + self.updates + self.update_deps: + # Skip all packages that are already local. + if pkg.local: + continue + + yield pkg + def install(self, pkg, dep=False): logging.info(" --> Marking package for install: %s" % pkg.friendly_name)