[releng] wiki.py: print a short calendar overview



commit 83398c68b6ac14897959b1588b56f343f32a9327
Author: Olav Vitters <olav vitters nl>
Date:   Sat Apr 23 21:55:20 2011 +0200

    wiki.py: print a short calendar overview

 tools/schedule/wiki.py |   57 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/tools/schedule/wiki.py b/tools/schedule/wiki.py
index d3e14f2..6a88820 100755
--- a/tools/schedule/wiki.py
+++ b/tools/schedule/wiki.py
@@ -2,16 +2,65 @@
 
 from libschedule import *
 import itertools
+import calendar
 
-events = parse_file ("3.2.schedule")
+def wiki_cal_week(events, week, m):
+    cells = []
+    for day in week:
+        f1 = '<#c5d2c8>' if day.month == m else ''
+        f2 = str(day.day) if day not in events else '[[#d%s|%s|title="%s"]]' % (day.isoformat(), str(day.day), '; '.join((event.summary() for event in events[day])))
+        cells.append('%s%s' % (f1, f2))
+    return cells
 
-print "||<:> '''Week''' ||<:> '''Date''' || '''Task''' || '''Notes''' ||"
+def wiki_cal_month(events, y, m):
+    calmonth = cal.monthdatescalendar(y, m)
+    if len(calmonth) < 6:
+        next_month = cal.monthdatescalendar(y + 1, 1) if m == 12 else \
+                     cal.monthdatescalendar(y, m + 1)
+
+        calmonth.append(next_month[0] if calmonth[-1][-1].month == m else next_month[1])
+    if len(calmonth) < 6:
+        before_month = cal.monthdatescalendar(y - 1, 12) if m == 1 else \
+                       cal.monthdatescalendar(y, m -  1)
+
+        calmonth.insert(0, before_month[-1])
+
+    yield ('<-7: rowbgcolor="#dddddd"> %s' % calmonth[2][0].strftime('%B'),)
+    for week in calmonth:
+        #yield [''.join(('<#c5d2c8>' if d.month == m else '', str(d.day) if d not in events else '[[#d%s|%s]]' % (d.isoformat(), str(d.day))))  for d in week]
+        yield wiki_cal_week(events, week, m)
+
+def splitter(l, n):
+    i = 0
+    chunk = l[:n]
+    while chunk:
+        yield chunk
+        i += n
+        chunk = l[i:i+n]
+
+events = parse_file ("3.2.schedule")
 
 cat_task = set(('release', 'tarball'))
 by_month = lambda val: val.date.month
 by_week = lambda val: val.rel_week
-by_date = lambda val: val.date.day
+by_date = lambda val: val.date
+
+cal = calendar.Calendar()
+
+months = sorted(set([(event.date.year, event.date.month) for event in events]))
+day_events = dict((k, list(val)) for k, val in itertools.groupby(events, by_date))
 
+for smonths in splitter(months, 4):
+    cals = []
+    for month in smonths:
+        c  = wiki_cal_month(day_events, *month)
+        cals.append(c)
+
+    for r in zip(*cals):
+        print '||%s||' % '||'.join(("||".join(cells) for cells in r))
+
+print ""
+print "||<:> '''Week''' ||<:> '''Date''' || '''Task''' || '''Notes''' ||"
 for month, events_month in itertools.groupby(events, by_month):
     events = list(events_month)
 
@@ -27,7 +76,7 @@ for month, events_month in itertools.groupby(events, by_month):
         print "||<|%d ^ : #9db8d2> '''%d''' " % (len (dates), rel_week_str),
         for date, items in dates:
             date_str = items[0].date.strftime("%b %d")
-            print "||<^ : #c5d2c8> %s" % date_str,
+            print "||<^ : #c5d2c8> %s %s" % (date_str, '<<Anchor(d%s)>>' % items[0].date.isoformat()),
 
 
             task_items = [item for item in items if item.category in cat_task]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]