- templates: Fixed UTF-8 handling in replace command

- templates: Added iconv command to convert from UTF-8 to another encoding
- remove libreport-rhel-anaconda-bugzilla depend
i8-beta changed/i8-beta/lorax-28.14.71-1.el8.inferit
Arkady L. Shane 8 months ago
parent f72c613048
commit 3ac2bd3f7f
Signed by: tigro
GPG Key ID: 1EC08A25C9DB2503

@ -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

@ -4,7 +4,7 @@
Name: lorax
Version: 28.14.71
Release: 1%{?dist}
Release: 1%{?dist}.inferit
Summary: Tool for creating the anaconda install images
Group: Applications/System
@ -16,6 +16,9 @@ URL: https://github.com/weldr/lorax
# tito build --tgz
Source0: %{name}-%{version}.tar.gz
Patch1: 0001-Fix-replace-command-utf8-handling.patch
Patch2: 0002-Add-iconv-template-command.patch
BuildRequires: python3-devel
Requires: lorax-templates
@ -177,6 +180,7 @@ build images, etc. from the command line.
%prep
%autosetup -p1 -n %{name}-%{version}
sed -i '/libreport-rhel-anaconda-bugzilla/d' share/templates.d/99-generic/runtime-install.tmpl
%build
@ -261,6 +265,11 @@ getent passwd weldr >/dev/null 2>&1 || useradd -r -g weldr -d / -s /sbin/nologin
%{_mandir}/man1/composer-cli.1*
%changelog
* Fri Apr 19 2024 Arkady L. Shane <tigro@msvsphere-os.ru> - 28.14.71-1.inferit
- templates: Fixed UTF-8 handling in replace command
- templates: Added iconv command to convert from UTF-8 to another encoding
- remove libreport-rhel-anaconda-bugzilla depend
* Fri Mar 29 2024 MSVSphere Packaging Team <packager@msvsphere-os.ru> - 28.14.71-1
- Rebuilt for MSVSphere 8.10 beta

Loading…
Cancel
Save