From: Didier Raboud Date: Wed, 23 May 2012 09:18:18 +0000 (+0200) Subject: Py3: Replace commands with subprocess calls in lsb_release.py. X-Git-Tag: archive/raspbian/10.2018112800+rpi1^2~108 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=31af58326d117615982dc6a92920cda46be3c8f6;p=lsb.git Py3: Replace commands with subprocess calls in lsb_release.py. Thanks-to: Nicolas Dandrimont Thanks-to: Jakub Wilk --- diff --git a/lsb_release.py b/lsb_release.py index d35f8b1..910ca0e 100644 --- a/lsb_release.py +++ b/lsb_release.py @@ -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)