[elbe-devel] [PATCH v2 44/75] efilesystem: use f-strings

Daniel Braunwarth daniel at braunwarth.dev
Wed Nov 2 20:14:26 CET 2022


Signed-off-by: Daniel Braunwarth <daniel at braunwarth.dev>
---
 elbepack/efilesystem.py | 68 ++++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index d8a52c0f3..b6e01572b 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -85,8 +85,9 @@ def copy_filelist(src, file_lst, dst):
 
         else:
             try:
-                system('cp -a --reflink=auto "%s" "%s"' % (src.realpath(f),
-                                                           dst.realpath(f)))
+                system(
+                    'cp -a --reflink=auto '
+                    f'"{src.realpath(f)}" "{dst.realpath(f)}"')
             except CommandError as E:
                 logging.warning("Error while copying from %s to %s of file %s - %s",
                                 src.path, dst.path, f, E)
@@ -120,15 +121,12 @@ def extract_target(src, xml, dst, cache):
 
         file_list = []
         for line in pkglist:
-            file_list += src.cat_file("var/lib/dpkg/info/%s.list" % (line))
-            file_list += src.cat_file("var/lib/dpkg/info/%s.conffiles" %
-                                      (line))
+            file_list += src.cat_file(f"var/lib/dpkg/info/{line}.list")
+            file_list += src.cat_file(f"var/lib/dpkg/info/{line}.conffiles")
 
-            file_list += src.cat_file("var/lib/dpkg/info/%s:%s.list" %
-                                      (line, arch))
+            file_list += src.cat_file(f"var/lib/dpkg/info/{line}:{arch}.list")
             file_list += src.cat_file(
-                "var/lib/dpkg/info/%s:%s.conffiles" %
-                (line, arch))
+                f"var/lib/dpkg/info/{line}:{arch}.conffiles")
 
         file_list = sorted(set(file_list),
                            key = lambda k: k[4:] if k.startswith('/usr') else k)
@@ -158,20 +156,20 @@ def extract_target(src, xml, dst, cache):
 
         with open(dst.fname(psel), 'w+') as f:
             for item in pkglist:
-                f.write("%s  install\n" % item)
+                f.write(f"{item}  install\n")
 
         host_arch = get_command_out("dpkg --print-architecture").strip()
         if xml.is_cross(host_arch):
             ui = "/usr/share/elbe/qemu-elbe/" + str(xml.defs["userinterpr"])
             if not os.path.exists(ui):
                 ui = "/usr/bin/" + str(xml.defs["userinterpr"])
-            do('cp %s %s' % (ui, dst.fname("usr/bin")))
+            do(f"cp {ui} {dst.fname('usr/bin')}")
 
         cmds = ["--clear-selections",
-                "--set-selections < %s" % dst.fname(psel),
+                f"--set-selections < {dst.fname(psel)}",
                 "--purge -a"]
         for cmd in cmds:
-            chroot(dst.path, "/usr/bin/dpkg %s" % cmd)
+            chroot(dst.path, f"/usr/bin/dpkg {cmd}")
 
 
 class ElbeFilesystem(Filesystem):
@@ -180,8 +178,8 @@ class ElbeFilesystem(Filesystem):
 
     def dump_elbeversion(self, xml):
         f = self.open("etc/elbe_version", "w+")
-        f.write("%s %s\n" % (xml.prj.text("name"), xml.prj.text("version")))
-        f.write("this RFS was generated by elbe %s\n" % (elbe_version))
+        f.write(f"{xml.prj.text('name')} {xml.prj.text('version')}\n")
+        f.write(f"this RFS was generated by elbe {elbe_version}\n")
         f.write(time.strftime("%c\n"))
         f.close()
 
@@ -206,8 +204,8 @@ class ElbeFilesystem(Filesystem):
             except IOError as e:
                 logging.exception("Error while processing license file %s",
                                   copyright_fname)
-                lic_text = u"Error while processing license file %s: '%s'" % (
-                    copyright_file, e.strerror)
+                lic_text = (f"Error while processing license file "
+                            f"{copyright_file}: '{e.strerror}'")
             # in Python2 'pkg' is a binary string whereas in Python3 it is a
             # unicode string. So make sure that pkg ends up as a unicode string
             # in both Python2 and Python3.
