#!/usr/bin/python import string, sys from xml.sax import saxutils class FeaturePlan: def __init__ (self, input): in_header = 1 version_break = 0 manual_break = 0 version = [] section1 = [] section2 = [] paragraph = [] self.versions = versions = [] self.header = header = {} for line in input.readlines(): line = line[:-1] ##DEBUG## print line if not line.strip(): manual_break = 1 ##DEBUG## print "(manual break)" elif line[0] == '=': version_break = 1 in_header = 0 ##DEBUG## print "(end section)" elif in_header: field, value = line.split(':',1) value = value.strip() header[field] = value ##DEBUG## print "(header text)" elif version_break: version = [] versions.append( (line, version) ) version_break = 0 ##DEBUG## print "(version)" elif line[0] != ' ': section2 = [] section1 = [('',section2)] version.append ((line, section1)) ##DEBUG## print "(new section)" else: indention = int((len(line) - len(line.lstrip()))/2-2 + .5) if indention < 0: indention = 0 line = line.strip() if line[0] == '[': section2 = [] manual_break = 1 section1.append( (line[1:-1].strip(), section2) ) ##DEBUG## print "(new subsection)" elif manual_break: paragraph = [line] section2.append((indention, paragraph)) manual_break = 0 ##DEBUG## print "(new paragraph)" else: paragraph.append(line) ##DEBUG## print "(con't paragraph)" ##DEBUG## print self.versions def writeHtml(self, output): colorMap = { 'GOALS': ('blue', '#eeeeff'), 'TODO': ('red', '#ffeeee'), 'IN PROGRESS': ('yellow','#ffffee'), 'FINISHED': ('green', '#eeffee') } output.write(htmlHeader.replace('__tool__',self.header['Product'])) for version, sections in self.versions: output.write('
' + string.join(paragraph,'\n') + '
') output.write('
__tool__ feature planIf you cannot finish a feature in time, please consider moving it to the next release section. """ ############################################################ ## ## if __name__ == '__main__': infile = sys.argv[1] txtfile = "TODO" htmlfile = string.join(infile.split('.')[:-1],'.') + '.html' input = open(infile) fp = FeaturePlan(input) input.close() output = open(htmlfile,'w') fp.writeHtml(output) output.close() output = open(txtfile,'w') fp.writeText(output) output.close() |