Attachment 'CSV.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Processor for CSV data
4
5 @copyright: 2002 by Jürgen Hermann <jh@web.de>
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 Dependencies = []
10
11 def process(request, formatter, lines):
12 # parse bangpath for arguments
13 exclude = []
14 separator=';'
15 for arg in lines[0].split()[1:]:
16 if arg[0] == '-':
17 try:
18 idx = int(arg[1:])
19 except ValueError:
20 pass
21 else:
22 exclude.append(idx-1)
23 else:
24 separator=arg
25
26 # remove bang path, create output list
27 del lines[0]
28 output = []
29
30 if lines[0]:
31 # expect column headers in first line
32 first = 1
33 else:
34 # empty first line, no bold headers
35 first = 0
36 del lines[0]
37
38 output.append(formatter.table(1))
39 for line in lines:
40 output.append(formatter.table_row(1))
41 cells = line.split(separator)
42 for idx in range(len(cells)):
43 if idx in exclude: continue
44 output.append(formatter.table_cell(1))
45 if first: output.append(formatter.strong(1))
46 output.append(formatter.text(cells[idx]))
47 if first: output.append(formatter.strong(0))
48 output.append(formatter.table_cell(0))
49 output.append(formatter.table_row(0))
50 first = 0
51 output.append(formatter.table(0))
52
53 request.write(''.join(output))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.