Py3: Replace commands with subprocess calls in lsb_release.py.
authorDidier Raboud <odyx@debian.org>
Wed, 23 May 2012 09:18:18 +0000 (11:18 +0200)
committerDidier Raboud <odyx@debian.org>
Wed, 23 May 2012 12:56:48 +0000 (14:56 +0200)
Thanks-to: Nicolas Dandrimont <nicolas.dandrimont@crans.org>
Thanks-to: Jakub Wilk <jwilk@debian.org>
lsb_release.py

index d35f8b11483345bb4bc4e3fc342152e87e7a4d29..910ca0ec51afcf1d39c80cba618e67847d71d4e7 100644 (file)
@@ -21,7 +21,7 @@
 from __future__ import print_function
 
 import sys
-import commands
+import subprocess
 import os
 import re
 
@@ -125,7 +125,13 @@ except NameError:
 # This is Debian-specific at present
 def check_modules_installed():
     # Find which LSB modules are installed on this system
-    output = commands.getoutput("dpkg-query -f '${Version} ${Provides}\n' -W %s 2>/dev/null" % PACKAGES)
+    C_env = os.environ.copy(); C_env['LC_ALL'] = 'C'
+    output = subprocess.Popen(['dpkg-query','-f',"${Version} ${Provides}\n",'-W'] + PACKAGES.split(),
+                              env=C_env,
+                              stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE,
+                              close_fds=True).communicate()[0].decode('ascii')
+
     if not output:
         return []
 
@@ -184,7 +190,12 @@ def compare_release(x, y):
 def parse_apt_policy():
     data = []
     
-    policy = commands.getoutput('LANG=C apt-cache policy 2>/dev/null')
+    C_env = os.environ.copy(); C_env['LC_ALL'] = 'C'
+    policy = subprocess.Popen(['apt-cache','policy'],
+                              env=C_env,
+                              stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE,
+                              close_fds=True).communicate()[0].decode('ascii')
     for line in policy.split('\n'):
         line = line.strip()
         m = re.match(r'(-?\d+)', line)