Patchwork [2/4] scripts: replace os.system with subprocess.call

login
register
mail settings
Submitter Robert Yang
Date May 29, 2012, 2:53 p.m.
Message ID <a32f1f619d2d181d166b99eda05e267e57048eef.1338302685.git.liezhi.yang@windriver.com>
Download mbox | patch
Permalink /patch/28889/
State Accepted
Commit 57f843146ed62c04c23bc380dc8cb38aba264f1c
Headers show

Comments

Robert Yang - May 29, 2012, 2:53 p.m.
Replace os.system with subprocess.call since the older function would
fail (more or less) silently if the executed program cannot be found

More info:
http://docs.python.org/library/subprocess.html#subprocess-replacements

[YOCTO #2454]

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 scripts/rpm-createsolvedb.py  |    5 +++--
 scripts/swabber-strace-attach |    3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

Patch

diff --git a/scripts/rpm-createsolvedb.py b/scripts/rpm-createsolvedb.py
index 0d5f219..a5b61ba 100755
--- a/scripts/rpm-createsolvedb.py
+++ b/scripts/rpm-createsolvedb.py
@@ -14,6 +14,7 @@ 
 import sys, os
 import hashlib
 import stat
+import subprocess
 
 if len(sys.argv) < 1:
     print("Error, rpm command not specified")
@@ -44,7 +45,7 @@  for path in paths:
         continue
 
     if os.path.exists(path + "/solvedb"):
-        os.system("rm -rf %s" % (path + "/solvedb"))
+        subprocess.call("rm -rf %s" % (path + "/solvedb"), shell=True)
     os.mkdir(path + "/solvedb")
     m = open(path + "/solvedb/manifest", "w")
     m.write("# Dynamically generated solve manifest\n")
@@ -56,7 +57,7 @@  for path in paths:
 			--noaid --nodeps --noorder --noscripts --notriggers --noparentdirs --nolinktos --stats \
 			--ignoresize --nosignature --nodigest -D "__dbi_txn create nofsync" \
 			' + path + '/solvedb/manifest'
-    os.system(cmd)
+    subprocess.call(cmd, shell=True)
 
     open(path + "/solvedb.checksum", "w").write(checksum)
     open(path + "/solvedb.done", "w")
diff --git a/scripts/swabber-strace-attach b/scripts/swabber-strace-attach
index d4f80e4..bb0391a 100755
--- a/scripts/swabber-strace-attach
+++ b/scripts/swabber-strace-attach
@@ -1,6 +1,7 @@ 
 #!/usr/bin/env python
 import os
 import sys
+import subprocess
 
 # Detach from the controlling terminal and parent process by forking twice to daemonize ourselves,
 # then run the command passed as argv[1]. Send log data to argv[2].
@@ -24,7 +25,7 @@  os.dup2(si.fileno(), sys.stdin.fileno())
 os.dup2(so.fileno(), sys.stdout.fileno())
 os.dup2(se.fileno(), sys.stderr.fileno())
 
-ret = os.system(sys.argv[1])
+ret = subprocess.call(sys.argv[1], shell=True)
 
 os._exit(ret)