1#!/usr/bin/env python3
2
3"""Tool to update older syntax reports to newer.
4
5Basically works but needs to use argparse.
6"""
7
8# import sys
9
10# from lxml.etree import Element
11
12# from chart.common.xml import load_xml
13# from chart.common.xml import write_xml
14# from chart.common.xml import parsechildstr
15# from chart.common.xml import is_xml_comment
16
17# elem = load_xml(sys.argv[1])
18
19# name_map = {
20# 'Introduction': 'introduction',
21# 'ListOfFigures': 'list-of-figures',
22# 'TableOfContents': 'table-of-contents',
23# 'MHSImage': 'mhs-image',
24# 'GeoPlot': 'geoplot',
25# 'Heading': 'heading',
26# 'SubHeading': 'subheading',
27# 'SubSubHeading': 'subsubheading',
28# 'Paragraph': 'paragraph',
29# 'Graph': 'graph',
30# 'Title': 'title',
31# 'StatusTable': 'status-table',
32# 'EventsList': 'events-list',
33# 'Limits': 'limits',
34# 'Intelliplot': 'intelliplot',
35# 'LifeLimitedItems': 'life-limited-items',
36# 'NSPTable': 'nsp-table',
37# 'OOLTable': 'ool-table',
38# 'MHSGeoPlot': 'mhs-geoplot',
39# 'Picture': 'picture',
40# }
41
42# for w in elem.findall('widget'):
43# name = parsechildstr(w, 'class')
44# if name in name_map:
45# name = name_map[name]
46
47# w.tag = name
48# w.remove(w.find('class'))
49
50# for param in w.findall('param'):
51# param.tag = parsechildstr(param, 'name')
52# param.remove(param.find('name'))
53# param.text = parsechildstr(param, 'value')
54# param.remove(param.find('value'))
55
56# for i, w in enumerate(elem):
57# # print(dir(w))
58# # print(w.tag)
59# if is_xml_comment(w):
60# continue
61# empty = True
62# for e in w:
63# empty = False
64
65# if w.text is not None and len(w.text.strip()) > 0:
66# empty = False
67
68# if empty:
69# # w.insert(0, Element('empty'))
70# elem.remove(w)
71# elem.insert(i, Element(w.tag))
72
73# # elem.insert(0, Element('hello'))
74
75# write_xml(elem, 'temp.xml', True)
76# temp_elem = load_xml('temp.xml')
77
78# for w in temp_elem:
79# w.tail = '\n\n\t'
80
81# write_xml(temp_elem, 'temp2.xml', False)
82
83# hin = open('temp2.xml', 'rb')
84# hout = open(sys.argv[2], 'wb')
85# hout.write('<?xml version="1.0" encoding="UTF-8"?>\n')
86# h = hin.read()
87# h = h.replace('\t</template', '</template>')
88# h = h.replace(
89# '<template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://chart/schemas/report.xsd">',
90# '<template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\t\t xsi:noNamespaceSchemaLocation="http://chart/schemas/report.xsd">'
91# )
92# hout.write(h)