1 | |
---|
2 | import xml, string |
---|
3 | import xml.dom, xml.dom.minidom |
---|
4 | import utils_wb |
---|
5 | import re |
---|
6 | import appendEsmVal |
---|
7 | |
---|
8 | empty=re.compile('^$') |
---|
9 | |
---|
10 | import appendViacs_p1 as p1 |
---|
11 | |
---|
12 | print p1.res.keys() |
---|
13 | |
---|
14 | class addViacs(object): |
---|
15 | |
---|
16 | def __init__(self): |
---|
17 | |
---|
18 | src = 'out/annotated_20150731_i1.xml' |
---|
19 | dest = 'out/annotated_20150731.xml' |
---|
20 | self.doc = xml.dom.minidom.parse( src ) |
---|
21 | section = 'requestVar' |
---|
22 | this = self.doc.getElementsByTagName(section)[0] |
---|
23 | for tt in p1.res[section]: |
---|
24 | item = self.doc.createElement( 'item' ) |
---|
25 | item.setAttribute( 'uid', tt[0] ) |
---|
26 | item.setAttribute( 'label', tt[1] ) |
---|
27 | item.setAttribute( 'priority', '1' ) |
---|
28 | item.setAttribute( 'title', '%s: %s' % ( tt[2], tt[1]) ) |
---|
29 | item.setAttribute( 'vid', tt[3] ) |
---|
30 | item.setAttribute( 'vgid', tt[4] ) |
---|
31 | this.appendChild( item ) |
---|
32 | |
---|
33 | section = 'requestLink' |
---|
34 | this = self.doc.getElementsByTagName(section)[0] |
---|
35 | for tt in p1.res[section]: |
---|
36 | item = self.doc.createElement( 'item' ) |
---|
37 | item.setAttribute( 'uid', tt[0] ) |
---|
38 | item.setAttribute( 'objective', tt[1] ) |
---|
39 | item.setAttribute( 'mip', 'VIACSAB' ) |
---|
40 | item.setAttribute( 'label', tt[3] ) |
---|
41 | item.setAttribute( 'title', tt[4] ) |
---|
42 | item.setAttribute( 'refid', tt[5] ) |
---|
43 | this.appendChild( item ) |
---|
44 | |
---|
45 | section = 'requestItem' |
---|
46 | this = self.doc.getElementsByTagName(section)[0] |
---|
47 | for tt in p1.res[section]: |
---|
48 | item = self.doc.createElement( 'item' ) |
---|
49 | item.setAttribute( 'uid', tt[0] ) |
---|
50 | item.setAttribute( 'rlid', tt[1] ) |
---|
51 | item.setAttribute( 'esid', tt[2] ) |
---|
52 | item.setAttribute( 'mip', 'VIACSAB' ) |
---|
53 | item.setAttribute( 'label', tt[3] ) |
---|
54 | item.setAttribute( 'title', tt[4] ) |
---|
55 | item.setAttribute( 'ny', '160' ) |
---|
56 | item.setAttribute( 'preset', '-1' ) |
---|
57 | t0 = string.split( tt[4], ':' )[0] |
---|
58 | if t0[-2:] == '3b': |
---|
59 | item.setAttribute( 'tslice', '_slice_cfOff' ) |
---|
60 | item.setAttribute( 'nenmax', '-1' ) |
---|
61 | item.setAttribute( 'nymax', '1' ) |
---|
62 | elif t0[-1] == 'c': |
---|
63 | item.setAttribute( 'nenmax', '1' ) |
---|
64 | item.setAttribute( 'nymax', '160' ) |
---|
65 | elif t0[-1] == 'd': |
---|
66 | item.setAttribute( 'nenmax', '1' ) |
---|
67 | item.setAttribute( 'nymax', '40' ) |
---|
68 | else: |
---|
69 | item.setAttribute( 'nenmax', '-1' ) |
---|
70 | item.setAttribute( 'nymax', '-1' ) |
---|
71 | this.appendChild( item ) |
---|
72 | |
---|
73 | section = 'objective' |
---|
74 | this = self.doc.getElementsByTagName(section)[0] |
---|
75 | for tt in p1.res[section]: |
---|
76 | item = self.doc.createElement( 'item' ) |
---|
77 | item.setAttribute( 'uid', tt[0] ) |
---|
78 | item.setAttribute( 'mip', tt[1] ) |
---|
79 | item.setAttribute( 'label', tt[2] ) |
---|
80 | item.setAttribute( 'title', tt[3] ) |
---|
81 | item.setAttribute( 'description', tt[4] ) |
---|
82 | this.appendChild( item ) |
---|
83 | |
---|
84 | section = 'objectiveLink' |
---|
85 | this = self.doc.getElementsByTagName(section)[0] |
---|
86 | for tt in p1.res[section]: |
---|
87 | item = self.doc.createElement( 'item' ) |
---|
88 | item.setAttribute( 'uid', tt[0] ) |
---|
89 | item.setAttribute( 'label', tt[1] ) |
---|
90 | item.setAttribute( 'title', tt[2] ) |
---|
91 | item.setAttribute( 'oid', tt[3] ) |
---|
92 | item.setAttribute( 'rid', tt[4] ) |
---|
93 | this.appendChild( item ) |
---|
94 | |
---|
95 | |
---|
96 | def write(self): |
---|
97 | txt = self.doc.toprettyxml(indent='\t', newl='\n', encoding=None) |
---|
98 | oo = open( 'out/annotated_20150731.xml', 'w' ) |
---|
99 | lines = string.split( txt, '\n' ) |
---|
100 | for line in lines: |
---|
101 | l = utils_wb.uniCleanFunc( string.strip(line) ) |
---|
102 | if empty.match(l): |
---|
103 | continue |
---|
104 | else: |
---|
105 | oo.write(l + '\n') |
---|
106 | oo.close() |
---|
107 | |
---|
108 | adv = addViacs() |
---|
109 | appendEsmVal.addEsmVal( adv.doc ) |
---|
110 | adv.write() |
---|