diff options
author | Papoteur <papoteur@mageia.org> | 2019-08-15 17:38:11 +0200 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2019-08-15 17:40:05 +0200 |
commit | eb4bcba5349f9ff5c89e1733acb36aa277efa52f (patch) | |
tree | 3248e644ef8567a77a49be238f15cc5dbc1433c6 /lib/isodumper.py | |
parent | 31278b4585ea9d52671d4c51ac9ad44d2488bd99 (diff) | |
download | isodumper-eb4bcba5349f9ff5c89e1733acb36aa277efa52f.tar isodumper-eb4bcba5349f9ff5c89e1733acb36aa277efa52f.tar.gz isodumper-eb4bcba5349f9ff5c89e1733acb36aa277efa52f.tar.bz2 isodumper-eb4bcba5349f9ff5c89e1733acb36aa277efa52f.tar.xz isodumper-eb4bcba5349f9ff5c89e1733acb36aa277efa52f.zip |
Rework udisks information to be more reliable
enumerate drives, then devices if drive is removable
format drive size.
Diffstat (limited to 'lib/isodumper.py')
-rwxr-xr-x | lib/isodumper.py | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 5ae5af3..eab8b5d 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -79,24 +79,44 @@ class UDisks2(object): if m] list=[] - for dev in devs: - dev_obj =objects[dev['path']][self.DRIVE] - if (dev_obj['ConnectionBus'] == 'usb' or dev_obj['ConnectionBus'] == 'sdio') and \ - (dev_obj['Removable'] == 1 or dev_obj['MediaRemovable'] == 1 ): - item=[] - vend = dev_obj['Vendor'] - name = dev_obj['Model'] - for block in blocks: - if dev['path'] == objects[block['path']][self.BLOCK]['Drive']: - dev_name = block['path'].split('/')[-1] - path = ''.join([i for i in dev_name if not i.isdigit()]) - path = '/dev/' + path - break - size = dev_obj['Size'] - item.append(vend+" "+name) - item.append(path) - item.append(size) - list.append(item) + for block in blocks: + if not block['path'][-1].isdigit(): + for dev in devs: + if dev['path'] == objects[block['path']][self.BLOCK]['Drive']: + dev_obj =objects[dev['path']][self.DRIVE] + if (dev_obj['ConnectionBus'] == 'usb' or dev_obj['ConnectionBus'] == 'sdio') and \ + (dev_obj['Removable'] == 1 or dev_obj['MediaRemovable'] == 1 ): + item=[] + vend = dev_obj['Vendor'] + if vend == "": + name = dev_obj['Model'] + else: + name = vend + " "+ dev_obj['Model'] + dev_name = block['path'].split('/')[-1] + path = '/dev/'+block['path'].split('/')[-1] + size = dev_obj['Size'] + item.append(name) + item.append(path) + item.append(size) + list.append(item) + #for dev in devs: + #dev_obj =objects[dev['path']][self.DRIVE] + #if (dev_obj['ConnectionBus'] == 'usb' or dev_obj['ConnectionBus'] == 'sdio') and \ + #(dev_obj['Removable'] == 1 or dev_obj['MediaRemovable'] == 1 ): + #item=[] + #vend = dev_obj['Vendor'] + #name = dev_obj['Model'] + #for block in blocks: + #if dev['path'] == objects[block['path']][self.BLOCK]['Drive']: + #dev_name = block['path'].split('/')[-1] + #path = ''.join([i for i in dev_name if not i.isdigit()]) + #path = '/dev/' + path + #break + #size = dev_obj['Size'] + #item.append(vend+" "+name) + #item.append(path) + #item.append(size) + # return list class Info(object): @@ -122,9 +142,7 @@ class IsoDumper(object): if len(self.list)>0: for name, path, size in self.list: if size != 0 : - # convert in Mbytes - sizeM=str(int(size)/(1024*1024)) - self.devicelist.addItem(str(name+' ('+path.lstrip()+') '+sizeM+_('Mb')),False) + self.devicelist.addItem(str(name+' ('+path.lstrip()+') ' + self.sizeof_fmt(size)),False) return True @@ -151,6 +169,13 @@ class IsoDumper(object): self.backup_select.setEnabled() break + def sizeof_fmt(self, num): + for unit in [_('B'),_('KiB'),_('MiB'),_('GiB'),_('TiB')]: + if abs(num) < 1024.0: + return "%3.3f %s" % (num, unit) + num /= 1024.0 + return "%.1f %s" % (num, _('TiB')) + def backup_choosed(self): # Add .img if not specified if not self.backup_img_name.lower().endswith('.img'): |