summaryrefslogtreecommitdiffstats
path: root/src/fringlib/fringutil.py
blob: b5b98df781886ded3e1b32b33c93da07044b7373 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import gtk
import gnomevfs

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 format_uri(uri):
    return gnomevfs.format_uri_for_display(uri)

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")

LICENSE = """
fring is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

fring is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with fring; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
"""