3 """Some common utility functions.
10 def convert_size(size
):
11 """Convert a string like '500MB' into size that can be used to create partitions etc.
14 mb
= re
.compile("^([0-9]+)\s*(MB?)?$")
15 match
= mb
.match(size
)
17 ret
= long(match
.group(1)) * (1 << 20) / parted
.SECTOR_SIZE
20 gkb
= re
.compile("^([0-9]+)\s*(G|K)B?$")
21 match
= gkb
.match(size
)
24 if match
.group(2) == 'G':
26 ret
= long(match
.group(1)) * unit
/ parted
.SECTOR_SIZE
30 def get_display_size(size
):
31 """Return a good display string for size (in bytes).
35 size
= float(size
/ (1 << 30))
37 elif size
> (1 << 20):
38 size
= float(size
/ (1 << 20))
40 elif size
> (1 << 10):
41 size
= float(size
/ (1 << 10))
43 size
= ("%.1lf " + unit
) % (float(size
))
46 def create_box(label
, widget
, homo
= False, vert
= False):
47 hbox
= gnt
.Box(homo
= homo
, vert
= vert
)
48 hbox
.add_widget(label
)
49 hbox
.add_widget(widget
)
51 hbox
.set_alignment(gnt
.ALIGN_MID
)
54 filesystems
= ['ext2', 'fat32', 'fat16', 'HFS', 'linux-swap', 'NTFS', 'reiserfs', 'ufs']