You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pungi/SOURCES/0001-Add-charset-detection-...

51 lines
1.9 KiB

From df408e43ace861fdc2c016aca002bc2e23232837 Mon Sep 17 00:00:00 2001
From: Eugene Zamriy <evgeniy.zamriy@softline.com>
Date: Thu, 27 Jul 2023 23:48:40 +0300
Subject: [PATCH] Add charset detection to tweak_configs
This patch is required for making Pungi work with isolinux.cfg
files in cp866 encoding.
---
pungi/phases/buildinstall.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py
index 354c47a..a6efc59 100644
--- a/pungi/phases/buildinstall.py
+++ b/pungi/phases/buildinstall.py
@@ -22,6 +22,7 @@ import re
from six.moves import cPickle as pickle
from copy import copy
+import chardet
from kobo.threads import ThreadPool, WorkerThread
from kobo.shortcuts import run, force_list
import kobo.rpmlib
@@ -383,8 +384,10 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS, logger=None):
if not os.path.exists(config_path):
continue
- with open(config_path, "r") as f:
- data = original_data = f.read()
+ with open(config_path, "rb") as f:
+ byte_data = f.read()
+ encoding = chardet.detect(byte_data)["encoding"]
+ data = original_data = byte_data.decode(encoding)
os.unlink(config_path) # break hadlink by removing file writing a new one
# double-escape volid in yaboot.conf
@@ -398,8 +401,8 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS, logger=None):
data = re.sub(r":LABEL=[^ \n]*", r":LABEL=%s%s" % (new_volid, ks), data)
data = re.sub(r"(search .* -l) '[^'\n]*'", r"\1 '%s'" % volid, data)
- with open(config_path, "w") as f:
- f.write(data)
+ with open(config_path, "wb") as f:
+ f.write(data.encode(encoding))
if data != original_data:
found_configs.append(config)
--
2.41.0