Detect running 7zip on a currupted iso as well as the lack of 7z

executable.
Remove repeated call to _7zip.list_iso(iso_link)
Adjusted line breaking to fit within 80 columns.
pull/300/head
Shinji Suzuki 6 years ago
parent 03077403d2
commit d75642ac62

@ -61,7 +61,7 @@ def extract_iso(src, dst, pattern=None, suppress_out=True):
subprocess.call(_cmd, stdin=devnull, stdout=devnull, stderr=devnull, shell=True) subprocess.call(_cmd, stdin=devnull, stdout=devnull, stderr=devnull, shell=True)
def list_iso(iso_link, suppress_out=True): def list_iso(iso_link, suppress_out=True, expose_exception=False):
""" """
List the content of ISO files. It does'nt work with non 'utf' characters (simply ignores them). List the content of ISO files. It does'nt work with non 'utf' characters (simply ignores them).
:param iso_link:Path to ISO link :param iso_link:Path to ISO link
@ -85,6 +85,8 @@ def list_iso(iso_link, suppress_out=True):
shell=True).decode('utf-8', 'ignore').splitlines() shell=True).decode('utf-8', 'ignore').splitlines()
except Exception as e: except Exception as e:
gen.log(e) gen.log(e)
if expose_exception:
raise
_cmd_out = '' _cmd_out = ''
for line in _cmd_out: for line in _cmd_out:
if '...' in line: if '...' in line:

@ -15,7 +15,7 @@ from .gen import *
from . import _7zip from . import _7zip
def distro(iso_cfg_ext_dir, iso_link): def distro(iso_cfg_ext_dir, iso_link, expose_exception=False):
""" """
Detect if distro is supported by multibootusb. Detect if distro is supported by multibootusb.
:param iso_cfg_ext_dir: Directory where *.cfg files are extracted. :param iso_cfg_ext_dir: Directory where *.cfg files are extracted.
@ -23,7 +23,7 @@ def distro(iso_cfg_ext_dir, iso_link):
""" """
# iso9660fs = ISO9660(iso_link) # iso9660fs = ISO9660(iso_link)
# iso_file_list = iso9660fs.readDir("/") # iso_file_list = iso9660fs.readDir("/")
iso_file_list = _7zip.list_iso(iso_link) iso_file_list = _7zip.list_iso(iso_link, expose_exception=expose_exception)
if platform.system() == "Linux" or platform.system() == "Windows": if platform.system() == "Linux" or platform.system() == "Windows":
for path, subdirs, files in os.walk(iso_cfg_ext_dir): for path, subdirs, files in os.walk(iso_cfg_ext_dir):
for name in files: for name in files:
@ -146,7 +146,7 @@ def distro(iso_cfg_ext_dir, iso_link):
elif re.search(r'BOOT_IMAGE=insert', string, re.I): elif re.search(r'BOOT_IMAGE=insert', string, re.I):
return 'insert' return 'insert'
distro = detect_iso_from_file_list(iso_link) distro = detect_iso_from_file_list(iso_link, iso_file_list)
if distro: if distro:
return distro return distro
@ -166,13 +166,12 @@ def distro(iso_cfg_ext_dir, iso_link):
return None return None
def detect_iso_from_file_list(iso_link): def detect_iso_from_file_list(iso_link, iso_file_list):
""" """
Fallback detection script from the content of an ISO. Fallback detection script from the content of an ISO.
:return: supported distro as string :return: supported distro as string
""" """
if os.path.exists(iso_link): if os.path.exists(iso_link):
iso_file_list = _7zip.list_iso(iso_link)
if any("sources" in s.lower() for s in iso_file_list) and any("boot.wim" in s.lower() for s in iso_file_list): if any("sources" in s.lower() for s in iso_file_list) and any("boot.wim" in s.lower() for s in iso_file_list):
return "Windows" return "Windows"
elif any("config.isoclient" in s.lower() for s in iso_file_list): elif any("config.isoclient" in s.lower() for s in iso_file_list):

