org/teams/NetworkTeam/TeamRotations: rotations.py

File rotations.py, 1.6 KB (added by nickm, 10 months ago)
Line 
1#!/usr/bin/python3
2PEOPLE = """
3  ahf
4  asn
5  catalyst
6  dgoulet
7  isis
8  mikeperry
9  nickm
10"""
11
12ROTATIONS = """
13  Bug triage
14  Community hero
15  Coverity
16  CI
17"""
18
19PEOPLE = [ x.strip() for x in PEOPLE.split("\n") if x.strip() ]
20
21ROTATIONS = [ x.strip() for x in ROTATIONS.split("\n") if x.strip() ]
22
23START_DATE = "2018-03-26"
24END_DATE = "2018-08-01"
25
26INITIAL_OFFSET = 0
27
28import time, calendar
29
30def skip(iterable, offset):
31    it = iter(iterable)
32    for _ in range(offset):
33        next(it)
34    for x in it:
35        yield x
36
37def loop(lst):
38    while True:
39        for x in lst:
40            yield x
41
42if len(PEOPLE) < len(ROTATIONS):
43    print("Pigeonhole principle is violated: more rotations than people.")
44
45rotation_iterators = [ ]
46
47for off in range(len(ROTATIONS)):
48    rotation_iterators.append(
49        skip(loop(PEOPLE), offset=(off+INITIAL_OFFSET)))
50
51DFORMAT = "%Y-%m-%d"
52ONE_WEEK = 7 * 24 * 60 * 60
53
54begin = calendar.timegm(time.strptime(START_DATE, DFORMAT))
55end = calendar.timegm(time.strptime(END_DATE, DFORMAT))
56
57now = begin
58
59inmonth = -10 # no month
60
61while now <= end:
62    wstart = time.gmtime(now)
63
64    if inmonth != wstart.tm_mon:
65        # month header
66        print()
67        print(time.strftime("'''%B, %Y'''", wstart))
68        print()
69        print("||= {} =||".format(" =||= ".join(
70              "{:16}".format(x) for x in [ "Week of" ] + ROTATIONS)))
71        inmonth = wstart.tm_mon
72
73    # The line for this week
74    print("||= {:16} =||".format(time.strftime(DFORMAT, wstart)),
75          end="")
76    for ri in rotation_iterators:
77        print(" {:18} ||".format(next(ri)), end="")
78    print()
79
80    now += ONE_WEEK
81