blob: f981a45e2821252b1563f27e0b4a48f191febd3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import os
def get_parent_from_uri(uri):
""" Get the parent folder from an uri """
p = os.path.split(uri)
p = os.path.join(p[:-1])
return p[0]
def pretty_size(size):
if size >= 1024*1024*1024:
return "%.1f GiB" % round(size/1024/1024/1024.0)
elif size >= 1024*1024:
return "%.1f MiB" % round(size/1024/1024.0)
elif size >= 1024:
return "%.1f KiB" % round(size/1024.0)
else:
return "%u B" % size
def format_disk_space(size):
""" Convert bytes to a human readable format.
Returns a tuple, for example (20,"MiB") """
if size >= 1024*1024*1024:
return ("%.1f"%round(size/1024/1024/1024.0),"GiB")
elif size >= 1024*1024:
return ("%.1f"%round(size/1024/1024.0),"MiB")
elif size >= 1024:
return ("%.1f"%round(size/1024.0),"KiB")
else:
return ("%u"%size,"B")
|