~ubuntu-branches/ubuntu/quantal/lsb/quantal-proposed

« back to all changes in this revision

Viewing changes to lsb_release.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2013-06-13 10:22:16 UTC
  • Revision ID: package-import@ubuntu.com-20130613102216-1oqae13cgvdnybch
Tags: 4.0-0ubuntu26.2
lsb_release.py: Use the subprocess module instead of the commands
module to work around Python SIGCHLD handler issue9127.  LP: #1094218

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    02111-1307, USA.
19
19
 
20
20
import sys
21
 
import commands
22
21
import os
23
22
import re
 
23
import subprocess
24
24
 
25
25
# XXX: Update as needed
26
26
# This should really be included in apt-cache policy output... it is already
99
99
# This is Debian-specific at present
100
100
def check_modules_installed():
101
101
    # Find which LSB modules are installed on this system
102
 
    output = commands.getoutput("dpkg-query -f '${Version} ${Provides}\n' -W %s 2>/dev/null" % PACKAGES)
 
102
    C_env = os.environ.copy(); C_env['LC_ALL'] = 'C'
 
103
    output = subprocess.Popen(['dpkg-query','-f',"${Version} ${Provides}\n",'-W'] + PACKAGES.split(),
 
104
                              env=C_env,
 
105
                              stdout=subprocess.PIPE,
 
106
                              stderr=subprocess.PIPE,
 
107
                              close_fds=True).communicate()[0].decode('utf-8')
 
108
 
103
109
    if not output:
104
110
        return []
105
111
 
106
112
    modules = set()
107
113
    for line in output.split(os.linesep):
 
114
        if not line:
 
115
            break
108
116
        version, provides = line.split(' ', 1)
109
117
        version = version.split('-', 1)[0]
110
118
        for pkg in provides.split(','):
145
153
def parse_apt_policy():
146
154
    data = []
147
155
    
148
 
    policy = commands.getoutput('LANG=C apt-cache policy 2>/dev/null')
 
156
    C_env = os.environ.copy(); C_env['LC_ALL'] = 'C'
 
157
    policy = subprocess.Popen(['apt-cache','policy'],
 
158
                              env=C_env,
 
159
                              stdout=subprocess.PIPE,
 
160
                              stderr=subprocess.PIPE,
 
161
                              close_fds=True).communicate()[0].decode('utf-8')
149
162
    for line in policy.split('\n'):
150
163
        line = line.strip()
151
164
        m = re.match(r'(\d+)', line)