From acafa4b8c920ce7032515812984e22f611660a72 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Tue, 19 Dec 2017 19:36:32 +0000 Subject: [PATCH] Add exception handling to get_disk_info Similar to 92305ebd92dab070e7c6dafc0acd56b6cafe7547, except instead of handling the error in the callers of get_disk_info, fix it in the function directly since all but one of the callers were checking for empty results anyway. --- ister_gui.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ister_gui.py b/ister_gui.py index e9dc134..ff3e9c7 100644 --- a/ister_gui.py +++ b/ister_gui.py @@ -81,7 +81,10 @@ def get_disk_info(disk): """Return dictionary with disk information""" info = {'partitions': []} cmd = ['/usr/bin/fdisk', '-l', disk] - output = subprocess.check_output(cmd).decode('utf-8') + try: + output = subprocess.check_output(cmd).decode('utf-8') + except: + return info lines = output.split('\n') expr = re.compile('^Device') # discard header... @@ -1236,13 +1239,11 @@ def _mount_host_disk(self, config): for disk in disks: if disk in self.current or root_part: continue - try: - part_info = get_disk_info('/dev/{}'.format(disk)) - except: - continue - root_part = self._get_part(part_info, - 'Linux root', - self.target_dir) + part_info = get_disk_info('/dev/{}'.format(disk)) + if part_info["partitions"]: + root_part = self._get_part(part_info, + 'Linux root', + self.target_dir) # only look for a boot partition on the same disk as the root # partition and only if a root partition is found if root_part: