aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2020-10-10 12:52:06 +0200
committerPapoteur <papoteur@mageia.org>2020-10-10 12:52:06 +0200
commit194a1e4f3206bcd69a0d29a831d009d0aad49536 (patch)
tree703ee51786319e17a655d4eb518b9c92f5c4d42f
parent80aa0733fac3bec248fc764ed44cb44d68899636 (diff)
downloadisodumper-194a1e4f3206bcd69a0d29a831d009d0aad49536.tar
isodumper-194a1e4f3206bcd69a0d29a831d009d0aad49536.tar.gz
isodumper-194a1e4f3206bcd69a0d29a831d009d0aad49536.tar.bz2
isodumper-194a1e4f3206bcd69a0d29a831d009d0aad49536.tar.xz
isodumper-194a1e4f3206bcd69a0d29a831d009d0aad49536.zip
Add waiting step for table partition after new created partition
Move the do_persistence step in a thread a display progress
-rwxr-xr-xbackend/magiback5
-rwxr-xr-xbackend/raw_write.py40
-rwxr-xr-xlib/isodumper.py24
3 files changed, 53 insertions, 16 deletions
diff --git a/backend/magiback b/backend/magiback
index e7541c3..2ad748b 100755
--- a/backend/magiback
+++ b/backend/magiback
@@ -94,9 +94,12 @@ class Isodumper(raw_write.Dumper):
def do_persistence(self, target, label, key):
self.finished.clear()
if self.writing_perm and self.writing_target == target :
- self._do_persistence(target, label, key)
+ self.thread = threading.Thread(target=self._do_persistence, args=(target, label, key))
+ self.thread.start()
+ logging.debug("Persistence thread started")
else:
self.return_message = "Persistence: Access denied"
+ self.finished.set()
self.writing_perm = False
self.writing_target = ""
diff --git a/backend/raw_write.py b/backend/raw_write.py
index 33279d7..0bdaf81 100755
--- a/backend/raw_write.py
+++ b/backend/raw_write.py
@@ -261,10 +261,24 @@ class Dumper(object):
self.return_message = _("Error while doing persistent partition: ") + errs.decode('utf-8')
return
logging.debug("New partition created")
-
- # Wait some time to propagate the info of new partition table
- time.sleep(1.0)
+ self._progress = 33
+ # Wait for propagation of the info of new partition table
+ wait = Popen(["udevadm","settle","--timeout=15"], stderr=PIPE)
+ outs, errs = wait.communicate()
+ working=True
+ while working:
+ time.sleep(0.5)
+ wait.poll()
+ rc=wait.returncode
+ if not (rc is None):
+ wait = None
+ working= False
+ if rc != 0:
+ self.return_state = False
+ self.return_message = _("Timeout reached when creating a new partition table")
+ return
+ self._progress = 50
if key == "":
# example mkfs.ext4 -L mgalive-persist /dev/sdf3
process = Popen(['mkfs.ext4','-L', label, target+"3"],stderr=PIPE)
@@ -281,13 +295,14 @@ class Dumper(object):
working= False
if rc == 0:
self.return_state = True
+ self._progress = 100
self.return_message = _("Persistent partition done")
else:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
+ self.finished.set()
return
logging.info("Persistent partition done")
-
else:
# example cryptsetup luksFormat /dev/sdb3
print("Crypt key provided",file=sys.stderr)
@@ -306,9 +321,11 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
+ self._progress = 75
# cryptsetup open /dev/sdb3 crypt_sdb3
process = Popen(['cryptsetup','luksOpen', target + "3", 'crypt_' + base_target ,'-d','-'],stdin=PIPE, stderr=PIPE)
@@ -325,8 +342,9 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
# mkfs.ext4 -L mgalive-persist /dev/mapper/crypt_sdb3
@@ -344,8 +362,9 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
# cryptsetup close crypt_sdb3
@@ -363,12 +382,15 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
else:
self.return_state = True
self.return_message = _("Persistent partition done")
logging.info("Persistent partition done")
+ self._progress = 100
+ self.finished.set()
+ logging.debug("Finished")
def __init__(self):
diff --git a/lib/isodumper.py b/lib/isodumper.py
index 4f77422..6e111b1 100755
--- a/lib/isodumper.py
+++ b/lib/isodumper.py
@@ -44,13 +44,12 @@ import time
import os
import re
import gettext
-from subprocess import call, Popen, PIPE
+from subprocess import Popen, PIPE
from pydbus import SystemBus
-from gi.repository import GLib
import psutil
import manatools.args as args
-
+
class NoUDisks2(Exception):
@@ -122,7 +121,7 @@ class Info(object):
class ParseCLI(args.AppArgs):
def __init(self, command):
super().__init__(command)
-
+
class IsoDumper(object):
def get_devices(self):
@@ -346,18 +345,31 @@ class IsoDumper(object):
self.logger(message)
# Add persistent partition if asked
if self.persistencecb.isChecked():
- self.logger(_("Adding persistent partition"))
+ self.progress.setLabel(_("Adding persistent partition"))
+ self.progress.setValue(0)
if self.cryptcb.isChecked():
if self.cryptkey.value() == "":
self.logger(_("No key for encrypted partition provided. Adding the partition aborted."))
else:
iface.do_persistence(target,"mgalive-persist", self.cryptkey.value())
+ progress = iface.progress
+ while not iface.done :
+ progress = iface.progress
+ self.progress.setValue(progress)
+ self.dialog.pollEvent()
+ time.sleep(.5)
if iface.state:
self.logger(_("Added encrypted persistent partition"))
else:
self.logger(iface.message)
else:
iface.do_persistence(target, "mgalive-persist", "")
+ progress = iface.progress
+ while not iface.done :
+ progress = iface.progress
+ self.progress.setValue(progress)
+ self.dialog.pollEvent()
+ time.sleep(.5)
self.logger(_("Added persistent partition"))
# Unmount if partitions are automatically mounted and then eject
success, message = iface.do_unmount(target)
@@ -365,7 +377,7 @@ class IsoDumper(object):
self.u.eject(target)
self.success()
else:
- emergency(message)
+ self.emergency(message)
self.restore()
else:
self.emergency(message)