[Pkg-privacy-commits] [tails-installer] 114/210: Use DBus signals to handle coming and going USB devices
Intrigeri
intrigeri at moszumanska.debian.org
Wed May 24 15:26:35 UTC 2017
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to tag 3.90.0
in repository tails-installer.
commit a3f79a2075dc043aae8e1a653ce4bfc936db5704
Author: Martin Briza <mbriza at redhat.com>
Date: Wed Jul 1 14:04:29 2015 +0200
Use DBus signals to handle coming and going USB devices
---
liveusb/creator.py | 72 +++++++++++++++++++++++++++++-------------------------
liveusb/gui.py | 20 ++++++++++-----
2 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/liveusb/creator.py b/liveusb/creator.py
index 9c562bb..b57c41c 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -501,9 +501,11 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
'that does not support the ext4 filesystem'))
self.valid_fstypes -= set(['ext4'])
- def detect_removable_drives(self, callback=None):
+ def detect_removable_drives(self, callbackAdded=None, callbackRemoved=None):
""" Detect all removable USB storage devices using UDisks2 via D-Bus """
import dbus
+ self.callbackAdded = callbackAdded
+ self.callbackRemoved = callbackRemoved
self.drives = {}
self.bus = dbus.SystemBus()
udisks_obj = self.bus.get_object("org.freedesktop.UDisks2",
@@ -513,38 +515,21 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
def strify(s):
return bytearray(s).replace(b'\x00', b'').decode('utf-8')
- for name, device in self.udisks.GetManagedObjects().iteritems():
+ def handleAdded(name, device):
if ('org.freedesktop.UDisks2.Block' in device and
'org.freedesktop.UDisks2.Filesystem' in device and
'org.freedesktop.UDisks2.Partition' in device):
self.log.debug('Found block device with filesystem on %s' % name)
else:
- continue
+ return
partition = device['org.freedesktop.UDisks2.Partition']
fs = device['org.freedesktop.UDisks2.Filesystem']
blk = device['org.freedesktop.UDisks2.Block']
- """
- if blk['HintAuto'] is False:
- self.log.debug('Skipping non-automounting filesystem: %s' % name)
- continue
- if blk['HintSystem'] is True:
- self.log.debug('Skipping system filesystem: %s' % name)
- continue
- if blk['ReadOnly'] is True:
- self.log.debug('Skipping read-only filesystem: %s' % name)
- continue
- if blk['IdUsage'] != 'filesystem':
- self.log.debug('Skipping non-filesystem device: %s' % name)
- continue
- if blk['HintIgnore'] is True:
- self.log.debug('Skipping ignorable device: %s' % name)
- continue
- """
if blk['Drive'] == '/':
self.log.debug('Skipping root drive: %s' % name)
- continue
+ return
drive_obj = self.bus.get_object("org.freedesktop.UDisks2", blk['Drive'])
drive = dbus.Interface(drive_obj, "org.freedesktop.DBus.Properties").GetAll("org.freedesktop.UDisks2.Drive")
@@ -555,7 +540,7 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
(drive[u'ConnectionBus'] != 'usb' and
drive[u'ConnectionBus'] != 'sdio')):
self.log.debug('Skipping a device that is not removable, connected via USB or is optical: %s' % name)
- continue
+ return
data = {
'udi': str(blk['Drive']),
@@ -571,19 +556,19 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
if '/boot' in data['mount']:
self.log.debug('Skipping boot device: %s' % name)
- continue
+ return
# Skip things without a size
if not data['size'] and not self.opts.force:
self.log.debug('Skipping device without size: %s' % device)
- continue
+ return
# Skip devices with unknown filesystems
if data['fstype'] not in self.valid_fstypes and \
self.opts.force != data['device']:
self.log.debug('Skipping %s with unknown filesystem: %s' % (
data['device'], data['fstype']))
- continue
+ return
mount = data['mount']
if mount:
@@ -597,22 +582,43 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
data['free'] = mount and \
self.get_free_bytes(mount) / 1024**2 or None
- print(partition[u'Table'])
parent_obj = self.bus.get_object("org.freedesktop.UDisks2", partition[u'Table'])
parent = dbus.Interface(parent_obj, "org.freedesktop.DBus.Properties").Get("org.freedesktop.UDisks2.Block", "Device")
data['parent'] = strify(parent)
self.log.debug(pformat(data))
- self.drives[data['device']] = data
+ self.drives[name] = data
- # Remove parent drives if a valid partition exists
- #for parent in [d['parent'] for d in self.drives.values()]:
- # if parent in self.drives:
- # del(self.drives[parent])
+ if self.callbackAdded:
+ self.callbackAdded()
- if callback:
- callback()
+ def handleRemoved(path, interfaces):
+
+ print ("KEYS!", path, self.drives.keys())
+ if self.drives.has_key(path):
+ print("PRE REMOVED", path, interfaces)
+ del self.drives[path]
+ print("POST REMOVED", path, interfaces)
+
+ if self.callbackRemoved:
+ self.callbackRemoved()
+ #blk = device['org.freedesktop.UDisks2.Block']
+ #if path.startswith("/org/freedesktop/UDisks2"):
+
+ #if 'org.freedesktop.UDisks2.Block' in interfaces:
+ #object = self.bus.get_object("org.freedesktop.UDisks2", path)
+ #device = dbus.Interface(object, "org.freedesktop.UDisks2.Block").GetAll("Drive")
+ #print device
+ #print("FOUND:", device['org.freedesktop.UDisks2.Block'])
+ #print("GOT:", self.drives.keys())
+ #callbackRemoved()
+
+ self.bus.add_signal_receiver(handleAdded, "InterfacesAdded", "org.freedesktop.DBus.ObjectManager", "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2")
+ self.bus.add_signal_receiver(handleRemoved, "InterfacesRemoved", "org.freedesktop.DBus.ObjectManager", "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2")
+
+ for name, device in self.udisks.GetManagedObjects().iteritems():
+ handleAdded(name, device)
def _storage_bus(self, dev):
storage_bus = None
diff --git a/liveusb/gui.py b/liveusb/gui.py
index cdac8cd..5360917 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -327,24 +327,27 @@ class LiveUSBWindow(QtGui.QMainWindow, LiveUSBInterface):
self.driveBox.clear()
#self.textEdit.clear()
- def add_devices():
- if not len(self.live.drives):
+ def update_devices():
+ self.driveBox.clear()
+ if len(self.live.drives) <= 0:
self.textEdit.setPlainText(_("Unable to find any USB drives"))
self.startButton.setEnabled(False)
return
for device, info in self.live.drives.items():
if info['label']:
- self.driveBox.addItem("%s (%s)" % (device, info['label']))
+ self.driveBox.addItem("%s (%s)" % (info['device'], info['label']))
else:
self.driveBox.addItem(device)
self.startButton.setEnabled(True)
try:
- self.live.detect_removable_drives(callback=add_devices)
+ self.live.detect_removable_drives(callbackAdded=update_devices,callbackRemoved=update_devices)
except LiveUSBError, e:
self.textEdit.setPlainText(e.args[0])
self.startButton.setEnabled(False)
+ update_devices()
+
def populate_releases(self):
for release in [release['name'] for release in releases]:
self.downloadCombo.addItem(release)
@@ -416,7 +419,10 @@ class LiveUSBWindow(QtGui.QMainWindow, LiveUSBInterface):
drive = unicode(drive)
if not drive:
return
- self._refresh_overlay_slider(drive.split()[0])
+ print self.live.drives
+ for key in self.live.drives:
+ if self.live.drives[key]['device'] == drive.split()[0]:
+ self._refresh_overlay_slider(key)
def _refresh_overlay_slider(self, drive=None):
"""
@@ -507,7 +513,9 @@ class LiveUSBWindow(QtGui.QMainWindow, LiveUSBInterface):
def get_selected_drive(self):
text = self.live._to_unicode(self.driveBox.currentText()).split()
if text:
- return text[0]
+ for key, drive in self.live.drives:
+ if drive['device'] == text:
+ return key
def begin(self):
""" Begin the liveusb creation process.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git
More information about the Pkg-privacy-commits
mailing list