diff --git a/gui/slick/interfaces/default/displayShow.tmpl b/gui/slick/interfaces/default/displayShow.tmpl index beceb837..292a218f 100644 --- a/gui/slick/interfaces/default/displayShow.tmpl +++ b/gui/slick/interfaces/default/displayShow.tmpl @@ -237,7 +237,10 @@ Unwanted Group#if len($bwl.get_black_keywords_for("release_group"))>1 then "s" else ""#: #echo ', '.join($bwl.get_black_keywords_for("release_group"))# - #end if + #end if + + Size:$sickbeard.helpers.human(sickbeard.helpers.get_size($showLoc[0])) + diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index a1c87a63..b3c5bab9 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1378,4 +1378,40 @@ def clearCache(force=False): except OSError, e: logger.log(u"Unable to clean " + cache_root + ": " + repr(e) + " / " + str(e), logger.WARNING) - break \ No newline at end of file + break + +def human(size): + """ + format a size in bytes into a 'human' file size, e.g. bytes, KB, MB, GB, TB, PB + Note that bytes/KB will be reported in whole numbers but MB and above will have greater precision + e.g. 1 byte, 43 bytes, 443 KB, 4.3 MB, 4.43 GB, etc + """ + if size == 1: + # because I really hate unnecessary plurals + return "1 byte" + + suffixes_table = [('bytes', 0), ('KB', 0), ('MB', 1), ('GB', 2),('TB', 2), ('PB', 2)] + + num = float(size) + for suffix, precision in suffixes_table: + if num < 1024.0: + break + num /= 1024.0 + + if precision == 0: + formatted_size = "%d" % num + else: + formatted_size = str(round(num, ndigits=precision)) + + return "%s %s" % (formatted_size, suffix) + + +def get_size(start_path='.'): + + total_size = 0 + for dirpath, dirnames, filenames in os.walk(start_path): + for f in filenames: + fp = os.path.join(dirpath, f) + total_size += os.path.getsize(fp) + return total_size +