diff options
-rwxr-xr-x | backend/raw_write.py | 78 |
1 files changed, 61 insertions, 17 deletions
diff --git a/backend/raw_write.py b/backend/raw_write.py index 9f06295..48dbb9c 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -234,14 +234,28 @@ class Dumper(object): def _do_persistence(self, target, label, key): logging.debug("Start doing persistence partition") - p = Popen(["fdisk",target], stdin = PIPE) - p.communicate(input=b'n\np\n3\n\n\nw\n') - # example mkfs.ext4 -L mgalive-persist /dev/sdf3 + p = Popen(["fdisk",target], stdin = PIPE, stderr=PIPE) + outs, errs = p.communicate(input=b'n\np\n3\n\n\nw\n') + working=True + while working: + time.sleep(0.5) + p.poll() + rc=p.returncode + if rc is None: + working=True + else: + process = None + working= False + if rc != 0: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs.decode('utf-8') + return + logging.debug("New partition created") if key == "": - print("No key provided", file=sys.stderr) - process = Popen(['mkfs.ext4','-L', label, target+"3"]) - p.communicate() + # example mkfs.ext4 -L mgalive-persist /dev/sdf3 + process = Popen(['mkfs.ext4','-L', label, target+"3"],sterr=PIPE) + outs, errs = p.communicate() working=True while working: time.sleep(0.5) @@ -252,13 +266,21 @@ class Dumper(object): else: process = None working= False - logging.debug("Persistence partition done") + if rc == 0: + self.return_state = True + self.return_message = _("Persistent partition done") + else: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs + return + logging.info("Persistent partition done") + else: - # cryptsetup luksFormat /dev/sdb3 + # example cryptsetup luksFormat /dev/sdb3 print("Crypt key provided",file=sys.stderr) base_target = os.path.basename(target) + "3" - process = Popen(['cryptsetup','luksFormat','-q', target+"3", '-d', '-'],stdin=PIPE) - process.communicate(input=key.encode('utf-8')) + process = Popen(['cryptsetup','luksFormat','-q', target+"3", '-d', '-'],stdin=PIPE, stderr=PIPE) + outs, errs = process.communicate(input=key.encode('utf-8')) working=True while working: time.sleep(0.5) @@ -269,10 +291,15 @@ class Dumper(object): else: process = None working= False + if rc != 0: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs + logging.error(self.return_message) + return # cryptsetup open /dev/sdb3 crypt_sdb3 - process = Popen(['cryptsetup','luksOpen', target + "3", 'crypt_' + base_target ,'-d','-'],stdin=PIPE) - process.communicate(input=key.encode('utf-8')) + process = Popen(['cryptsetup','luksOpen', target + "3", 'crypt_' + base_target ,'-d','-'],stdin=PIPE, stderr=PIPE) + outs, errs = process.communicate(input=key.encode('utf-8')) working=True while working: time.sleep(0.5) @@ -283,9 +310,15 @@ class Dumper(object): else: process = None working= False + if rc != 0: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs + logging.error(self.return_message) + return + # mkfs.ext4 -L mgalive-persist /dev/mapper/crypt_sdb3 - process = Popen(['mkfs.ext4','-L', label, '/dev/mapper/crypt_' + base_target]) - process.communicate() + process = Popen(['mkfs.ext4','-L', label, '/dev/mapper/crypt_' + base_target],stderr=PIPE) + outs, errs = process.communicate() working=True while working: time.sleep(0.5) @@ -296,10 +329,15 @@ class Dumper(object): else: process = None working= False + if rc != 0: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs + logging.error(self.return_message) + return # cryptsetup close crypt_sdb3 process = Popen(['cryptsetup','luksClose', 'crypt_' + base_target ]) - process.communicate() + outs, errs = process.communicate() working=True while working: time.sleep(0.5) @@ -310,8 +348,14 @@ class Dumper(object): else: process = None working= False - return rc - + if rc != 0: + self.return_state = False + self.return_message = _("Error while doing persistent partition: ") + errs + logging.error(self.return_message) + else: + self.return_state = True + self.return_message = _("Persistent partition done") + logging.info("Persistent partition done") def __init__(self): |