Project

General

Profile

« Previous | Next » 

Revision 6673

dict2redmine: Generate an outline instead of a table so each term will be indexed in the page's table of contents

View differences:

dict2redmine
55 55
    def writerow(self, row):
56 56
        self.stream.write(('|'.join(['']+row+['']))+'\n')
57 57

  
58
class RedmineDictWriter:
59
    '''Formats rows as Redmine sections containing a table'''
60
    
61
    def __init__(self, term_col, header, stream):
62
        header.pop(term_col)
63
        
64
        self.term_col = term_col
65
        self.header = header
66
        self.stream = stream
67
    
68
    def writerow(self, row):
69
        term = row.pop(self.term_col)
70
        self.stream.write('\nh3. '+term+'\n\n')
71
        
72
        table = RedmineTableWriter(self.stream)
73
        for i, col_name in enumerate(self.header):
74
            table.writerow([redmine_bold(col_name), row[i]])
58 75

  
76

  
59 77
def main():
60 78
    try: _prog_name, term_col, sources_col = sys.argv
61 79
    except ValueError: raise SystemExit('Usage: '+sys.argv[0]
......
64 82
    
65 83
    # Translate input
66 84
    reader = csv.reader(sys.stdin)
67
    writer = RedmineTableWriter(sys.stdout)
68
    writer.writerow(map(redmine_bold, reader.next())) # header
85
    header = reader.next()
86
    writer = RedmineDictWriter(term_col, header, sys.stdout)
69 87
    for row in reader:
70 88
        term = row[term_col]
71 89
        sources = row[sources_col].split(source_sep)

Also available in: Unified diff