-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_supported_ubuntu_versions.py
executable file
·65 lines (55 loc) · 1.57 KB
/
get_supported_ubuntu_versions.py
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
#!/usr/bin/env python3
import os
import tempfile
import atexit
import shutil
from typing import Optional
from datetime import datetime, timedelta, timezone
from launchpadlib.launchpad import Launchpad
# launchpadlib loves to write a cache directory to the user's HOME directory.
# Tell to write in /tmp instead.
cachedir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, cachedir)
os.environ["HOME"] = cachedir
ubus = []
exc = None
try:
lp = Launchpad.login_anonymously(
consumer_name="series-support-check",
service_root="production",
launchpadlib_dir=cachedir,
timeout=15,
version="devel")
series = lp.distributions["ubuntu"].series
for s in series:
# We want more than just the supported versions
dr: Optional[datetime] = s.datereleased
if dr is None:
# Seems to happen for upcoming versions, which won't have working
# Docker images ready yet.
continue
days_old = (datetime.now(timezone.utc) - dr).days
if s.supported or days_old < 365 * 4:
ubus.append((s.version, s.name))
except Exception as e:
# Now that this only runs during pwnmake image building, we don't need
# to be nice when an error happens.
raise
ubus.sort()
print(f'# Autogenerated by {os.path.basename(__file__)}')
if exc is not None:
print(f'# Exception: {exc}')
print("UBUNTU_VERSIONS := \\")
for p in ubus:
print(f"\t{p[0]} \\")
print("\n")
print("UBUNTU_ALIASES := \\")
for p in ubus:
print(f"\t{p[1]} \\")
print("\n")
for p in ubus:
print(f"UBUNTU_VERSION_TO_ALIAS[{p[0]}] := {p[1]}")
print("\n")
for p in ubus:
print(f"UBUNTU_ALIAS_TO_VERSION[{p[1]}] := {p[0]}")
print("\n")