diff options
Diffstat (limited to 'pym/_emerge/format_size.py')
-rw-r--r-- | pym/_emerge/format_size.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pym/_emerge/format_size.py b/pym/_emerge/format_size.py new file mode 100644 index 000000000..7638100f6 --- /dev/null +++ b/pym/_emerge/format_size.py @@ -0,0 +1,16 @@ + +# formats a size given in bytes nicely +def format_size(mysize): + if isinstance(mysize, basestring): + return mysize + if 0 != mysize % 1024: + # Always round up to the next kB so that it doesn't show 0 kB when + # some small file still needs to be fetched. + mysize += 1024 - mysize % 1024 + mystr=str(mysize/1024) + mycount=len(mystr) + while (mycount > 3): + mycount-=3 + mystr=mystr[:mycount]+","+mystr[mycount:] + return mystr+" kB" + |