1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
with open('cr_fixes.xml') as file:
    xmlfile = file.read()

def CRlistToTable(CRlist):
    cols = CRlist[0] # first item is header-row of col names on the first line
    CRstrings = ['<table cellspacing="1" cellpadding="1" border="1">']
    # table header row
    CRstrings.append('  <tr>')
    for col in cols:
        CRstrings.append('    <th bgcolor="#67B0F9" scope="col">{}</th>'.format(col))
    CRstrings.append('  </tr>')
        # create a template for each table row
    TR_TEMPLATE = ['  <tr>']
    for items in CRlist[0]:
        if "," in items[0]:
            print "IN ,"
        else:
            TR_TEMPLATE.append(
                '    <td><a href="http://prism/CR/{{{}}}">{{{}}}</a></td>'.format(*[cols[0]]*2))

    for col in cols[1:]:
        TR_TEMPLATE.append('    <td>{{}}</td>'.format(col))
    TR_TEMPLATE.append('  </tr>')
    TR_TEMPLATE = '\n'.join(TR_TEMPLATE)
        # then apply the template to all the non-header rows of CRlist
    for items in CRlist[1:]:
        CRstrings.append(TR_TEMPLATE.format(CR=items[0], *items[1:]))
    CRstrings.append("</table>")

    return '\n'.join(CRstrings) + '\n'

FIXES_START_TAG, FIXES_END_TAG = '<Fixes>, </Fixes>'.replace(',', ' ').split()
CRsFixesStart = xmlfile.find(FIXES_START_TAG) + len(FIXES_START_TAG)
CRsFixesEnd = xmlfile.find(FIXES_END_TAG)
info = xmlfile[CRsFixesStart:CRsFixesEnd].strip().splitlines()

# first line of extracted info is a blank-separated list of column names
num_cols = len(info[0].split())

# split non-blank lines of info into list of columnar data
# assuming last col is the variable-length title, comprising reminder of line
CRlist = [line.split('\t', num_cols-1) for line in info if line]

# convert list into html table
crInfo = CRlistToTable(CRlist)
print crInfo