From 7362cc8a4099237ba8b5cec36077596cd3b2ffd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Sat, 18 Jun 2005 23:05:20 +0000 Subject: [PATCH] * implement a function in util to calculate the total file size under a dir --- lib/pisi/util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pisi/util.py b/lib/pisi/util.py index a26f8c76..3170ac62 100644 --- a/lib/pisi/util.py +++ b/lib/pisi/util.py @@ -34,6 +34,17 @@ def clean_dir(top): for name in dirs: os.rmdir(os.path.join(root, name)) + +# calculate the size of files under a dir +# based on the tutorial example +def dir_size(dir): + from os.path import join, getsize + def sizes(): + for root, dirs, files in os.walk(dir): + print sum(getsize(join(root, name)) for name in files) + yield sum(getsize(join(root, name)) for name in files) + return sum( sizes() ) + def copy_file(s,d): check_file(s) check_dir(os.path.dirname(d))