- templates: Added iconv command to convert from UTF-8 to another encoding - remove libreport-rhel-anaconda-bugzilla dependi8-beta changed/i8-beta/lorax-28.14.71-1.el8.inferit
parent
f72c613048
commit
3ac2bd3f7f
@ -0,0 +1,51 @@
|
|||||||
|
From fa48ddd7ca1d8a4f24f2e1de6880fd5bd6c770f5 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Eugene Zamriy <evgeniy.zamriy@softline.com>
|
||||||
|
Date: Wed, 26 Jul 2023 22:45:32 +0300
|
||||||
|
Subject: [PATCH 1/2] Fix replace command utf8 handling
|
||||||
|
|
||||||
|
This change allows using non-latin UTF-8 symbols in files modified
|
||||||
|
from Lorax templates using the "replace" command.
|
||||||
|
|
||||||
|
Note: fileinput.input doesn't support encoding argument in the
|
||||||
|
in-place mode, so we replaced it with StringIO.
|
||||||
|
---
|
||||||
|
src/pylorax/sysutils.py | 15 +++++++--------
|
||||||
|
1 file changed, 7 insertions(+), 8 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/pylorax/sysutils.py b/src/pylorax/sysutils.py
|
||||||
|
index 209757a..21b9698 100644
|
||||||
|
--- a/src/pylorax/sysutils.py
|
||||||
|
+++ b/src/pylorax/sysutils.py
|
||||||
|
@@ -25,7 +25,7 @@ __all__ = ["joinpaths", "touch", "replace", "chown_", "chmod_", "remove",
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
-import fileinput
|
||||||
|
+import io
|
||||||
|
import pwd
|
||||||
|
import grp
|
||||||
|
import glob
|
||||||
|
@@ -50,14 +50,13 @@ def touch(fname):
|
||||||
|
|
||||||
|
|
||||||
|
def replace(fname, find, sub):
|
||||||
|
- fin = fileinput.input(fname, inplace=1)
|
||||||
|
pattern = re.compile(find)
|
||||||
|
-
|
||||||
|
- for line in fin:
|
||||||
|
- line = pattern.sub(sub, line)
|
||||||
|
- sys.stdout.write(line)
|
||||||
|
-
|
||||||
|
- fin.close()
|
||||||
|
+ with open(fname, "r", encoding="utf-8") as fd:
|
||||||
|
+ fin = io.StringIO(fd.read())
|
||||||
|
+ with open(fname, "w", encoding="utf-8") as fd:
|
||||||
|
+ for line in fin:
|
||||||
|
+ line = pattern.sub(sub, line)
|
||||||
|
+ fd.write(line)
|
||||||
|
|
||||||
|
|
||||||
|
def chown_(path, user=None, group=None, recursive=False):
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
@ -0,0 +1,38 @@
|
|||||||
|
From 432c907e8f5d306611e84cd6fe56087362794f68 Mon Sep 17 00:00:00 2001
|
||||||
|
From: tigro <tigro@msvsphere-os.ru>
|
||||||
|
Date: Fri, 22 Dec 2023 13:06:59 +0300
|
||||||
|
Subject: [PATCH 2/2] Add iconv template command
|
||||||
|
|
||||||
|
---
|
||||||
|
src/pylorax/ltmpl.py | 15 +++++++++++++++
|
||||||
|
1 file changed, 15 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
|
||||||
|
index ccd297c..a06534a 100644
|
||||||
|
--- a/src/pylorax/ltmpl.py
|
||||||
|
+++ b/src/pylorax/ltmpl.py
|
||||||
|
@@ -275,6 +275,21 @@ class LoraxTemplateRunner(TemplateRunner):
|
||||||
|
for pkg in debug_pkgs:
|
||||||
|
f.write("%s\n" % pkg)
|
||||||
|
|
||||||
|
+ def iconv(self, encoding, *fileglobs):
|
||||||
|
+ '''
|
||||||
|
+ iconv ENCODING [FILEGLOB ...]
|
||||||
|
+ Convert given files from UTF-8 to a specified encoding.
|
||||||
|
+
|
||||||
|
+ Examples:
|
||||||
|
+ iconv 'cp866' ${BOOTDIR}/isolinux.cfg
|
||||||
|
+ '''
|
||||||
|
+ for g in fileglobs:
|
||||||
|
+ for f in rglob(self._out(g)):
|
||||||
|
+ with open(f, "r", encoding="utf-8") as fd:
|
||||||
|
+ content = fd.read()
|
||||||
|
+ with open(f, "wb") as fd:
|
||||||
|
+ fd.write(content.encode(encoding))
|
||||||
|
+
|
||||||
|
def install(self, srcglob, dest):
|
||||||
|
'''
|
||||||
|
install SRC DEST
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
Loading…
Reference in new issue