~ubuntu-branches/ubuntu/wily/simplestreams/wily-proposed

« back to all changes in this revision

Viewing changes to tools/ubuntu_versions.py

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2015-05-13 13:03:50 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20150513130350-1lop1j1l02zzzsyc
Tags: 0.1.0~bzr378-0ubuntu1
* New upstream snapshot.
  - GlanceMirror: identify images as i686 not i386 (LP: #1454775)
  - sstream-mirror: debug statement about filtered items
  - GlanceMirror: do not strip version information from endpoints
    (LP: #1346935)
  - general fixes to tools/ that are upstream only, not packaged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
#   Copyright (C) 2013 Canonical Ltd.
 
3
#
 
4
#   Author: Scott Moser <scott.moser@canonical.com>
 
5
#
 
6
#   Simplestreams is free software: you can redistribute it and/or modify it
 
7
#   under the terms of the GNU Affero General Public License as published by
 
8
#   the Free Software Foundation, either version 3 of the License, or (at your
 
9
#   option) any later version.
 
10
#
 
11
#   Simplestreams is distributed in the hope that it will be useful, but
 
12
#   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
13
#   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 
14
#   License for more details.
 
15
#
 
16
#   You should have received a copy of the GNU Affero General Public License
 
17
#   along with Simplestreams.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
# this is only used if no distro_info available
 
20
HARDCODED_REL2VER = {
 
21
    "hardy": {'version': "8.04", 'devname': "Hardy Heron"},
 
22
    "lucid": {'version': "10.04", 'devname': "Lucid Lynx"},
 
23
    "oneiric": {'version': "11.10", 'devname': "Oneiric Ocelot"},
 
24
    "precise": {'version': "12.04", 'devname': "Precise Pangolin"},
 
25
    "quantal": {'version': "12.10", 'devname': "Quantal Quetzal"},
 
26
    "raring": {'version': "13.04", 'devname': "Raring Ringtail"},
 
27
    "saucy": {'version': "13.10", 'devname': "Saucy Salamander"},
 
28
    "trusty": {'version': "14.04", 'devname': "Trusty Tahr"},
 
29
    "utopic": {'version': "14.10", 'devname': "Utopic Unicorn"},
 
30
    "vivid": {'version': "15.04", 'devname': "Vivid Vervet"},
 
31
    "vivid": {'version': "15.10", 'devname': "Wily Werewolf"},
 
32
}
 
33
 
 
34
from simplestreams.log import LOG
 
35
 
 
36
 
 
37
def get_ubuntu_info(date=None):
 
38
    # this returns a sorted list of dicts
 
39
    # each dict has information about an ubuntu release.
 
40
    # Notably absent is any date information (release or eol)
 
41
    # its harder than you'd like to get at data via the distro_info library
 
42
    #
 
43
    # The resultant dicts looks like this:
 
44
    # {'codename': 'saucy', 'devel': True,
 
45
    #  'full_codename': 'Saucy Salamander',
 
46
    #  'fullname': 'Ubuntu 13.10 "Saucy Salamander"',
 
47
    #  'lts': False, 'supported': True, 'version': '13.10'}
 
48
 
 
49
    udi = distro_info.UbuntuDistroInfo()
 
50
    # 'all' is a attribute, not a function. so we can't ask for it formated.
 
51
    # s2all and us2all are lists, the value of each is the index
 
52
    # where that release should fall in 'all'.
 
53
    allcn = udi.all
 
54
    s2all = [allcn.index(c) for c in
 
55
             udi.supported(result="codename", date=date)]
 
56
    us2all = [allcn.index(c) for c in
 
57
              udi.unsupported(result="codename", date=date)]
 
58
 
 
59
    def getall(result, date):
 
60
        ret = [None for f in range(0, len(allcn))]
 
61
        for i, r in enumerate(udi.supported(result=result, date=date)):
 
62
            ret[s2all[i]] = r
 
63
        for i, r in enumerate(udi.unsupported(result=result, date=date)):
 
64
            ret[us2all[i]] = r
 
65
        return [r for r in ret if r is not None]
 
66
 
 
67
    codenames = getall(result="codename", date=date)
 
68
    fullnames = getall(result="fullname", date=date)
 
69
    lts = [bool('LTS' in f) for f in fullnames]
 
70
    versions = [x.replace(" LTS", "") for x in
 
71
                getall(result="release", date=date)]
 
72
    full_codenames = [x.split('"')[1] for x in fullnames]
 
73
    supported = udi.supported(date=date)
 
74
    try:
 
75
        devel = udi.devel(date=date)
 
76
    except distro_info.DistroDataOutdated as e:
 
77
        LOG.warn("distro_info.UbuntuDistroInfo() raised exception (%s)."
 
78
                 " Using stable release as devel.", e)
 
79
        devel = udi.stable(date=date)
 
80
    ret = []
 
81
    for i, codename in enumerate(codenames):
 
82
        ret.append({'lts': lts[i], 'version': versions[i],
 
83
                    'supported': codename in supported,
 
84
                    'fullname': fullnames[i], 'codename': codename,
 
85
                    'devname': full_codenames[i],
 
86
                    'devel': bool(codename == devel)})
 
87
 
 
88
    return ret
 
89
 
 
90
 
 
91
try:
 
92
    import distro_info
 
93
    info = get_ubuntu_info()
 
94
    REL2VER = {}
 
95
    for r in info:
 
96
        if r['codename'] < "hardy":
 
97
            continue
 
98
        REL2VER[r['codename']] = {x: r[x] for x in ("version", "devname")}
 
99
 
 
100
except ImportError:
 
101
    REL2VER = HARDCODED_REL2VER