+
+ shift = int(args.level)
+ start = int(args.start)
+
+ output = open(args.output, 'w')
+
+ for item in data:
+ if int(item['level']) < start:
+ continue
+ if 'ndrchk' in item['title'].lower():
+ continue
+ mark = "=" * (int(item['level']) - start + shift) + ' '
+ output.write(mark + item['title'].lower() + mark + '\n')
+ output.write(item['doc'].replace('*', "'''").replace('|br|', '\n*') +
+ '\n')
+ try:
+ output.write(gen_wiki_table(item['tests']) + '\n\n')
+ except KeyError:
+ continue
+ output.close()
+
+
+def gen_wiki_table(data):
+ """Generates a table with TCs' names, documentation and messages / statuses
+ in wiki format.
+
+ :param data: Json data representing a table with TCs.
+ :type data: str
+ :returns: Table with TCs' names, documentation and messages / statuses in
+ wiki format.
+ :rtype: str
+ """
+
+ table = '{| class="wikitable"\n'
+ header = ""
+ for item in data[-1]:
+ header += '!{}\n'.format(item)
+ table += header
+ for item in data[0:-1]:
+ desc = re.sub(r'(^ \|br\| )', r'', item[1]).replace(' |br| ', '\n\n')
+ msg = item[2].replace(' |br| ', '\n\n')
+ table += '|-\n|{}\n|{}\n|{}\n'.format(item[0], desc, msg)
+ table += '|}\n'
+
+ return table