--- /dev/null
+lsb-release for Debian
+----------------------
+
+NB: These notes are intended for anyone building a derived
+distribution using this package. They are not likely to be helpful to
+end-users.
+
+This is a reimplementation of the classic lsb_release command; its
+main new feature is support for the new output for the -v option in
+LSB 2.x/3.x. This version of lsb_release is also designed to only report
+that a system is LSB compliant if the correct LSB metapackages are available,
+and to properly support situations where only certain LSB metapackages
+(i.e. lsb-core only) are installed.
+
+Distribution-specific information should be *separately provided* in
+/etc/lsb-release; it is no longer provided in this package. It is my
+hope that in Debian, this will be managed by the base-files
+maintainer (who already maintains the debian_version file).
+
+The file should be formatted as a series of shell variable
+assignments. Multiword strings should be quoted in double quotes.
+You should not assume this file is actually parsed by a Bourne shell
+(i.e., no fancy stuff). Example:
+
+DISTRIB_ID=(Distributor ID)
+DISTRIB_DESCRIPTION=(A human-readable description of the release)
+DISTRIB_RELEASE=(The release number)
+DISTRIB_CODENAME=(The codename for the release)
+
+Any other variable assignments will be silently ignored. For Debian
+3.1 (sarge), it might have read:
+
+DISTRIB_ID=Debian
+DISTRIB_DESCRIPTION="Debian GNU/Linux 3.1 (sarge)"
+DISTRIB_RELEASE=3.1
+DISTRIB_CODENAME=sarge
+
+ -- Chris Lawrence <lawrencc@debian.org>, Wed Sep 21 20:40:25 2005
--- /dev/null
+#!/usr/bin/python
+
+# lsb_release command for Debian
+# (C) 2005 Chris Lawrence <lawrencc@debian.org>
+
+# This package is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 dated June, 1991.
+
+# This package is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this package; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+from optparse import OptionParser
+import sys
+import commands
+import os
+import re
+
+# LSB compliance packages... may grow eventually
+PACKAGES = 'lsb-core lsb-cxx lsb-graphics'
+
+modnamere = re.compile(r'lsb-(?P<module>[a-z]+)-(?P<arch>[^ ]+)(?: \(= (?P<version>[0-9.]+)\))?')
+
+def valid_lsb_versions(version, module):
+ # If a module is ever released that only appears in >= version, deal
+ # with that here
+ if version == '3.0':
+ return ['2.0', '3.0']
+
+ return [version]
+
+def check_modules_installed():
+ # Find which LSB modules are installed on this system
+ output = commands.getoutput("dpkg-query -f '${Version} ${Provides}\n' -W %s 2>/dev/null" % PACKAGES)
+ if not output:
+ return []
+
+ modules = []
+ for line in output.split(os.linesep):
+ version, provides = line.split(' ', 1)
+ version = version.split('-', 1)[0]
+ for pkg in provides.split(','):
+ mob = modnamere.search(pkg)
+ if not mob:
+ continue
+
+ mgroups = mob.groupdict()
+ # If no versioned provides...
+ if mgroups.get('version'):
+ module = '%(module)s-%(version)s-%(arch)s' % mgroups
+ modules += [module]
+ else:
+ module = mgroups['module']
+ for v in valid_lsb_versions(version, module):
+ mgroups['version'] = v
+ module = '%(module)s-%(version)s-%(arch)s' % mgroups
+ modules += [module]
+
+ return modules
+
+RELEASE_CODENAME_LOOKUP = {
+ '1.1' : 'buzz',
+ '1.2' : 'rex',
+ '1.3' : 'bo',
+ '2.0' : 'hamm',
+ '2.1' : 'slink',
+ '2.2' : 'potato',
+ '3.0' : 'woody',
+ '3.1' : 'sarge',
+ '3.2' : 'etch', # XXX - may not end up as 3.2
+ }
+
+def guess_debian_release():
+ distinfo = {'ID' : 'Debian'}
+
+ kern = os.uname()[0]
+ if kern in ('Linux', 'Hurd', 'NetBSD'):
+ distinfo['OS'] = 'GNU/'+kern
+ elif kern == 'FreeBSD':
+ distinfo['OS'] = 'GNU/k'+kern
+
+ if os.path.exists('/etc/debian_version'):
+ release = open('/etc/debian_version').read().strip()
+ if not release[0:1].isalpha():
+ # /etc/debian_version should be numeric
+ codename = RELEASE_CODENAME_LOOKUP.get(release, 'n/a')
+ distinfo.update({ 'RELEASE' : release, 'CODENAME' : codename })
+ else:
+ # Guess with apt policy before being this stupid?
+ distinfo.update({ 'RELEASE' : release, 'CODENAME' : 'sid'} )
+
+ distinfo['DESCRIPTION'] = '%(ID)s %(OS)s %(RELEASE)s (%(CODENAME)s)' % distinfo
+ return distinfo
+
+def get_distro_information():
+ distinfo = {}
+ if os.path.exists('/etc/lsb-release'):
+ for line in open('/etc/lsb-release'):
+ line = line.strip()
+ if not line:
+ continue
+ var, arg = line.split('=', 1)
+ if var.startswith('DISTRIB_'):
+ var = var[8:]
+ if arg.startswith('"') and arg.endswith('"'):
+ arg = arg[1:-1]
+ distinfo[var] = arg
+ else:
+ distinfo = guess_debian_release()
+
+ return distinfo
+
+def main():
+ parser = OptionParser()
+ parser.add_option('-v', '--version', dest='output', action='store_const',
+ const='version', default='version',
+ help="show LSB modules this system supports")
+ parser.add_option('-i', '--id', dest='output', action='store_const',
+ const='id', help="show distributor ID")
+ parser.add_option('-d', '--description', dest='output',
+ action='store_const', const='description',
+ help="show description of this distribution")
+ parser.add_option('-r', '--release', dest='output',
+ action='store_const', const='release',
+ help="show release number of this distribution")
+ parser.add_option('-c', '--codename', dest='output',
+ action='store_const', const='codename',
+ help="show code name of this distribution")
+ parser.add_option('-a', '--all', dest='output',
+ action='store_const', const='all',
+ help="show all of the above information")
+ parser.add_option('-s', '--short', dest='short',
+ action='store_true', default=False,
+ help="show all of the above information in short format")
+
+ (options, args) = parser.parse_args()
+ if args:
+ parser.error("No arguments are permitted")
+
+ short = (options.short)
+ all = (options.output=='all')
+
+ distinfo = get_distro_information()
+
+ if options.output == 'version' or all:
+ verinfo = check_modules_installed()
+ if not verinfo:
+ print >> sys.stderr, "No LSB modules are available."
+ elif short:
+ print ':'.join(verinfo)
+ else:
+ print 'LSB Version:\t' + ':'.join(verinfo)
+
+ if options.output == 'id' or all:
+ if short:
+ print distinfo.get('ID', 'n/a')
+ else:
+ print 'Distributor ID:\t%s' % distinfo.get('ID', 'n/a')
+
+ if options.output == 'description' or all:
+ if short:
+ print distinfo.get('DESCRIPTION', 'n/a')
+ else:
+ print 'Description:\t%s' % distinfo.get('DESCRIPTION', 'n/a')
+
+ if options.output == 'release' or all:
+ if short:
+ print distinfo.get('RELEASE', 'n/a')
+ else:
+ print 'Release:\t%s' % distinfo.get('RELEASE', 'n/a')
+
+ if options.output == 'codename' or all:
+ if short:
+ print distinfo.get('CODENAME', 'n/a')
+ else:
+ print 'Codename:\t%s' % distinfo.get('CODENAME', 'n/a')
+
+if __name__ == '__main__':
+ main()