Add charset detection to tweak_configs

i8 changed/i8/pungi-4.1.38-1.el8.2.inferit
Arkady L. Shane 1 year ago
commit 7f25c81e3f
Signed by: tigro
GPG Key ID: 1EC08A25C9DB2503

1
.gitignore vendored

@ -0,0 +1 @@
SOURCES/pungi-4.1.38.tar.bz2

@ -0,0 +1 @@
9fe83327acf4c7233db6dcd6d108ff466ca924b1 SOURCES/pungi-4.1.38.tar.bz2

@ -0,0 +1,48 @@
From a90340decd367296c58d7339ab235f2955e5f5cb Mon Sep 17 00:00:00 2001
From: tigro <tigro@msvsphere-os.ru>
Date: Tue, 23 Jan 2024 12:53:16 +0300
Subject: [PATCH] Add charset detection to tweak_configs
---
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 e8feea0..706e960 100644
--- a/pungi/phases/buildinstall.py
+++ b/pungi/phases/buildinstall.py
@@ -19,6 +19,7 @@ import os
import time
import shutil
import re
+import chardet
from kobo.threads import ThreadPool, WorkerThread
from kobo.shortcuts import run
@@ -247,8 +248,10 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS):
continue
found_configs.append(config)
- with open(config_path, "r") as f:
- data = f.read()
+ with open(config_path, "rb") as f:
+ byte_data = f.read()
+ encoding = chardet.detect(byte_data)["encoding"]
+ data = byte_data.decode(encoding)
os.unlink(config_path) # break hadlink by removing file writing a new one
# double-escape volid in yaboot.conf
@@ -262,8 +265,8 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS):
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))
return found_configs
--
2.43.0

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save