mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
ubuntutools.misc: Replace Popen() calls with check_output()
This commit is contained in:
parent
4438c23a72
commit
7a6b779e77
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,3 +1,9 @@
|
|||||||
|
ubuntu-dev-tools (0.174) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* ubuntutools.misc: Replace Popen() calls with check_output()
|
||||||
|
|
||||||
|
-- Stefano Rivera <stefanor@debian.org> Wed, 11 Sep 2019 13:30:54 -0300
|
||||||
|
|
||||||
ubuntu-dev-tools (0.173) unstable; urgency=medium
|
ubuntu-dev-tools (0.173) unstable; urgency=medium
|
||||||
|
|
||||||
[ Stefano Rivera ]
|
[ Stefano Rivera ]
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
# ##################################################################
|
# ##################################################################
|
||||||
|
|
||||||
# Modules.
|
# Modules.
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from subprocess import check_output, CalledProcessError
|
||||||
|
|
||||||
import distro_info
|
import distro_info
|
||||||
|
|
||||||
@ -47,29 +47,22 @@ def system_distribution_chain():
|
|||||||
global _system_distribution_chain
|
global _system_distribution_chain
|
||||||
if len(_system_distribution_chain) == 0:
|
if len(_system_distribution_chain) == 0:
|
||||||
try:
|
try:
|
||||||
p = Popen(('dpkg-vendor', '--query', 'Vendor'),
|
vendor = check_output(('dpkg-vendor', '--query', 'Vendor'),
|
||||||
stdout=PIPE, encoding='utf-8')
|
encoding='utf-8').strip()
|
||||||
_system_distribution_chain.append(p.communicate()[0].strip())
|
_system_distribution_chain.append(vendor)
|
||||||
except OSError:
|
except CalledProcessError:
|
||||||
print('Error: Could not determine what distribution you are running.')
|
print('Error: Could not determine what distribution you are running.')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
p = Popen(('dpkg-vendor',
|
parent = check_output((
|
||||||
'--vendor', _system_distribution_chain[-1],
|
'dpkg-vendor', '--vendor', _system_distribution_chain[-1],
|
||||||
'--query', 'Parent'),
|
'--query', 'Parent'), encoding='utf-8').strip()
|
||||||
stdout=PIPE, encoding='utf-8')
|
except CalledProcessError:
|
||||||
parent = p.communicate()[0].strip()
|
# Vendor has no parent
|
||||||
# Don't check return code, because if a vendor has no
|
|
||||||
# parent, dpkg-vendor returns 1
|
|
||||||
if not parent:
|
|
||||||
break
|
break
|
||||||
_system_distribution_chain.append(parent)
|
_system_distribution_chain.append(parent)
|
||||||
except Exception:
|
|
||||||
print(('Error: Could not determine the parent of the '
|
|
||||||
'distribution %s' % _system_distribution_chain[-1]))
|
|
||||||
return []
|
|
||||||
|
|
||||||
return _system_distribution_chain
|
return _system_distribution_chain
|
||||||
|
|
||||||
@ -91,14 +84,18 @@ def host_architecture():
|
|||||||
architecture can't be determined, print an error message and return None.
|
architecture can't be determined, print an error message and return None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
arch = Popen(['dpkg', '--print-architecture'], stdout=PIPE,
|
try:
|
||||||
stderr=PIPE).communicate()[0].split()
|
arch = check_output(('dpkg', '--print-architecture'),
|
||||||
|
encoding='utf-8').strip()
|
||||||
|
except CalledProcessError:
|
||||||
|
arch = None
|
||||||
|
|
||||||
if not arch or 'not found' in arch[0]:
|
if not arch or 'not found' in arch:
|
||||||
print('Error: Not running on a Debian based system; could not detect its architecture.')
|
print('Error: Not running on a Debian based system; '
|
||||||
|
'could not detect its architecture.')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return arch[0]
|
return arch
|
||||||
|
|
||||||
|
|
||||||
def readlist(filename, uniq=True):
|
def readlist(filename, uniq=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user