File: debian-distro-info

package info (click to toggle)
distro-info 1.14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 324 kB
  • sloc: ansic: 973; python: 959; sh: 860; haskell: 519; perl: 411; makefile: 69
file content (136 lines) | stat: -rwxr-xr-x 4,458 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3

# Copyright (C) 2009-2011, Benjamin Drung <bdrung@debian.org>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# pylint: disable=invalid-name
# pylint: enable=invalid-name

"""provides information about Debian's distributions"""

import argparse
import os
import sys

from distro_info import DebianDistroInfo, convert_date


def parse_args():
    script_name = os.path.basename(sys.argv[0])
    usage = f"{script_name} [options]"
    epilog = f"See {script_name}(1) for more info."
    parser = argparse.ArgumentParser(usage=usage, epilog=epilog)

    parser.add_argument(
        "--date",
        dest="date",
        default=None,
        help="date for calculating the version (default: today).",
    )
    parser.add_argument(
        "-a", "--all", dest="all", action="store_true", help="list all known versions"
    )
    parser.add_argument(
        "-d", "--devel", dest="devel", action="store_true", help="latest development version"
    )
    parser.add_argument(
        "-t", "--testing", dest="testing", action="store_true", help="current testing version"
    )
    parser.add_argument(
        "-s", "--stable", dest="stable", action="store_true", help="latest stable version"
    )
    parser.add_argument(
        "-o", "--old", dest="old", action="store_true", help="latest old (stable) version"
    )
    parser.add_argument(
        "--supported",
        dest="supported",
        action="store_true",
        help="list of all supported versions (including development)",
    )
    parser.add_argument(
        "-l",
        "--lts",
        dest="lts",
        action="store_true",
        help="list of all LTS supported stable versions",
    )
    parser.add_argument(
        "-e",
        "--elts",
        dest="elts",
        action="store_true",
        help="list of all ELTS supported stable versions",
    )
    parser.add_argument(
        "--unsupported", dest="unsupported", help="list of all unsupported stable versions"
    )

    args = parser.parse_args()

    versions = [
        args.all,
        args.devel,
        args.lts,
        args.elts,
        args.old,
        args.stable,
        args.supported,
        args.testing,
        args.unsupported,
    ]
    if len([x for x in versions if x]) != 1:
        parser.error(
            "You have to select exactly one of --all, --devel, --elts, --lts,"
            " --old, --stable, --supported, --testing, --unsupported."
        )

    if args.date is not None:
        try:
            args.date = convert_date(args.date)
        except ValueError:
            parser.error("Option --date needs to be a date in ISO 8601 format.")
    return args


def main():
    # pylint: disable=too-many-branches
    args = parse_args()
    if args.all:
        for distro in DebianDistroInfo().all:
            sys.stdout.write(distro + "\n")
    elif args.devel:
        sys.stdout.write(DebianDistroInfo().devel(args.date) + "\n")
    elif args.old:
        sys.stdout.write(DebianDistroInfo().old(args.date) + "\n")
    elif args.stable:
        sys.stdout.write(DebianDistroInfo().stable(args.date) + "\n")
    elif args.supported:
        for distro in DebianDistroInfo().supported(args.date):
            sys.stdout.write(distro + "\n")
    elif args.lts:
        for distro in DebianDistroInfo().lts_supported(args.date):
            sys.stdout.write(distro + "\n")
    elif args.elts:
        for distro in DebianDistroInfo().elts_supported(args.date):
            sys.stdout.write(distro + "\n")
    elif args.testing:
        sys.stdout.write(DebianDistroInfo().testing(args.date) + "\n")
    elif args.unsupported:
        for distro in DebianDistroInfo().unsupported(args.date):
            sys.stdout.write(distro + "\n")


if __name__ == "__main__":
    main()