@ -208,14 +208,16 @@ Are you SURE you want to enable it?",
def browse_iso(self): def browse_iso(self):
if str(self.ui.image_path.text()): if str(self.ui.image_path.text()):
self.ui.image_path.clear() self.ui.image_path.clear()
preference_file_path = os.path.join(multibootusb_host_dir(), "preference", "iso_dir.txt") preference_file_path = os.path.join(multibootusb_host_dir(),
"preference", "iso_dir.txt")
dir_path = '' dir_path = ''
if os.path.exists(preference_file_path): if os.path.exists(preference_file_path):
dir_path = open(preference_file_path, 'r').read() dir_path = open(preference_file_path, 'r').read()
config.image_path = QtWidgets.QFileDialog.getOpenFileName(self, 'Select an iso...', dir_path, config.image_path = QtWidgets.QFileDialog.getOpenFileName(
'ISO Files (*.iso);; Zip Files(*.zip);; ' self, 'Select an iso...', dir_path,
'Img Files(*.img);; All Files(*.*)')[0] 'ISO Files (*.iso);; Zip Files(*.zip);; '
'Img Files(*.img);; All Files(*.*)')[0]
if config.image_path: if config.image_path:
# sanity checks # sanity checks
@ -223,20 +225,38 @@ Are you SURE you want to enable it?",
QtWidgets.QMessageBox.critical( QtWidgets.QMessageBox.critical(
self, self,
"ISO Not readable", "ISO Not readable",
"Sorry, the file \"{0}\" is not readable.".format(config.image_path) "Sorry, the file \"{0}\" is not readable.".format(
config.image_path)
) )
return return
if iso_size(config.image_path) == 0: if iso_size(config.image_path) == 0:
QtWidgets.QMessageBox.critical( QtWidgets.QMessageBox.critical(
self, self,
"ISO is an empty file", "ISO is an empty file",
"Sorry, the file \"{0}\" contains no data.".format(config.image_path) "Sorry, the file \"{0}\" contains no data.".format(
config.image_path)
) )
return return
default_dir_path = os.path.dirname(config.image_path) default_dir_path = os.path.dirname(config.image_path)
gen.write_to_file(preference_file_path, default_dir_path) gen.write_to_file(preference_file_path, default_dir_path)
# Detect supported distro
try:
clean_iso_cfg_ext_dir( # Need to be cleaned.
os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir"))
extract_cfg_file(config.image_path)
config.distro = distro(iso_cfg_ext_dir(), config.image_path,
expose_exception=True)
except Exception as exc:
QtWidgets.QMessageBox.critical(
self,
"Failure to detect distro type",
'Sorry, failed in examining "{0}" to detect distro type '
'due to the following reason.\n\n"{1}".'
.format(config.image_path, exc)
)
return
if platform.system() == "Windows": if platform.system() == "Windows":
if "/" in config.image_path: if "/" in config.image_path:
config.image_path = config.image_path.strip().replace("/", "\\") config.image_path = config.image_path.strip().replace("/", "\\")
@ -248,9 +268,6 @@ Are you SURE you want to enable it?",
self.ui.label_image_bootable_value.setVisible(True) self.ui.label_image_bootable_value.setVisible(True)
if os.path.exists(config.image_path): if os.path.exists(config.image_path):
clean_iso_cfg_ext_dir(os.path.join(multibootusb_host_dir(), "iso_cfg_ext_dir")) # Need to be cleaned.
extract_cfg_file(config.image_path)
config.distro = distro(iso_cfg_ext_dir(), config.image_path) # Detect supported distro
self.ui.label_image_type_value.setText(str(config.distro)) self.ui.label_image_type_value.setText(str(config.distro))
self.ui.label_image_type_value.setVisible(True) self.ui.label_image_type_value.setVisible(True)
if config.distro: if config.distro:

Loading…
Cancel
Save