return releases[0][1]
def guess_debian_release():
- distinfo = {'ID' : 'Debian'}
+ distinfo = {}
+
+ distinfo['ID'] = 'Debian'
+ # Use /etc/dpkg/origins/default to fetch the distribution name
+ etc_dpkg_origins_default = os.environ.get('LSB_ETC_DPKG_ORIGINS_DEFAULT','/etc/dpkg/origins/default')
+ if os.path.exists(etc_dpkg_origins_default):
+ try:
+ with open(etc_dpkg_origins_default) as dpkg_origins_file:
+ for line in dpkg_origins_file:
+ try:
+ (header, content) = line.split(': ', 1)
+ header = header.lower()
+ content = content.strip()
+ if header == 'vendor':
+ distinfo['ID'] = content
+ except ValueError:
+ pass
+ except IOError as msg:
+ print('Unable to open ' + etc_dpkg_origins_default + ':', str(msg), file=sys.stderr)
kern = os.uname()[0]
if kern in ('Linux', 'Hurd', 'NetBSD'):
def test_guess_debian_release(self):
distinfo = get_arch_distinfo()
+
+ # Test different dpkg origin with an fake "unstable releases" that ends in /sid, and an invalid apt-cache policy
+ distinfo['ID'] = rnd_string(5,12)
+ fn = 'test/dpkg_origins_default_' + rnd_string(5,5)
+ f = open(fn,'w')
+ f.write('Vendor: ' + distinfo['ID'] + "\n")
+ f.close()
+ os.environ['LSB_ETC_DPKG_ORIGINS_DEFAULT'] = fn
+
+ distinfo['RELEASE'] = 'testing/unstable'
+ distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s' % distinfo
+ fn2 = 'test/debian_version_' + rnd_string(5,12)
+ f = open(fn2,'w')
+ f.write(rnd_string(5,12) + '/sid')
+ f.close()
+ os.environ['LSB_ETC_DEBIAN_VERSION'] = fn2
+ self.assertEqual(lr.guess_debian_release(),distinfo)
+ os.remove(fn)
+ # Make sure no existing /etc/dpkg/origins/default is used
+ os.environ['LSB_ETC_DPKG_ORIGINS_DEFAULT'] = '/non-existant'
+ distinfo['ID'] = 'Debian'
# Test "stable releases" with numeric debian_versions
for rno in lr.RELEASE_CODENAME_LOOKUP: