Merge pull request #318 from shinji-s/wifislax

Get salitaz-rolling rolling again.
pull/320/head
multibootusb 6 years ago committed by GitHub
commit 2f10191a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,6 +28,11 @@ def distro(iso_cfg_ext_dir, iso_link, expose_exception=False):
for path, subdirs, files in os.walk(iso_cfg_ext_dir):
for name in files:
if name.endswith(('.cfg', '.CFG', '.txt', '.TXT', '.lst')):
if name.lower()=='i18n.cfg':
# i18n.cfg in salitaz-rolling cause misdetection
# of centos by the following line.
# MENU LABEL English US (acentos)
continue
try:
# errors='ignore' is required as some files also contain non utf character
string = open(os.path.join(path, name), errors='ignore').read()

@ -195,26 +195,36 @@ def write_to_file(file_path, _strings):
gen.log('Error writing to %s...' % file_path)
def kernel_search_path(isolinux_dir):
return
def locate_kernel_file(subpath, isolinux_dir):
subpath_original = subpath
if subpath[0] != '/':
gen.log("Accepting a relative kernel/initrd path '%s' as is."
% subpath)
return subpath
if os.path.exists(os.path.join(config.usb_mount, subpath[1:])):
gen.log("Accepting kernel/initrd path '%s' as it exists." % subpath)
return subpath
_iso_basename = iso.iso_basename(config.image_path)
subpath = subpath[1:] # strip off the leading '/'
drive_relative_prefix = 'multibootusb/' + _iso_basename + '/'
if subpath.startswith(drive_relative_prefix):
# Paths is already drive-relative make it install-dir-relative.
subpath = subpath[len(drive_relative_prefix):]
gen.log("Trying to locate kernel/initrd file '%s'" % subpath)
for d in [
'',
os.path.join('multibootusb',
iso.iso_basename(config.image_path), isolinux_dir),
os.path.join('multibootusb', _iso_basename, isolinux_dir),
# Down below are dire attemps to find.
os.path.join('multibootusb',
iso.iso_basename(config.image_path)),
os.path.join('multibootusb',
iso.iso_basename(config.image_path), 'arch'),
os.path.join('multibootusb', _iso_basename),
os.path.join('multibootusb', _iso_basename, 'arch'),
]:
if os.path.exists(os.path.join(config.usb_mount, d, subpath)):
fullpath = os.path.join(config.usb_mount, d, subpath)
if os.path.exists(fullpath):
gen.log("Digged out '%s' at '%s'" % (subpath, fullpath))
unix_style_path = os.path.join(d, subpath).\
replace('\\', '/').\
lstrip('/')
return ('/' + unix_style_path)
return subpath
return subpath_original
def tweak_bootfile_path(img_file_spec, isolinux_dir):
@ -244,23 +254,26 @@ def tweak_bootfile_path(img_file_spec, isolinux_dir):
return ' '.join(img_file_spec.split(','))
def extract_initrd_param(value, isolinux_dir):
kernel_search_path = [
'',
os.path.join('multibootusb',
iso.iso_basename(config.image_path), isolinux_dir),
os.path.join('multibootusb', # A dire attemp to find.
iso.iso_basename(config.image_path)),
]
initrd_line, others = '', []
for paramdef in value.split(' '):
if not paramdef.lower().startswith('initrd='):
others.append(paramdef)
continue
paths = [locate_kernel_file(s, isolinux_dir) for s
in paramdef[len('initrd='):].split(',')]
initrd_line = 'initrd ' + ' '.join(paths)
return initrd_line, ' '.join(others)
def extract_initrd_params_and_fix_kernel(value, isolinux_dir):
initrd_line, others = '', []
tokens = value.split(' ')
tokens.reverse()
while 0<len(tokens):
token = tokens.pop()
if token=='linux':
# deal with 'append linux /boot/bzImage' in salitaz-rolling
if 0<len(tokens):
kernel_file = locate_kernel_file(tokens.pop(), isolinux_dir)
others.extend(['linux', kernel_file])
else:
others.append('linux')
elif token.startswith('initrd='):
paths = [locate_kernel_file(s, isolinux_dir) for s
in token[len('initrd='):].split(',')]
initrd_line = 'initrd ' + ' '.join(paths)
else:
others.append(token)
return initrd_line, ' '.join(others),
def iso2grub2(install_dir, loopback_cfg_path):
@ -370,15 +383,16 @@ def iso2grub2(install_dir, loopback_cfg_path):
initrd_line = 'initrd ' + \
tweak_bootfile_path(value, iso_bin_dir)
elif kw== 'append':
new_initrd_line, new_value = extract_initrd_param(
value, iso_bin_dir)
new_initrd_line, new_value \
= extract_initrd_params_and_fix_kernel(
value, iso_bin_dir)
appends.append(new_value)
if new_initrd_line:
if initrd_line:
gen.log("Warning: found more than one initrd "
"specifications in block '%s'."
% menu_label)
initrd_line = new_initrd_line
appends.append(new_value)
if menu_line in seen_menu_lines:
out_lines.append( "# '%s' is superceded by the previous "
@ -387,11 +401,12 @@ def iso2grub2(install_dir, loopback_cfg_path):
if linux_line or initrd_line:
seen_menu_lines.append(menu_line)
out_lines.append(menu_line + ' {')
for l, a in [
(linux_line, ' ' + ' '.join(appends)),
for starter, value in [
(linux_line, ' '.join(appends)),
(initrd_line, '')]:
if l:
out_lines.append(' ' + l + a)
vec = [x for x in [starter, value] if x]
if vec:
out_lines.append(' ' + ' '.join(vec))
out_lines.append( '}' )
else:
out_lines.append("# Avoided emitting an empty "

@ -0,0 +1,88 @@
from functools import reduce
import os
import sys
from unittest.mock import MagicMock, patch, sentinel
sys.path = ['..'] + sys.path
from scripts import config
from scripts import gen
from scripts import grub
from scripts import iso
class OpenMock:
def __init__(self, *args, **kw):
self.writes = []
def read(self):
return """LABEL core
MENU LABEL SliTaz core Live
COM32 c32box.c32
append linux /boot/bzImage initrd=/boot/rootfs4.gz,/boot/rootfs3.gz,/boot/rootfs2.gz,/boot/rootfs1.gz rw root=/dev/null video=-32 autologin
"""
def write(self, data):
self.writes.append(data)
def __enter__(self):
return self
def __exit__(self, *args):
pass
OPEN_MOCK = OpenMock()
def gen_log(obj):
print ('[*] %s' % obj)
def my_open(fname, mode, **kw):
return OPEN_MOCK
def iso_bin_dir(iso_image):
return 'isolinux'
def os_path_exists(f):
chunks = reduce(lambda accum, x : accum + x.split('/'), f.split('\\'), [])
if chunks[-1] in ['multibootusb.log', 'loopback.cfg']:
return True
if 'arch' in chunks:
return True
if chunks[1] in ['rootfs1.gz', 'rootfs2.gz']:
return True
if chunks == ['multibootusb', 'debian-sid', 'boot', 'rootfs4.gz']:
return True
return False
def os_walk(dirpath):
return [('isolinux', [], ['isolinux.cfg'])]
def test_iso2grub2():
gen_log_mock = MagicMock()
iso_bin_dir_mock = MagicMock()
os_walk_mock = MagicMock()
os_path_exists_mock = MagicMock()
open_mock = MagicMock()
@patch('scripts.gen.log', gen_log_mock)
@patch('scripts.iso.isolinux_bin_dir', iso_bin_dir_mock)
@patch('os.walk', os_walk)
@patch('os.path.exists', os_path_exists)
@patch('builtins.open', open_mock)
def _():
gen_log_mock.side_effect = gen_log
open_mock.side_effect = my_open
os_path_exists_mock.side_effect = os_path_exists
os_walk_mock.side_effect = os_walk
iso_bin_dir_mock.side_effect = iso_bin_dir
config.image_path = '/home/suzuki/Downloads/debian-sid.iso'
grub.iso2grub2('/tmp/mbusb/debian', 'loopback.cfg')
_()
assert ''.join(OPEN_MOCK.writes)=="""# Extracted from isolinux/isolinux.cfg
menuentry "SliTaz core Live" {
linux /multibootusb/debian-sid/arch/boot/bzImage rw root=/dev/null video=-32 autologin
initrd /multibootusb/debian-sid/boot/rootfs4.gz /multibootusb/debian-sid/arch/boot/rootfs3.gz /boot/rootfs2.gz /boot/rootfs1.gz
}
"""
print ("Test Passed.")
test_iso2grub2()
Loading…
Cancel
Save