[elbe-devel] [PATCH 04/19] elbepack: drop init_template_dir

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue Mar 19 08:47:33 CET 2024


Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/init.py | 15 ++++++++++-----
 elbepack/directories.py   |  1 -
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 295cc7a65c25..ded827d1c9b9 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 # SPDX-FileCopyrightText: 2014-2015, 2017, 2018 Linutronix GmbH
 
+import importlib.resources
 import logging
 import os
 import shutil
@@ -9,9 +10,10 @@ import subprocess
 import sys
 from optparse import OptionParser
 
+import elbepack.init
 from elbepack.config import cfg
 from elbepack.debinstaller import NoKinitrdException, copy_kinitrd
-from elbepack.directories import elbe_dir, init_template_dir
+from elbepack.directories import elbe_dir
 from elbepack.filesystem import Filesystem
 from elbepack.log import elbe_logging
 from elbepack.shellhelper import do, system
@@ -194,13 +196,16 @@ def run_command(argv):
             ('default-init.xml', out_path, False, False),
         ]
 
+        template_dir = importlib.resources.files(elbepack.init)
+
         for t, out_dir, make_executable, linebreak in templates:
             o = t.replace('.mako', '')
 
-            write_template(
-                os.path.join(out_dir, o),
-                os.path.join(init_template_dir, t), d, linebreak=linebreak,
-            )
+            with importlib.resources.as_file(template_dir / t) as template:
+                write_template(
+                    os.path.join(out_dir, o),
+                    template, d, linebreak=linebreak,
+                )
 
             if make_executable:
                 os.chmod(os.path.join(out_dir, o), 0o755)
diff --git a/elbepack/directories.py b/elbepack/directories.py
index 2501ff6e21af..76d65e328afe 100644
--- a/elbepack/directories.py
+++ b/elbepack/directories.py
@@ -22,7 +22,6 @@ def get_cmdlist():
 
 pack_dir = elbepack.__path__[0]
 
-init_template_dir = os.path.join(pack_dir, 'init')
 mako_template_dir = os.path.join(pack_dir, 'makofiles')
 
 default_preseed_fname = os.path.join(pack_dir, 'default-preseed.xml')

-- 
2.44.0



More information about the elbe-devel mailing list