Fix exception from opening utf-8 encoded text file under non-utf-8 locale

setting.
Update scanned text files only when desktop-image path was tweaked.
pull/319/head
Shinji Suzuki 6 years ago
parent 6cbb1b791f
commit 7e6aa856be

@ -374,7 +374,8 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0):
return
log("Probing '%s'!" % fname)
theme_file = os.path.join(dir_, fname)
with open(theme_file, 'r') as f:
updated = False
with open(theme_file, 'r', encoding='utf-8') as f:
lines = []
pattern = re.compile(r'^desktop-image\s*:\s*(.*)$')
for line in f.readlines():
@ -382,12 +383,14 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0):
m = pattern.match(line)
if m:
log("Updating '%s'" % line)
updated = True
partial_path = m.group(1).strip('"').lstrip('/')
line = 'desktop-image: "%s/%s"' % \
(install_dir_for_grub, partial_path)
lines.append(line)
with open(theme_file, 'w') as f:
f.write('\n'.join(lines))
if updated:
with open(theme_file, 'w') as f:
f.write('\n'.join(lines))
visitor_callbacks = [
# Ensure that isolinux.cfg file is copied as syslinux.cfg

Loading…
Cancel
Save