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.
49 lines
1.6 KiB
49 lines
1.6 KiB
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
|
|
|