-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupport_status.py
More file actions
116 lines (94 loc) · 4.42 KB
/
Copy pathsupport_status.py
File metadata and controls
116 lines (94 loc) · 4.42 KB
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
"""Shared support-state and display rules for generated consumers."""
from datetime import date, datetime
STATES = {"supported", "ending", "guarantee_elapsed", "ended", "unknown"}
MONTHS = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
]
def _day(value: str) -> date:
return datetime.fromisoformat(value).date()
def _month(value: str) -> tuple[int, int]:
year, month = value.split("-")
return int(year), int(month)
def month_distance(start: date, target: tuple[int, int]) -> int:
"""Return whole calendar months from start's month to target."""
return (target[0] - start.year) * 12 + target[1] - start.month
def support_state(record: dict, as_of: date) -> str:
"""Classify support without inventing precision or an observed stop."""
observation = record.get("support_observation") or {}
if observation.get("status") in {
"no_longer_receives_updates",
"removed_from_support_scope",
}:
return "ended"
window = record.get("support_window") or {}
if window.get("precision") == "month":
target = _month(window["published_value"])
distance = month_distance(as_of, target)
if distance < 0:
return "guarantee_elapsed"
if distance <= 12:
return "ending"
return "supported"
if window.get("precision") == "unknown":
return "unknown"
eol = _day(record["eol"])
days = (eol - as_of).days
if days < 0:
return "ended"
if days <= 365:
return "ending"
return "supported"
def support_date_text(record: dict) -> str:
"""Return a truthful human date label for the evidence precision."""
window = record.get("support_window") or {}
if window.get("precision") == "month":
year, month = _month(window["published_value"])
return f"{MONTHS[month - 1]} {year} — exact end date not specified"
if window.get("precision") == "unknown":
return "Exact end date not established"
value = window.get("published_value") or record["eol"]
parsed = _day(value)
return f"{MONTHS[parsed.month - 1]} {parsed.day}, {parsed.year}"
def support_sentence(record: dict, as_of: date) -> str:
"""Return the status clause used by plain-HTML consumers."""
state = support_state(record, as_of)
name = f"{record['brand']} {record['model']}"
window = record.get("support_window") or {}
precision = window.get("precision")
observation = record.get("support_observation") or {}
observed_ended = observation.get("status") in {
"no_longer_receives_updates",
"removed_from_support_scope",
}
if state == "ended" and observed_ended:
if precision == "month":
return (
f"Current manufacturer evidence shows that the {name} no longer "
f"receives security updates; its stated minimum guarantee was through "
f"{support_date_text(record)}, and the exact stop day is not established here."
)
if precision == "unknown":
return (
f"Current manufacturer evidence shows that the {name} no longer "
"receives security updates; its exact historical cutoff date is not "
"established here."
)
return (
f"Current manufacturer evidence shows that the {name} no longer receives "
f"security updates; its published support date is {support_date_text(record)}, "
"but the observation does not establish the exact stop day."
)
if precision == "month":
label = support_date_text(record)
if state == "guarantee_elapsed":
return f"The stated security-update guarantee period for the {name} has elapsed ({label})."
if month_distance(as_of, _month(window["published_value"])) == 0:
return f"The guaranteed security-update window for the {name} ends this month ({label})."
return f"The guaranteed security-update window for the {name} ends in {label}."
if precision == "unknown":
return f"The current security-update status of the {name} is not established here; its exact support-end date is also unknown."
label = support_date_text(record)
if state == "ended":
return f"Android security updates for the {name} ended on {label}."
return f"Android security updates for the {name} are scheduled to end on {label}."