X-Git-Url: https://source.tree.se/git?p=treecutter.git;a=blobdiff_plain;f=treecutter%2Ftools.py;h=62cb32a71943c6cdf3aa19bd59f20ef8bfd2c398;hp=a9c94a0837b7cf523ff17d40d1e361a027b75706;hb=a456d5f41ddd66322dc55892b7cb3075554a3264;hpb=98c7fb4a79dda11aa974969489d1bae46a4ae946 diff --git a/treecutter/tools.py b/treecutter/tools.py index a9c94a0..62cb32a 100644 --- a/treecutter/tools.py +++ b/treecutter/tools.py @@ -27,3 +27,20 @@ def ssh_cmd(target, command): retcode = subprocess.call(cmd) if retcode: print 'Error: '+' '.join(cmd)+' Returncode ['+str(retcode)+']' + +def sizeof_fmt(num, suffix='B'): + for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: + if abs(num) < 1024.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1024.0 + return "%.1f%s%s" % (num, 'Yi', suffix) + +def get_folder_size(folder): + total_size = os.path.getsize(folder) + for item in os.listdir(folder): + itempath = os.path.join(folder, item) + if os.path.isfile(itempath): + total_size += os.path.getsize(itempath) + elif os.path.isdir(itempath): + total_size += get_folder_size(itempath) + return total_size