-
Notifications
You must be signed in to change notification settings - Fork 16
/
schedule
executable file
·97 lines (77 loc) · 2.89 KB
/
schedule
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
#!/usr/bin/env python
"""
This script aims to help you create a schedule by asking for a date and then suggesting a series of
dates. This is printed in a markdown compatible table.
It all starts with the dev start date, which is the date after the previous branching. The exact
date doesn't really matter, since it's normalized to weeks. Based on that it suggests a GA date.
The user should check whether it conflicts with holidays or important conferences and adjust as
needed.
"""
import sys
from datetime import date, datetime
from dateutil.relativedelta import relativedelta
RC = relativedelta(weeks=2)
def parse_date(value: str) -> date:
"""
Parse a date string into a date object
>>> parse_date('2024-03-01')
date(2024, 3, 1)
"""
try:
return datetime.strptime(value, '%Y-%m-%d').date()
except ValueError as exc:
raise SystemExit('Invalid date: ', str(exc)) from exc
def week_range(day: date) -> str:
"""
Accept a date and show the Monday - Friday dates in that week.
>>> week_range(date(2024, 3, 1))
'2024-2-26 - 2024-3-1'
"""
weekday = day.weekday()
monday = day - relativedelta(days=weekday)
friday = day + relativedelta(days=5 - weekday)
return f'{monday} - {friday}'
def print_table(table: list[list]) -> None:
"""
Print a markdown compatible table
"""
table = [[str(column) for column in row] for row in table]
headers = table[0]
# Insert a row of dashes after the headers
table = [headers, ['---'] * len(headers)] + table[1:]
widths = [max(len(x) for x in col) for col in zip(*table)]
for row in table:
print("|", " | ".join(f"{cell:{width}}" for cell, width in zip(row, widths)), "|")
def main():
try:
dev_start = parse_date(sys.argv[1])
except IndexError:
# Dev start is after previous branching
dev_start = parse_date(input("Dev start date (YYYY-MM-DD): "))
branching = dev_start + relativedelta(months=3)
# Align it to Tuesday
branching += relativedelta(days=1 - branching.weekday())
ga_date = branching + (2 * RC)
print('Suggested GA date', ga_date)
ga_date_str = input(f'GA date [{ga_date}] ')
if ga_date_str:
ga_date = parse_date(ga_date_str)
branching = ga_date - (2 * RC)
table = [
('Event', 'Date'),
('Dev start', dev_start),
('Half way point', dev_start + ((branching - dev_start) / 2)),
('Prep week', week_range(branching - relativedelta(weeks=2))),
('Stabilization week', week_range(branching - relativedelta(weeks=1))),
('Branching', branching),
('Release Candidate 1', branching),
('Release Candidate 2', ga_date - RC),
('General Availability', ga_date),
]
print()
print_table(table)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
raise SystemExit() # pylint:disable=raise-missing-from