#!/usr/bin/env python # ZNeK - 20031012 """ HTML ChangeLog aggregation. """ __version__ = "@()$Id: clhtml_month.py,v 1.3 2003/10/20 15:42:14 znek Exp $" import sys import time import urllib import calendar from changelogparser import * from config import * from index import INDEX ## ## TEMPLATES ## HTML=""" %(project)s progress
%(content)s
""" DATE_ENTRY="""
%(day)s %(monthName)s
%(year)s
%(logEntry)s
""" LOG_ENTRY_HEADER="""

%(subProject)s

%(subProjectPath)s


Committed by %(quotedAuthor)s
""" SINGLE_LOG_ENTRY="""
  • %(comment)s
    """ DUAL_LOG_ENTRY="""
  • %(preamble)s:
    %(comment)s
    """ EMPTY_CALENDAR_ENTRY=""" """ REF_CALENDAR_ENTRY="""%(day)d""" NOREF_CALENDAR_ENTRY="""%(day)d""" ARCHIVE_ENTRY="""%(monthName)s %(year)s
    """ ## ## MAIN ## if __name__ == '__main__': try: limit = 0 # no entry limit if len(sys.argv) != 3: raise IndexError("Foo") year = sys.argv[1] month = sys.argv[2] datematch = year + month + ".." CONFIG["monthName"] = time.strftime("%B", (int(year), int(month), 1, 0, 0, 0, 0, 0, 0)) CONFIG["month"] = month CONFIG["year"] = year CONFIG["archiveName"] = year + month + ".html" content = "" mergedEntries = getMergedEntriesFromConfig(CONFIG, datematch, limit) for mergedEntry in mergedEntries: dateStruct = mergedEntry["date"] entryDict = {} entryDict["day"] = time.strftime("%d", dateStruct) entryDict["month"] = time.strftime("%m", dateStruct) entryDict["monthName"] = time.strftime("%B", dateStruct) entryDict["year"] = time.strftime("%Y", dateStruct) logEntry = "" for entry in mergedEntry["entries"]: author = entry["author"] # replace author if we have a configuration for that purpose if EMAIL.has_key(author): author = EMAIL[author] mailto = "%s?Subject=%s" % (author, urllib.quote("Re: " + CONFIG["project"] + "'s " + entry["path"] + " ChangeLog entry (" + time.strftime("%Y-%m-%d", dateStruct) + ")")) logEntryDict = {} logEntryDict["subProject"] = htmlQuotedString(entry["project"]) logEntryDict["author"] = author logEntryDict["quotedAuthor"] = htmlQuotedString(author) logEntryDict["subProjectPath"] = entry["path"] logEntryDict["viewcvs"] = CONFIG["viewcvs"] logEntryDict["mailto"] = mailto logEntries = "" for log in entry["logs"]: logEntryDict["comment"] = htmlQuotedString(log[1]) if log[0] == None: if logEntryDict.has_key("preamble"): del logEntryDict["preamble"] logEntries += SINGLE_LOG_ENTRY % logEntryDict else: logEntryDict["preamble"] = htmlQuotedString(log[0]) logEntries += DUAL_LOG_ENTRY % logEntryDict logEntryDict["logEntries"] = logEntries logEntry += LOG_ENTRY_HEADER % logEntryDict entryDict["logEntry"] = logEntry dateEntry = DATE_ENTRY % entryDict content += dateEntry htmlDict = {} htmlDict.update(CONFIG) htmlDict["project"] = htmlQuotedString(CONFIG["project"]) htmlDict["content"] = content # construct this month's calendar cal = "" calDict = {} calDict["year"] = int(CONFIG["year"]) calDict["month"] = int(CONFIG["month"]) indexDays = INDEX[CONFIG["year"]][CONFIG["month"]] calendar.setfirstweekday(6) # Sunday daymatrix = calendar.monthcalendar(calDict["year"], calDict["month"]) for row in daymatrix: cal += "" for day in row: if day == 0: cal += EMPTY_CALENDAR_ENTRY % calDict else: calDict["day"] = day if "%02d" % day in indexDays: cal += REF_CALENDAR_ENTRY % calDict else: cal += NOREF_CALENDAR_ENTRY % calDict cal += "" htmlDict["calendar"] = cal # construct the archives overview archives = "" archiveDict = {} # archiveDict["webArchivePath"] = CONFIG["webArchivePath"] years = INDEX.keys() years.sort(sortDescending) for year in years: months = INDEX[year].keys() months.sort(sortDescending) for month in months: datestamp = year + month archiveDict["year"] = year archiveDict["monthName"] = time.strftime("%B", (int(year), int(month), 1, 0, 0, 0, 0, 0, 0)) archiveDict["pageName"] = datestamp archives += ARCHIVE_ENTRY % archiveDict htmlDict["archives"] = archives html = HTML % htmlDict f = open(fullFSPathForArchiveNamed(CONFIG, CONFIG["archiveName"]), "w") f.write(html) f.close() except IndexError: sys.stderr.write("Usage: clhtml.py year month\nyear: 4 digit number\nmonth: 2 digit number\n") sys.exit(1) except IOError: sys.stderr.write("%s\n" % (sys.exc_value)) sys.exit(1) # except: # sys.stderr.write("Unexpected error %s:%s\n" % (sys.exc_type, sys.exc_value)) # sys.exit(1)