~elementary-os/ubuntu-package-imports/lsb-trusty

« back to all changes in this revision

Viewing changes to lsb_release

  • Committer: RabbitBot
  • Date: 2013-11-08 11:21:44 UTC
  • Revision ID: rabbitbot@elementaryos.org-20131108112144-x97gxjpab4rk9fcx
Initial import, version 4.1+Debian11ubuntu4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -Es
 
2
 
 
3
# lsb_release command for Debian
 
4
# (C) 2005-10 Chris Lawrence <lawrencc@debian.org>
 
5
 
 
6
#    This package is free software; you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation; version 2 dated June, 1991.
 
9
 
 
10
#    This package is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
 
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this package; if not, write to the Free Software
 
17
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
18
#    02110-1301 USA
 
19
 
 
20
# Python3-compatible print() function
 
21
from __future__ import print_function
 
22
 
 
23
from optparse import OptionParser
 
24
import sys
 
25
import os
 
26
import re
 
27
 
 
28
import lsb_release
 
29
 
 
30
def main():
 
31
    parser = OptionParser()
 
32
    parser.add_option('-v', '--version', dest='version', action='store_true',
 
33
                      default=False,
 
34
                      help="show LSB modules this system supports")
 
35
    parser.add_option('-i', '--id', dest='id', action='store_true',
 
36
                      default=False,
 
37
                      help="show distributor ID")
 
38
    parser.add_option('-d', '--description', dest='description',
 
39
                      default=False, action='store_true',
 
40
                      help="show description of this distribution")
 
41
    parser.add_option('-r', '--release', dest='release',
 
42
                      default=False, action='store_true',
 
43
                      help="show release number of this distribution")
 
44
    parser.add_option('-c', '--codename', dest='codename',
 
45
                      default=False, action='store_true',
 
46
                      help="show code name of this distribution")
 
47
    parser.add_option('-a', '--all', dest='all',
 
48
                      default=False, action='store_true',
 
49
                      help="show all of the above information")
 
50
    parser.add_option('-s', '--short', dest='short',
 
51
                      action='store_true', default=False,
 
52
                      help="show requested information in short format")
 
53
    
 
54
    (options, args) = parser.parse_args()
 
55
    if args:
 
56
        parser.error("No arguments are permitted")
 
57
 
 
58
    short = (options.short)
 
59
    none = not (options.all or options.version or options.id or
 
60
                options.description or options.codename or options.release)
 
61
 
 
62
    distinfo = lsb_release.get_distro_information()
 
63
 
 
64
    if none or options.all or options.version:
 
65
        verinfo = lsb_release.check_modules_installed()
 
66
        if not verinfo:
 
67
            print("No LSB modules are available.", file=sys.stderr)
 
68
        elif short:
 
69
            print(':'.join(verinfo))
 
70
        else:
 
71
            print('LSB Version:\t' + ':'.join(verinfo))
 
72
 
 
73
    if options.id or options.all:
 
74
        if short:
 
75
            print(distinfo.get('ID', 'n/a'))
 
76
        else:
 
77
            print('Distributor ID:\t%s' % distinfo.get('ID', 'n/a'))
 
78
 
 
79
    if options.description or options.all:
 
80
        if short:
 
81
            print(distinfo.get('DESCRIPTION', 'n/a'))
 
82
        else:
 
83
            print('Description:\t%s' % distinfo.get('DESCRIPTION', 'n/a'))
 
84
 
 
85
    if options.release or options.all:
 
86
        if short:
 
87
            print(distinfo.get('RELEASE', 'n/a'))
 
88
        else:
 
89
            print('Release:\t%s' % distinfo.get('RELEASE', 'n/a'))
 
90
 
 
91
    if options.codename or options.all:
 
92
        if short:
 
93
            print(distinfo.get('CODENAME', 'n/a'))
 
94
        else:
 
95
            print('Codename:\t%s' % distinfo.get('CODENAME', 'n/a'))
 
96
 
 
97
if __name__ == '__main__':
 
98
    main()