From bb7fc231ea0cf04ab75e0a861b91ee11866ab619 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Thu, 2 Nov 2006 08:33:56 +0000 Subject: [PATCH] * calculate cached files size --- pisi/operations.py | 22 ++++++++++++++++++++-- pisi/package.py | 1 - 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pisi/operations.py b/pisi/operations.py index 5827e7d2..9240820e 100644 --- a/pisi/operations.py +++ b/pisi/operations.py @@ -467,9 +467,9 @@ def upgrade_pkg_names(A = []): ctx.ui.info(_('The following packages will be upgraded: ') + util.strlist(order)) - total_size = sum([ctx.packagedb.get_package(p).packageSize for p in order]) + total_size, cached_size = calculate_download_sizes(order) total_size, symbol = util.human_readable_size(total_size) - ctx.ui.info(_('Total size of packages: %.2f %s') % (total_size, symbol)) + ctx.ui.info(_('Total size of package(s): %.2f %s') % (total_size, symbol)) if ctx.get_option('dry_run'): return @@ -785,3 +785,21 @@ def plan_emerge(A, rebuild_all): G_f2, order_inst = plan_install_pkg_names(install_list) return G_f, order_inst, order_build + +def calculate_download_sizes(order): + total_size = cached_size = 0 + + for pkg in [ctx.packagedb.get_package(name) for name in order]: + + # get the cached package's path + fn = util.package_name(pkg.name, pkg.version, pkg.release, pkg.build, True) + path = util.join_path(ctx.config.packages_dir(), fn) + + # check the file and sha1sum to be sure it _is_ the cached package + if os.path.exists(path) and util.sha1_file(path) == pkg.packageHash: + cached_size += pkg.packageSize + + total_size += pkg.packageSize + + ctx.ui.notify(ui.cached, total=total_size, cached=cached_size) + return total_size, cached_size diff --git a/pisi/package.py b/pisi/package.py index 14cd382d..e6a04155 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -59,7 +59,6 @@ class Package: raise else: ctx.ui.info(_('%s [cached]') % url.filename()) - ctx.ui.notify(pisi.ui.cached, name = url.filename(), size = getsize(self.filepath)) def add_to_package(self, fn, an=None): """Add a file or directory to package"""