[elbe-devel] [PATCH 08/13] Change os.sytem to call_check for "efilesystem.py"

dion at linutronix.de dion at linutronix.de
Mon Jun 24 12:48:48 CEST 2019


From: Olivier Dion <dion at linutronix.de>

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/efilesystem.py | 58 +++++++++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
index 1f6428e0..51ec1221 100644
--- a/elbepack/efilesystem.py
+++ b/elbepack/efilesystem.py
@@ -13,6 +13,8 @@ import subprocess
 import io
 import stat
 
+from subprocess import check_call
+
 from elbepack.asciidoclog import CommandError
 from elbepack.filesystem import Filesystem
 from elbepack.version import elbe_version
@@ -186,20 +188,24 @@ class ChRootFilesystem(ElbeFilesystem):
             ui = "/usr/share/elbe/qemu-elbe/" + self.interpreter
             if not os.path.exists(ui):
                 ui = "/usr/bin/" + self.interpreter
-            os.system('cp %s %s' % (ui, self.fname("usr/bin")))
+            check_call('cp %s %s' % (ui, self.fname("usr/bin")), shell=True)
 
         if self.exists("/etc/resolv.conf"):
-            os.system('mv %s %s' % (self.fname("etc/resolv.conf"),
-                                    self.fname("etc/resolv.conf.orig")))
-        os.system('cp %s %s' % ("/etc/resolv.conf",
-                                self.fname("etc/resolv.conf")))
+            check_call('mv %s %s' % (self.fname("etc/resolv.conf"),
+                                     self.fname("etc/resolv.conf.orig")),
+                       shell=True)
+        check_call('cp %s %s' % ("/etc/resolv.conf",
+                                 self.fname("etc/resolv.conf")),
+                   shell=True)
 
         if self.exists("/etc/apt/apt.conf"):
-            os.system('cp %s %s' % (self.fname("/etc/apt/apt.conf"),
-                                    self.fname("/etc/apt/apt.conf.orig")))
+            check_call('cp %s %s' % (self.fname("/etc/apt/apt.conf"),
+                                     self.fname("/etc/apt/apt.conf.orig")),
+                       shell=True)
         if os.path.exists("/etc/apt/apt.conf"):
-            os.system('cp %s %s' % ("/etc/apt/apt.conf",
-                                    self.fname("/etc/apt/")))
+            check_call('cp %s %s' % ("/etc/apt/apt.conf",
+                                     self.fname("/etc/apt/")),
+                       shell=True)
 
         self.mkdir_p("usr/sbin")
         self.write_file("usr/sbin/policy-rc.d",
@@ -213,33 +219,39 @@ class ChRootFilesystem(ElbeFilesystem):
             self.leave_chroot()
         self.umount()
         if self.interpreter:
-            os.system('rm -f %s' %
-                      os.path.join(self.path, "usr/bin/" + self.interpreter))
+            check_call('rm -f %s' % os.path.join(self.path,
+                                                 "usr/bin/" + self.interpreter),
+                       shell=True)
 
-        os.system('rm -f %s' % (self.fname("etc/resolv.conf")))
+        check_call('rm -f %s' % (self.fname("etc/resolv.conf")),
+                   shell=True)
 
         if self.exists("/etc/resolv.conf.orig"):
-            os.system('mv %s %s' % (self.fname("etc/resolv.conf.orig"),
-                                    self.fname("etc/resolv.conf")))
+            check_call('mv %s %s' % (self.fname("etc/resolv.conf.orig"),
+                                     self.fname("etc/resolv.conf")),
+                       shell=True)
 
         if self.exists("/etc/apt/apt.conf"):
-            os.system('rm -f %s' % (self.fname("etc/apt/apt.conf")))
+            check_call('rm -f %s' % (self.fname("etc/apt/apt.conf")),
+                       shell=True)
 
         if self.exists("/etc/apt/apt.conf.orig"):
-            os.system('mv %s %s' % (self.fname("etc/apt/apt.conf.orig"),
-                                    self.fname("etc/apt/apt.conf")))
+            check_call('mv %s %s' % (self.fname("etc/apt/apt.conf.orig"),
+                                     self.fname("etc/apt/apt.conf")),
+                       shell=True)
 
         if self.exists("/usr/sbin/policy-rc.d"):
-            os.system('rm -f %s' % (self.fname("usr/sbin/policy-rc.d")))
+            check_call('rm -f %s' % (self.fname("usr/sbin/policy-rc.d")),
+                       shell=True)
 
     def mount(self):
         if self.path == '/':
             return
         try:
-            os.system("mount -t proc none %s/proc" % self.path)
-            os.system("mount -t sysfs none %s/sys" % self.path)
-            os.system("mount -o bind /dev %s/dev" % self.path)
-            os.system("mount -o bind /dev/pts %s/dev/pts" % self.path)
+            check_call("mount -t proc none %s/proc" % self.path, shell=True)
+            check_call("mount -t sysfs none %s/sys" % self.path, shell=True)
+            check_call("mount -o bind /dev %s/dev" % self.path, shell=True)
+            check_call("mount -o bind /dev/pts %s/dev/pts" % self.path, shell=True)
         except BaseException:
             self.umount()
             raise
@@ -261,7 +273,7 @@ class ChRootFilesystem(ElbeFilesystem):
 
     def _umount(self, path):
         if os.path.ismount(path):
-            os.system("umount %s" % path)
+            check_call("umount %s" % path, shell=True)
 
     def umount(self):
         if self.path == '/':
-- 
2.11.0




More information about the elbe-devel mailing list