[elbe-devel] [PATCH 2/8] elbepack: repomanager: switch to non-shell syntax

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed May 15 13:32:18 CEST 2024


The shell syntax is error-prone and a mess of nested quoting syntax.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/cdroms.py      |  2 +-
 elbepack/isooptions.py  |  4 +--
 elbepack/repomanager.py | 65 ++++++++++++++++++++-----------------------------
 3 files changed, 30 insertions(+), 41 deletions(-)

diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index 143409a5b62d..ceec8535ab56 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -113,7 +113,7 @@ def mk_source_cdrom(components, codename,
                             logging.warning("The src-cdrom archive's volume value "
                                             'is not contained in the actual volumes')
     else:
-        options = ''
+        options = []
 
     return [(repo.buildiso(os.path.join(target, f'src-cdrom-{component}.iso'),
             options=options)) for component, repo in repos.items()]
diff --git a/elbepack/isooptions.py b/elbepack/isooptions.py
index 732d0b4f07be..1bb5c0bd3d69 100644
--- a/elbepack/isooptions.py
+++ b/elbepack/isooptions.py
@@ -39,7 +39,7 @@ def get_iso_options(xml):
     options = []
     src_opts = xml.node('src-cdrom/src-opts')
     if src_opts is None:
-        return ''
+        return options
     for node in src_opts:
         if node.tag not in iso_options:
             continue
@@ -47,4 +47,4 @@ def get_iso_options(xml):
         logging.info('Adding option %s\n%s', node.tag, option[2])
         text = node.et.text[:option[1]]
         options.append('%s "%s"' % (option[0], text.replace('"', '\\"')))
-    return ' '.join(options)
+    return options
diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index 94f3d49e3fcf..ddaa19cd4477 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -165,17 +165,17 @@ class RepoBase:
         export_key(self.keyid, self.volume / 'repo.pub')
 
         if need_update:
-            cmd = f'reprepro --export=force --basedir "{self.volume}" update'
-            do(cmd, env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
+            do(['reprepro', '--export=force', '--basedir', self.volume, 'update'],
+               env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
         else:
             for att in self.attrs:
-                do(f'reprepro --basedir "{self.volume}" export {att.codename}',
+                do(['reprepro', '--basedir', self.volume, 'export', att.codename],
                    env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
 
     def finalize(self):
         for att in self.attrs:
-            cmd = f'reprepro --basedir "{self.volume}" export {att.codename}'
-            do(cmd, env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
+            do(['reprepro', '--basedir', self.volume, 'export', att.codename],
+               env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
 
     def _includedeb(self, path, codename, components=None, prio=None):
         if self.maxsize:
@@ -185,20 +185,18 @@ class RepoBase:
 
         global_opt = ['--keepunreferencedfiles',
                       '--export=silent-never',
-                      f'--basedir "{self.volume}"']
+                      '--basedir', self.volume]
 
         if prio is not None:
-            global_opt.append(f'--priority {prio}')
+            global_opt.extend(['--priority', prio])
 
         if components is not None:
             # Compatibility with old callers
             if isinstance(components, str):
                 components = [components]
-            global_opt.append(f'--component "{"|".join(components)}"')
+            global_opt.extend(['--component', '|'.join(components)])
 
-        global_opt = ' '.join(global_opt)
-
-        do(f'reprepro {global_opt} includedeb {codename} {path}')
+        do(['reprepro', *global_opt, 'includedeb', codename, path])
 
     def includedeb(self, path, components=None, pkgname=None, force=False, prio=None):
         # pkgname needs only to be specified if force is enabled
@@ -226,33 +224,29 @@ class RepoBase:
                       '--ignore=surprisingbinary',
                       '--keepunreferencedfiles',
                       '--export=silent-never',
-                      f'--basedir "{self.volume}"',
-                      '--priority normal',
-                      '--section misc']
+                      '--basedir', self.volume,
+                      '--priority', 'normal',
+                      '--section', 'misc']
 
         if components is not None:
             # Compatibility with old callers
             if isinstance(components, str):
                 components = [components]
-            global_opt.append(f'--component "{"|".join(components)}"')
-
-        global_opt = ' '.join(global_opt)
+            global_opt.extend(['--component', '|'.join(components)])
 
-        do(f'reprepro {global_opt} include {codename} {path}')
+        do(['reprepro', *global_opt, 'include', codename, path])
 
     def _removedeb(self, pkgname, codename, components=None):
 
-        global_opt = [f'--basedir "{self.volume}"']
+        global_opt = ['--basedir', self.volume]
 
         if components is not None:
             # Compatibility with old callers
             if isinstance(components, str):
                 components = [components]
-            global_opt.append(f'--component "{"|".join(components)}"')
-
-        global_opt = ' '.join(global_opt)
+            global_opt.extend(['--component', '|'.join(components)])
 
-        do(f'reprepro {global_opt} remove {codename} {pkgname}',
+        do(['reprepro', *global_opt, 'remove', codename, pkgname],
            env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
 
     def removedeb(self, pkgname, components=None):
@@ -260,11 +254,9 @@ class RepoBase:
 
     def _removesrc(self, srcname, codename):
 
-        global_opt = [f'--basedir {self.volume}']
+        global_opt = ['--basedir', self.volume]
 
-        global_opt = ' '.join(global_opt)
-
-        do(f'reprepro {global_opt} removesrc {codename} {srcname}',
+        do(['reprepro', *global_opt, 'removesrc', codename, srcname],
            env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
 
     def removesrc(self, path):
@@ -297,19 +289,17 @@ class RepoBase:
         global_opt = ['--keepunreferencedfiles',
                       '--keepunusednewfiles',
                       '--export=silent-never',
-                      f'--basedir "{self.volume}"',
-                      '--priority normal',
-                      '--section misc']
+                      '--basedir', self.volume,
+                      '--priority', 'normal',
+                      '--section', 'misc']
 
         if components is not None:
             # Compatibility with old callers
             if isinstance(components, str):
                 components = [components]
-            global_opt.append(f'--component "{"|".join(components)}"')
-
-        global_opt = ' '.join(global_opt)
+            global_opt.extend(['--component', '|'.join(components)])
 
-        do(f'reprepro {global_opt} includedsc {codename} {path}')
+        do(['reprepro', *global_opt, 'includedsc', codename, path])
 
     def includedsc(self, path, components=None, force=False):
         try:
@@ -337,17 +327,16 @@ class RepoBase:
     def include_init_dsc(self, path, components=None):
         self._includedsc(path, self.init_attr.codename, components)
 
-    def buildiso(self, fname, options=''):
+    def buildiso(self, fname, options=[]):
         files = []
         if self.volume_count == 0:
-            do(f'genisoimage {options} -o {fname} -J -joliet-long -R "{self.volume}"')
+            do(['genisoimage', *options, '-o', fname, '-J', '-joliet-long', '-R', self.volume])
             files.append(fname)
         else:
             for i in self.volume_indexes:
                 vol = self.get_volume_path(i)
                 newname = fname + (f'{i:02}')
-                do(f'genisoimage {options} -o {newname} -J -joliet-long '
-                   f'-R {vol}')
+                do(['genisoimage', *options, '-o', newname, '-J', '-joliet-long', '-R', vol])
                 files.append(newname)
 
         return files

-- 
2.45.0



More information about the elbe-devel mailing list