def createPage(display, filename, title): page = {} page['title'] = title; page['blocks'] = [] display[filename] = page return page def appendBlockToPage(page, block): page['blocks'].append(block) def createTable(title, cols): table = {'type' : 'table', 'title' : title} table['cols'] = cols table['rows'] = [] return table def appendRowToTable(table, row): table['rows'].append(row) def buildTable(block, f): print 'Write table %s' % block['title'] f.write('') f.write('') for title in block['cols']: f.write('' % (title)) f.write('') for row in block['rows']: f.write('') for v in row: f.write('' % (v)) f.write('') f.write('
%s
%s
') def buildPages(display_root, display): for filename in display.keys(): page = display[filename] print "OPEN %s" % (display_root + filename) with open(display_root + filename, 'w') as f: f.write('%s' % (page['title'])) for block in page['blocks']: print "Bluid block" print block print "End block" if block['type'] == 'html': f.write(block['value']) elif block['type'] == 'table': buildTable(block, f) f.write('')