mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-12 01:11:29 +00:00
Use dpkg-vendor in ubuntutools.misc.system_distribution(), cache result.
This commit is contained in:
parent
516b264a8f
commit
f347770b46
1
debian/changelog
vendored
1
debian/changelog
vendored
@ -17,6 +17,7 @@ ubuntu-dev-tools (0.107) UNRELEASED; urgency=low
|
|||||||
- Refactor to use subprocess.popen instead of os.system (LP: #398974)
|
- Refactor to use subprocess.popen instead of os.system (LP: #398974)
|
||||||
- Catch OSErrors when creating directories (LP: #671067)
|
- Catch OSErrors when creating directories (LP: #671067)
|
||||||
- Set HOME so pbuilder reads .pbuilderrc
|
- Set HOME so pbuilder reads .pbuilderrc
|
||||||
|
* Use dpkg-vendor in ubuntutools.misc.system_distribution(), cache result.
|
||||||
|
|
||||||
[ Benjamin Drung ]
|
[ Benjamin Drung ]
|
||||||
* wrap-and-sort: Remove duplicate items from sorted lists.
|
* wrap-and-sort: Remove duplicate items from sorted lists.
|
||||||
|
@ -26,6 +26,7 @@ from subprocess import Popen, PIPE
|
|||||||
|
|
||||||
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
|
from ubuntutools.lp.udtexceptions import PocketDoesNotExistError
|
||||||
|
|
||||||
|
_system_distribution = None
|
||||||
def system_distribution():
|
def system_distribution():
|
||||||
""" system_distro() -> string
|
""" system_distro() -> string
|
||||||
|
|
||||||
@ -33,21 +34,22 @@ def system_distribution():
|
|||||||
name of the distribution can't be determined, print an error message
|
name of the distribution can't be determined, print an error message
|
||||||
and return None.
|
and return None.
|
||||||
"""
|
"""
|
||||||
# We try to avoid calling the "lsb_release" as looking up the value
|
global _system_distribution
|
||||||
# directly is faster. However, Debian doesn't have /etc/lsb-release
|
if _system_distribution is None:
|
||||||
# so we need to fallback to the former there.
|
try:
|
||||||
if os.path.isfile('/etc/lsb-release'):
|
if os.path.isfile('/usr/bin/dpkg-vendor'):
|
||||||
for line in open('/etc/lsb-release'):
|
p = Popen(('dpkg-vendor', '--query', 'vendor'), stdout=PIPE)
|
||||||
line = line.strip()
|
else:
|
||||||
if line.startswith('DISTRIB_CODENAME'):
|
p = Popen(('lsb_release', '-cs'), stdout=PIPE)
|
||||||
return line[17:]
|
output = p.communicate()[0]
|
||||||
else:
|
except OSError:
|
||||||
import commands
|
print 'Error: Could not determine what distribution you are running.'
|
||||||
output = commands.getoutput('lsb_release -cs')
|
return None
|
||||||
if output:
|
if p.returncode != 0:
|
||||||
return output
|
print 'Error determininng system distribution'
|
||||||
print 'Error: Could not determine what distribution you are running.'
|
return None
|
||||||
return None
|
_system_distribution = output.strip()
|
||||||
|
return _system_distribution
|
||||||
|
|
||||||
def host_architecture():
|
def host_architecture():
|
||||||
""" host_architecture -> string
|
""" host_architecture -> string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user