Skip to content

Instantly share code, notes, and snippets.

@curlup
Created August 16, 2012 14:12
Show Gist options
  • Save curlup/3370381 to your computer and use it in GitHub Desktop.
Save curlup/3370381 to your computer and use it in GitHub Desktop.
график релизов по командам
#!/usr/bin/env python
#coding: utf-8
import calendar, datetime, time, itertools
from itertools import cycle, starmap
class ReleaseCal(calendar.HTMLCalendar):
def __init__(self, groups, offset=0, skip_list=None):
super(ReleaseCal, self).__init__()
self.skip_list = skip_list if skip_list is not None else []
self.today = time.localtime()[:3]
self._formatyear = None
self._formatmonth = None
self._formatday = None
self._today_group = None
self.groups = groups
self.offset = offset
self.groups_cycle = cycle(groups)
for i in range(offset):
self.groups_cycle.next()
def check_this_day(self, year, month, day, *ignore):
return self._formatyear == year and self._formatmonth == month and self._formatday == day
def formatday(self, day, weekday):
self._formatday = day
skip_this = any(starmap(self.check_this_day, self.skip_list))
this_today = self.check_this_day(*self.today)
if day and not skip_this:
_group = self.groups_cycle.next() if weekday not in [5,6] else ''
if this_today:
self._today_group = _group
_group += ' today'
res = '<td class="{1}">{0}</td>'.format(day, _group)
else:
res = super(ReleaseCal, self).formatday(day, weekday)
self._formatday = None
return res
def formatyear(self, theyear, width=3):
self._formatyear = theyear
res = super(ReleaseCal, self).formatyear(theyear, width=width)
self._formatyear = None
res = '<p class="{0}">Today: {0}</p>'.format(self._today_group) + res
return res +'\n'.join(map('<p class="{0}">{0}</p>'.format, self.groups))
def formatmonth(self, theyear, themonth, withyear=True):
old_formatyear = self._formatyear
self._formatyear = theyear
self._formatmonth = themonth
res = super(ReleaseCal, self).formatmonth(theyear, themonth, withyear=withyear)
self._formatyear = old_formatyear
self._formatmonth = None
return res
print ReleaseCal([
('sre billing'),
('joker product'),
('marketing search'),
('webservice *'),
],
2,
[
(2012, 7, 17),
(2012, 8, 15),
(2012, 8, 16),
(2012, 8, 17),
(2012, 8, 30),
(2012, 8, 31),
]
).formatyearpage(time.localtime()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment