diff options
author | Papoteur <papoteur@mageialinux-online.org> | 2016-08-21 19:52:12 +0200 |
---|---|---|
committer | Papoteur <papoteur@mageialinux-online.org> | 2016-08-21 19:52:12 +0200 |
commit | 39f0d84e9c117e94c6b01898c2d4a74c51c6cab3 (patch) | |
tree | 87bf6feff81ca549399ced22e75ab9ee78bddc8e | |
parent | 3535908b34c9519ed64fcd96318372026cd55e13 (diff) | |
download | isodumper-39f0d84e9c117e94c6b01898c2d4a74c51c6cab3.tar isodumper-39f0d84e9c117e94c6b01898c2d4a74c51c6cab3.tar.gz isodumper-39f0d84e9c117e94c6b01898c2d4a74c51c6cab3.tar.bz2 isodumper-39f0d84e9c117e94c6b01898c2d4a74c51c6cab3.tar.xz isodumper-39f0d84e9c117e94c6b01898c2d4a74c51c6cab3.zip |
Better detection of the device (mga#18411), avoiding to write to a partition.
The device is obtained through Drive list of udisks2, but without
/dev/sdxx name. This is got trough Block list, but without direct
correspondance. Thus, we get the first block which has 'Drive' the
selected Drive, and suppress the trailing digits.
Clean unused code
-rwxr-xr-x | lib/isodumper.py | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 8af078e..4fae067 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -42,7 +42,6 @@ class NoUDisks2(Exception): class UDisks2(object): BLOCK = 'org.freedesktop.UDisks2.Block' - FILESYSTEM = 'org.freedesktop.UDisks2.Filesystem' DRIVE = 'org.freedesktop.UDisks2.Drive' def __init__(self): @@ -55,41 +54,6 @@ class UDisks2(object): raise NoUDisks2() raise - def device(self, device_node_path): - device_node_path = os.path.realpath(device_node_path) - devname = device_node_path.split('/')[-1] - - # First we try a direct object path - bd = self.bus.get_object('org.freedesktop.UDisks2', - '/org/freedesktop/UDisks2/block_devices/%s'%devname) - try: - device = bd.Get(self.BLOCK, 'Device', - dbus_interface='org.freedesktop.DBus.Properties') - device = bytearray(device).replace(b'\x00', b'').decode('utf-8') - except: - device = None - - if device == device_node_path: - return bd - - # Enumerate all devices known to UDisks2 - devs = self.bus.get_object('org.freedesktop.UDisks2', - '/org/freedesktop/UDisks2/block_devices') - xml = devs.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable') - for dev in re.finditer(r'name=[\'"](.+?)[\'"]', type(u'')(xml)): - bd = self.bus.get_object('org.freedesktop.UDisks2', - '/org/freedesktop/UDisks2/block_devices/%s2'%dev.group(1)) - try: - device = bd.Get(self.BLOCK, 'Device', - dbus_interface='org.freedesktop.DBus.Properties') - device = bytearray(device).replace(b'\x00', b'').decode('utf-8') - except: - device = None - if device == device_node_path: - return bd - - raise ValueError(_('%r not known to UDisks2')%device_node_path) - def find_devices(self): proxy = self.bus.get_object("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2") iface = dbus.Interface(proxy, "org.freedesktop.UDisks2") @@ -113,8 +77,11 @@ class UDisks2(object): vend = dev_obj['Vendor'] name = dev_obj['Model'] for block in blocks: - if dev['path'] == objects[block['path']]['org.freedesktop.UDisks2.Block']['Drive']: - path = '/dev/'+block['path'].split('/')[-1] + if dev['path'] == objects[block['path']][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) @@ -132,7 +99,7 @@ class IsoDumper: def __init__(self,user): APP="isodumper" DIR="/usr/share/locale" - RELEASE="v0.47" + RELEASE="v0.48" gettext.bindtextdomain(APP, DIR) gettext.textdomain(APP) |