[Pkg-privacy-commits] [tails-installer] 25/27: Make the restore code work in Linux. Not shown in the UI yet

Intrigeri intrigeri at moszumanska.debian.org
Wed May 24 15:27:00 UTC 2017


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to tag 3.91.0
in repository tails-installer.

commit 2975877d1266a57477ac13209450f15ca3145f46
Author: Martin Briza <mbriza at redhat.com>
Date:   Fri Mar 18 13:23:23 2016 +0100

    Make the restore code work in Linux. Not shown in the UI yet
---
 liveusb/creator.py | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
 liveusb/gui.py     | 25 +++++++++----------------
 2 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/liveusb/creator.py b/liveusb/creator.py
index d8251e7..638f385 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -242,7 +242,7 @@ class LiveUSBCreator(object):
     def dd_image(self):
         raise NotImplementedError
 
-    def restore_drive(self, d):
+    def restore_drive(self, d, callback):
         raise NotImplementedError
 
 
@@ -262,7 +262,8 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
         import dbus
         self.callback = callback
         self.drives = {}
-        self.bus = dbus.SystemBus()
+        if not self.bus:
+            self.bus = dbus.SystemBus()
         udisks_obj = self.bus.get_object("org.freedesktop.UDisks2",
                                          "/org/freedesktop/UDisks2")
         self.udisks = dbus.Interface(udisks_obj, 'org.freedesktop.DBus.ObjectManager')
@@ -429,12 +430,51 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
     def flush_buffers(self):
         self.popen('sync', passive=True)
 
+
     def is_admin(self):
         return os.getuid() == 0
 
-    def restore_drive(self, d):
-        time.sleep(15)
-        pass
+    def restore_drive(self, d, callback):
+        import dbus
+
+        if not self.bus:
+            self.bus = dbus.SystemBus()
+
+        will_format = None
+        will_format_device = None
+
+        for name, device in self.udisks.GetManagedObjects().iteritems():
+            if 'org.freedesktop.UDisks2.Block' in device and 'org.freedesktop.UDisks2.Filesystem' in device:
+                current_device = self.strify(device['org.freedesktop.UDisks2.Block']['Device'])
+                if current_device.startswith(d.device) and device['org.freedesktop.UDisks2.Filesystem']['MountPoints']:
+                    obj = self.bus.get_object('org.freedesktop.UDisks2', name)
+                    obj.Unmount({'Force': True}, dbus_interface='org.freedesktop.UDisks2.Filesystem')
+            if 'org.freedesktop.UDisks2.Block' in device and 'org.freedesktop.UDisks2.PartitionTable' in device:
+                current_device = self.strify(device['org.freedesktop.UDisks2.Block']['Device'])
+                if current_device == d.device:
+                    will_format = name
+                    will_format_device = device
+
+        obj = self.bus.get_object('org.freedesktop.UDisks2', will_format)
+
+        create = obj.get_dbus_method('CreatePartition', 'org.freedesktop.UDisks2.PartitionTable')
+        clear = obj.get_dbus_method('Format', 'org.freedesktop.UDisks2.Block')
+
+        def error_handler(msg):
+            callback(False, msg.get_dbus_message())
+
+        def format_reply_handler():
+            callback(True)
+
+        def create_reply_handler(partition):
+            obj = self.bus.get_object('org.freedesktop.UDisks2', partition)
+            format = obj.get_dbus_method('Format', 'org.freedesktop.UDisks2.Block')
+            format.call_async('vfat', {}, reply_handler=format_reply_handler, error_handler=error_handler)
+
+        def clear_reply_handler():
+            create.call_async(0, will_format_device['org.freedesktop.UDisks2.Block']['Size'], '', '', {}, reply_handler=create_reply_handler, error_handler=error_handler)
+
+        clear.call_async('dos', {}, reply_handler=clear_reply_handler, error_handler=error_handler)
 
 
 class MacOsLiveUSBCreator(LiveUSBCreator):
diff --git a/liveusb/gui.py b/liveusb/gui.py
index 628ef84..2f033f3 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -692,20 +692,6 @@ class LiveUSBLogHandler(logging.Handler):
         if record.levelname in ('INFO', 'ERROR', 'WARN'):
             self.cb(record.msg)
 
-class USBDriveRestoreThread(QThread):
-    """ The actual write to the portable drive """
-
-    def __init__(self, parent):
-        QThread.__init__(self, parent)
-
-        self.live = parent.live
-        self.parent = parent
-
-    def run(self):
-        self.parent.beingRestored = True
-        self.live.restore_drive(self.parent.drive)
-        self.parent.beingRestored = False
-
 class USBDrive(QObject):
 
     beingRestoredChanged = pyqtSignal()
@@ -737,10 +723,13 @@ class USBDrive(QObject):
         if not v:
             self._restoreThread = None
 
+    def restoreCallback(self, ok, message=None):
+        beingRestored = False
+
     @pyqtSlot()
     def restore(self):
-        self._restoreThread = USBDriveRestoreThread(self)
-        self._restoreThread.start()
+        beingRestored = True
+        self.live.restore_drive(self.drive, self.restoreCallback)
 
 class LiveUSBData(QObject):
     """ An entry point to all the exposed properties.
@@ -782,6 +771,10 @@ class LiveUSBData(QObject):
         previouslySelected = ''
         if len(self._usbDrives) > 0:
             previouslySelected = self._usbDrives[self._currentDrive].drive.device
+
+        if self._driveToRestore and self._driveToRestore.beingRestored:
+            return
+
         for drive, info in self.live.drives.items():
             name = info.friendlyName
 

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