rpmlint/subprocess-support.diff

53 lines
1.5 KiB
Diff

--- Pkg.py
+++ Pkg.py
@@ -13,13 +13,18 @@ import rpm
import os.path
import stat
import commands
-import popen2
import re
import string
import tempfile
import types
import sys
+# popen2 is deprecated with 2.6 and newer
+if sys.version_info[0] > 2 or sys.version_info[1] >= 4:
+ import subprocess
+else:
+ import popen2
+
from Filter import printWarning
RPMFILE_CONFIG=(1 << 0)
@@ -93,13 +98,23 @@ def substitute_shell_vars(val, script):
def getstatusoutput(cmd, stdoutonly=0):
'''A version of commands.getstatusoutput() which can take cmd as a
sequence, thus making it potentially more secure. See popen2.'''
- if stdoutonly:
- proc = popen2.Popen3(cmd)
+ if sys.version_info[0] > 2 or sys.version_info[1] >= 4:
+ if stdoutonly:
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
+ else:
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
+
+ text = proc.stdout.read()
+ sts = proc.wait()
else:
- proc = popen2.Popen4(cmd)
- proc.tochild.close()
- text = proc.fromchild.read()
- sts = proc.wait()
+ if stdoutonly:
+ proc = popen2.Popen3(cmd)
+ else:
+ proc = popen2.Popen4(cmd)
+ proc.tochild.close()
+ text = proc.fromchild.read()
+ sts = proc.wait()
+
if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text