@@ -215,11 +213,11 @@ class ElbeFilesystem(Filesystem):
 
             if f is not None:
                 f.write(pkg)
-                f.write(u":\n======================================"
+                f.write(":\n======================================"
                         "==========================================")
-                f.write(u"\n")
+                f.write("\n")
                 f.write(lic_text)
-                f.write(u"\n\n")
+                f.write("\n\n")
 
             if xml_fname is not None:
                 licence_xml.add_copyright_file(pkg, lic_text)
@@ -263,18 +261,18 @@ class Excursion:
         self.dst = dst
 
     def _saved_to(self):
-        return "%s.orig" % self.origin
+        return f"{self.origin}.orig"
 
     def _do_excursion(self, rfs):
         if rfs.lexists(self.origin) and self.restore is True:
             save_to = self._saved_to()
-            system('mv %s %s' % (rfs.fname(self.origin), rfs.fname(save_to)))
+            system(f"mv {rfs.fname(self.origin)} {rfs.fname(save_to)}")
         if os.path.exists(self.origin):
             if self.dst is not None:
                 dst = self.dst
             else:
                 dst = self.origin
-            system('cp %s %s' % (self.origin, rfs.fname(dst)))
+            system(f"cp {self.origin} {rfs.fname(dst)}")
 
     # This should be a method of rfs
     @staticmethod
@@ -283,13 +281,13 @@ class Excursion:
             flags = "-f"
             if rfs.isdir(filename):
                 flags += "r"
-            system("rm %s %s" % (flags, rfs.fname(filename)))
+            system(f"rm {flags} {rfs.fname(filename)}")
 
     def _undo_excursion(self, rfs):
         saved_to = self._saved_to()
         self._del_rfs_file(self.origin, rfs)
         if self.restore is True and rfs.lexists(saved_to):
-            system('mv %s %s' % (rfs.fname(saved_to), rfs.fname(self.origin)))
+            system(f"mv {rfs.fname(saved_to)} {rfs.fname(self.origin)}")
 
 
 class ChRootFilesystem(ElbeFilesystem):
@@ -345,10 +343,10 @@ class ChRootFilesystem(ElbeFilesystem):
         if self.path == '/':
             return
         try:
-            system("mount -t proc none %s/proc" % self.path)
-            system("mount -t sysfs none %s/sys" % self.path)
-            system("mount -o bind /dev %s/dev" % self.path)
-            system("mount -o bind /dev/pts %s/dev/pts" % self.path)
+            system(f"mount -t proc none {self.path}/proc")
+            system(f"mount -t sysfs none {self.path}/sys")
+            system(f"mount -o bind /dev {self.path}/dev")
+            system(f"mount -o bind /dev/pts {self.path}/dev/pts")
         except BaseException:
             self.umount()
             raise
@@ -371,7 +369,7 @@ class ChRootFilesystem(ElbeFilesystem):
     def _umount(self, path):
         path = os.path.join(self.path, path)
         if os.path.ismount(path):
-            system("umount %s" % path)
+            system(f"umount {path}")
 
     def umount(self):
         if self.path == '/':
@@ -455,8 +453,9 @@ class TargetFs(ChRootFilesystem):
             cpio_name = self.xml.text("target/package/cpio/name")
             os.chdir(self.fname(''))
             try:
-                do("find . -print | cpio -ov -H newc >%s" %
-                   os.path.join(targetdir, cpio_name))
+                do(
+                    f"find . -print | cpio -ov -H newc >"
+                    f"{os.path.join(targetdir, cpio_name)}")
                 # only append filename if creating cpio was successful
                 self.images.append(cpio_name)
             except CommandError:
@@ -473,8 +472,9 @@ class TargetFs(ChRootFilesystem):
                 if self.xml.has("target/package/squashfs/options"):
                     options = self.xml.text("target/package/squashfs/options")
 
-                do("mksquashfs %s %s/%s -noappend -no-progress %s" %
-                   (self.fname(''), targetdir, sfs_name, options))
+                do(
+                    f"mksquashfs {self.fname('')} {targetdir}/{sfs_name} "
+                    f"-noappend -no-progress {options}")
                 # only append filename if creating mksquashfs was successful
                 self.images.append(sfs_name)
             except CommandError:
-- 
2.38.1



More information about the elbe-devel mailing list