+
+def do_html(data, args):
+ """Generation of a html file from json data.
+
+ :param data: List of suites from json file.
+ :param args: Parsed arguments.
+ :type data: list of dict
+ :type args: ArgumentParser
+ :returns: Nothing.
+ """
+
+ shift = int(args.level)
+ start = int(args.start)
+
+ output = open(args.output, 'w')
+
+ output.write('<html>')
+ for item in data:
+ if int(item['level']) < start:
+ continue
+ level = str(int(item['level']) - start + shift)
+ output.write('<h' + level + '>' + item['title'].lower() +
+ '</h' + level + '>')
+ output.write('<p>' + re.sub(r"(\*)(.*?)(\*)", r"<b>\2</b>", item['doc'],
+ 0, flags=re.MULTILINE).
+ replace(' |br| ', '<br>') + '</p>')
+ try:
+ output.write(gen_html_table(item['tests']))
+ except KeyError:
+ continue
+ output.write('</html>')
+ output.close()
+
+
+def gen_html_table(data):
+ """Generates a table with TCs' names, documentation and messages / statuses
+ in html format. There is no css used.
+
+ :param data: Json data representing a table with TCs.
+ :type data: str
+ :returns: Table with TCs' names, documentation and messages / statuses in
+ html format.
+ :rtype: str
+ """
+
+ table = '<table width=100% border=1><tr>'
+ table += '<th width=30%>Name</th>'
+ table += '<th width=50%>Documentation</th>'
+ table += '<th width=20%>Status</th></tr>'
+
+ for item in data[0:-2]:
+ table += '<tr>'
+ for element in item:
+ table += '<td>' + element.replace(' |br| ', '<br>') + '</td>'
+ table += '</tr></table>'
+
+ return table
+
+
+def do_rst(data, args):
+ """Generation of a rst file from json data.
+
+ :param data: List of suites from json file.
+ :param args: Parsed arguments.
+ :type data: list of dict
+ :type args: ArgumentParser
+ :returns: Nothing.
+ """
+
+ hdrs = ['=', '-', '`', "'", '.', '~', '*', '+', '^']
+ shift = int(args.level)
+ start = int(args.start)
+
+ output = open(args.output, 'w')
+ output.write('\n.. |br| raw:: html\n\n <br />\n\n')
+
+ for item in data:
+ if int(item['level']) < start:
+ continue
+ if 'ndrchk' in item['title'].lower():
+ continue
+ output.write(item['title'].lower() + '\n' +
+ hdrs[int(item['level']) - start + shift] *
+ len(item['title']) + '\n\n')
+ output.write(item['doc'].replace('*', '**').replace('|br|', '\n\n -') +
+ '\n\n')
+ try:
+ output.write(gen_rst_table(item['tests']) + '\n\n')
+ except KeyError:
+ continue
+ output.close()
+
+
+def gen_rst_table(data):
+ """Generates a table with TCs' names, documentation and messages / statuses
+ in rst format.
+
+ :param data: Json data representing a table with TCs.
+ :type data: str
+ :returns: Table with TCs' names, documentation and messages / statuses in
+ rst format.
+ :rtype: str
+ """
+
+ table = []
+ # max size of each column
+ lengths = map(max, zip(*[[len(str(elt)) for elt in item] for item in data]))
+
+ start_of_line = '| '
+ vert_separator = ' | '
+ end_of_line = ' |'
+ line_marker = '-'
+
+ meta_template = vert_separator.join(['{{{{{0}:{{{0}}}}}}}'.format(i)
+ for i in range(len(lengths))])
+ template = '{0}{1}{2}'.format(start_of_line, meta_template.format(*lengths),
+ end_of_line)
+ # determine top/bottom borders
+ to_separator = string.maketrans('| ', '+-')
+ start_of_line = start_of_line.translate(to_separator)
+ vert_separator = vert_separator.translate(to_separator)
+ end_of_line = end_of_line.translate(to_separator)
+ separator = '{0}{1}{2}'.format(start_of_line, vert_separator.
+ join([x * line_marker for x in lengths]),
+ end_of_line)
+ # determine header separator
+ th_separator_tr = string.maketrans('-', '=')
+ start_of_line = start_of_line.translate(th_separator_tr)
+ line_marker = line_marker.translate(th_separator_tr)
+ vertical_separator = vert_separator.translate(th_separator_tr)
+ end_of_line = end_of_line.translate(th_separator_tr)
+ th_separator = '{0}{1}{2}'.format(start_of_line, vertical_separator.
+ join([x * line_marker for x in lengths]),
+ end_of_line)
+ # prepare table
+ table.append(separator)
+ # set table header
+ titles = data[-1]
+ table.append(template.format(*titles))
+ table.append(th_separator)
+ # generate table rows
+ for d in data[0:-2]:
+ table.append(template.format(*d))
+ table.append(separator)
+ table.append(template.format(*data[-2]))
+ table.append(separator)
+ return '\n'.join(table)
+
+
+def do_md(data, args):
+ """Generation of a rst file from json data.
+
+ :param data: List of suites from json file.
+ :param args: Parsed arguments.
+ :type data: list of dict
+ :type args: ArgumentParser
+ :returns: Nothing.
+ """
+ raise NotImplementedError("Export to 'md' format is not implemented.")
+
+
+def do_wiki(data, args):
+ """Generation of a wiki page from json data.
+
+ :param data: List of suites from json file.
+ :param args: Parsed arguments.
+ :type data: list of dict
+ :type args: ArgumentParser
+ :returns: Nothing.
+ """
+ raise NotImplementedError("Export to 'wiki' format is not implemented.")