mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
ubuntutools.misc: Add a new "system_distribution_chain", which returns
a list starting with the current distribution and working its way up each distribution's parent.
This commit is contained in:
parent
d69e21a0af
commit
2398d09ba4
7
debian/changelog
vendored
7
debian/changelog
vendored
@ -22,7 +22,12 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low
|
||||
* lp-project-upload:
|
||||
- fix a bug when new milestone wasn't specified
|
||||
|
||||
-- Benjamin Drung <bdrung@debian.org> Sat, 28 May 2011 19:43:10 +0200
|
||||
[ Evan Broder ]
|
||||
* ubuntutools.misc: Add a new "system_distribution_chain", which returns
|
||||
a list starting with the current distribution and working its way up
|
||||
each distribution's parent.
|
||||
|
||||
-- Evan Broder <evan@ebroder.net> Sat, 11 Jun 2011 05:05:21 -0700
|
||||
|
||||
ubuntu-dev-tools (0.124) unstable; urgency=low
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
# Copyright (C) 2008, Jonathan Davies <jpds@ubuntu.com>,
|
||||
# 2008-2009, Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>,
|
||||
# 2010, Stefano Rivera <stefanor@ubuntu.com>
|
||||
# 2011, Evan Broder <evan@ebroder.net>
|
||||
#
|
||||
# ##################################################################
|
||||
#
|
||||
@ -30,7 +31,46 @@ import sys
|
||||
|
||||
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
|
||||
|
||||
_system_distribution = None
|
||||
_system_distribution_chain = []
|
||||
def system_distribution_chain():
|
||||
""" system_distribution_chain() -> [string]
|
||||
|
||||
Detect the system's distribution as well as all of its parent
|
||||
distributions and return them as a list of strings, with the
|
||||
system distribution first (and the greatest grandparent last). If
|
||||
the distribution chain can't be determined, print an error message
|
||||
and return an empty list.
|
||||
"""
|
||||
global _system_distribution_chain
|
||||
if len(_system_distribution_chain) == 0:
|
||||
try:
|
||||
p = Popen(('dpkg-vendor', '--query', 'Vendor'),
|
||||
stdout=PIPE)
|
||||
_system_distribution_chain.append(p.communicate()[0].strip())
|
||||
except OSError:
|
||||
print ('Error: Could not determine what distribution you are '
|
||||
'running.')
|
||||
return []
|
||||
|
||||
while True:
|
||||
try:
|
||||
p = Popen(('dpkg-vendor',
|
||||
'--vendor', _system_distribution_chain[-1],
|
||||
'--query', 'Parent'),
|
||||
stdout=PIPE)
|
||||
parent = p.communicate()[0].strip()
|
||||
# Don't check return code, because if a vendor has no
|
||||
# parent, dpkg-vendor returns 1
|
||||
if not parent:
|
||||
break
|
||||
_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
|
||||
|
||||
def system_distribution():
|
||||
""" system_distro() -> string
|
||||
|
||||
@ -38,24 +78,7 @@ def system_distribution():
|
||||
name of the distribution can't be determined, print an error message
|
||||
and return None.
|
||||
"""
|
||||
global _system_distribution
|
||||
if _system_distribution is None:
|
||||
try:
|
||||
if os.path.isfile('/usr/bin/dpkg-vendor'):
|
||||
process = Popen(('dpkg-vendor', '--query', 'vendor'),
|
||||
stdout=PIPE)
|
||||
else:
|
||||
process = Popen(('lsb_release', '-cs'), stdout=PIPE)
|
||||
output = process.communicate()[0]
|
||||
except OSError:
|
||||
print ('Error: Could not determine what distribution you are '
|
||||
'running.')
|
||||
return None
|
||||
if process.returncode != 0:
|
||||
print 'Error determininng system distribution'
|
||||
return None
|
||||
_system_distribution = output.strip()
|
||||
return _system_distribution
|
||||
return system_distribution_chain()[0]
|
||||
|
||||
def host_architecture():
|
||||
""" host_architecture -> string
|
||||
|
Loading…
x
Reference in New Issue
Block a user