|
@@
-1,349
+1,422
|
|
1
|
1
|
'''
|
|
2
|
2
|
Created on September , 2012
|
|
3
|
3
|
@author:
|
|
4
|
4
|
'''
|
|
5
|
5
|
from xml.etree.ElementTree import Element, SubElement, ElementTree
|
|
6
|
6
|
from xml.etree import ElementTree as ET
|
|
7
|
7
|
from xml.dom import minidom
|
|
8
|
8
|
|
|
9
|
9
|
import sys
|
|
10
|
10
|
|
|
11
|
11
|
def prettify(elem):
|
|
12
|
12
|
"""Return a pretty-printed XML string for the Element.
|
|
13
|
13
|
"""
|
|
14
|
14
|
rough_string = ET.tostring(elem, 'utf-8')
|
|
15
|
15
|
reparsed = minidom.parseString(rough_string)
|
|
16
|
16
|
return reparsed.toprettyxml(indent=" ")
|
|
17
|
17
|
|
|
18
|
18
|
#def save(a, b):
|
|
19
|
19
|
#
|
|
20
|
20
|
# nameP = "Alexnder"
|
|
21
|
21
|
# descripcion = self.projectWindow.Text()
|
|
22
|
22
|
# id = 1
|
|
23
|
23
|
# x = self.data.projectWindow.cmbbox.value()
|
|
24
|
24
|
#
|
|
25
|
25
|
# projectObj = Controller(id, name, description)
|
|
26
|
26
|
#
|
|
27
|
27
|
# projectObj.setup(id, name, description)
|
|
28
|
28
|
|
|
29
|
29
|
class Controller():
|
|
30
|
30
|
|
|
31
|
31
|
id = None
|
|
32
|
32
|
name = None
|
|
33
|
33
|
description = None
|
|
34
|
34
|
readBranchObjList = None
|
|
35
|
35
|
procBranchObjList = None
|
|
36
|
36
|
|
|
37
|
37
|
def __init__(self):
|
|
38
|
38
|
|
|
39
|
39
|
# self.id = id
|
|
40
|
40
|
# self.name = name
|
|
41
|
41
|
# self.description = description
|
|
42
|
42
|
|
|
43
|
43
|
self.readBranchObjList = []
|
|
44
|
44
|
self.procBranchObjList = []
|
|
45
|
45
|
|
|
46
|
46
|
def setParms(self, id, name, description):
|
|
47
|
47
|
|
|
48
|
48
|
self.id = id
|
|
49
|
49
|
self.name = name
|
|
50
|
50
|
self.description = description
|
|
51
|
51
|
|
|
52
|
52
|
def addReadBranch(self, dpath, dataformat, readMode, startDate='', endDate='', startTime='', endTime=''):
|
|
53
|
53
|
|
|
54
|
54
|
id = len(self.readBranchObjList) + 1
|
|
55
|
55
|
|
|
56
|
|
readBranchObj = ReadBranch(id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime)
|
|
|
56
|
readBranchObj = ReadBranch()
|
|
|
57
|
readBranchObj.setup(id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime)
|
|
57
|
58
|
|
|
58
|
59
|
self.readBranchObjList.append(readBranchObj)
|
|
59
|
60
|
|
|
60
|
61
|
return readBranchObj
|
|
61
|
62
|
|
|
62
|
63
|
def addProcBranch(self, name):
|
|
63
|
64
|
|
|
64
|
65
|
id = len(self.procBranchObjList) + 1
|
|
65
|
66
|
|
|
66
|
|
procBranchObj = ProcBranch(id, name)
|
|
|
67
|
procBranchObj = ProcBranch()
|
|
|
68
|
procBranchObj.setup(id, name)
|
|
67
|
69
|
|
|
68
|
70
|
self.procBranchObjList.append(procBranchObj)
|
|
69
|
71
|
|
|
70
|
72
|
return procBranchObj
|
|
71
|
73
|
|
|
72
|
74
|
def makeXml(self):
|
|
73
|
75
|
|
|
74
|
76
|
projectElement = Element('Controller')
|
|
75
|
77
|
projectElement.set('id', str(self.id))
|
|
76
|
78
|
projectElement.set('name', self.name)
|
|
77
|
79
|
#projectElement.set('description', self.description)
|
|
78
|
80
|
|
|
79
|
81
|
se = SubElement(projectElement, 'description',description=self.description)#ESTO ES LO ULTIMO QUE SE TRABAJO
|
|
80
|
82
|
#se.text = self.description #ULTIMA MODIFICACION PARA SACAR UN SUB ELEMENT
|
|
81
|
83
|
|
|
82
|
84
|
for readBranchObj in self.readBranchObjList:
|
|
83
|
85
|
readBranchObj.makeXml(projectElement)
|
|
84
|
86
|
|
|
85
|
87
|
for procBranchObj in self.procBranchObjList:
|
|
86
|
88
|
procBranchObj.makeXml(projectElement)
|
|
87
|
89
|
|
|
88
|
90
|
self.projectElement = projectElement
|
|
89
|
91
|
|
|
90
|
92
|
def writeXml(self, filename):
|
|
91
|
93
|
|
|
92
|
94
|
self.makeXml()
|
|
93
|
95
|
ElementTree(self.projectElement).write(filename, method='xml')
|
|
94
|
96
|
print prettify(self.projectElement)
|
|
95
|
97
|
|
|
96
|
98
|
def readXml(self, filename):
|
|
97
|
99
|
|
|
98
|
100
|
#tree = ET.parse(filename)
|
|
99
|
101
|
self.projectElement = None
|
|
100
|
|
tree = ElementTree(self.projectElement).parse(filename)
|
|
|
102
|
self.readBranchObjList = None
|
|
|
103
|
self.procBranchObjList = None
|
|
|
104
|
|
|
|
105
|
self.projectElement = ElementTree().parse(filename)
|
|
101
|
106
|
|
|
102
|
107
|
self.project = self.projectElement.tag
|
|
103
|
108
|
|
|
104
|
109
|
self.id = self.projectElement.get('id')
|
|
105
|
|
self.name = self.projectElement.get('name')
|
|
106
|
|
|
|
107
|
|
readElement = self.projectElement.getiterator('readBranch')
|
|
108
|
|
|
|
109
|
|
root = tree.getroot()
|
|
110
|
|
self.project = root.tag
|
|
111
|
|
self.id = root.attrib.get('id')
|
|
112
|
|
self.name = root.attrib.get('name')
|
|
113
|
|
|
|
114
|
|
for description in root.findall('description'):
|
|
115
|
|
description = description.get('description')
|
|
116
|
|
|
|
117
|
|
self.description= description
|
|
118
|
|
|
|
119
|
|
for readBranch in root.findall('readBranch'):
|
|
120
|
|
id = readBranch.get('id')
|
|
121
|
|
self.idrb=id
|
|
122
|
|
|
|
123
|
|
for procBranch in root.findall('procBranch'):
|
|
124
|
|
id = readBranch.get('id')
|
|
125
|
|
name = readBranch.get('name')
|
|
126
|
|
self.idpb=id
|
|
127
|
|
self.nameBranch=name
|
|
128
|
|
|
|
129
|
|
root=tree.getroot()
|
|
130
|
|
print root.tag , root.attrib
|
|
131
|
|
for child in root:
|
|
132
|
|
print child.tag ,child.attrib
|
|
133
|
|
for child in child:
|
|
134
|
|
print child.tag ,child.attrib
|
|
135
|
|
for child in child:
|
|
136
|
|
print child.tag ,child.attrib
|
|
137
|
|
for child in child:
|
|
138
|
|
print child.tag ,child.attrib
|
|
|
110
|
self.name = self.projectElement.get('name')
|
|
|
111
|
|
|
|
112
|
self.readBranchObjList = []
|
|
|
113
|
|
|
|
114
|
readBranchElementList = self.projectElement.getiterator('readBranch')
|
|
|
115
|
|
|
|
116
|
for readBranchElement in readBranchElementList:
|
|
|
117
|
readBrachObj = ReadBranch()
|
|
|
118
|
readBrachObj.readXml(readBranchElement)
|
|
|
119
|
self.readBranchObjList.append(readBranchObj)
|
|
|
120
|
|
|
|
121
|
self.procBranchObjList = []
|
|
|
122
|
|
|
|
123
|
procBranchElementList = self.projectElement.getiterator('procBranch')
|
|
|
124
|
|
|
|
125
|
for procBranchElement in procBranchElementList:
|
|
|
126
|
procBranchObj = ProcBranch()
|
|
|
127
|
procBranchObj.readXml(procBranchElement)
|
|
|
128
|
self.procBranchObjList.append(procBranchObj)
|
|
139
|
129
|
#
|
|
140
|
130
|
class ReadBranch():
|
|
141
|
131
|
|
|
142
|
132
|
id = None
|
|
143
|
|
dpath = None
|
|
144
|
|
dataformat = None
|
|
145
|
|
readMode = None
|
|
146
|
|
startDate = None
|
|
147
|
|
endDate = None
|
|
148
|
|
startTime = None
|
|
149
|
|
endTime = None
|
|
|
133
|
# dpath = None
|
|
|
134
|
# dataformat = None
|
|
|
135
|
# readMode = None
|
|
|
136
|
# startDate = None
|
|
|
137
|
# endDate = None
|
|
|
138
|
# startTime = None
|
|
|
139
|
# endTime = None
|
|
|
140
|
|
|
|
141
|
parmObjList = []
|
|
150
|
142
|
|
|
151
|
|
def __init__(self, id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime):
|
|
|
143
|
def __init__(self):
|
|
|
144
|
|
|
|
145
|
self.parmObjList = []
|
|
|
146
|
|
|
|
147
|
def setup(self, id, dpath, dataformat, readMode, startDate, endDate, startTime, endTime):
|
|
152
|
148
|
|
|
153
|
149
|
self.id = id
|
|
154
|
150
|
self.dpath = dpath
|
|
155
|
151
|
self.dataformat = dataformat
|
|
156
|
152
|
self.readMode = readMode
|
|
157
|
153
|
self.startDate = startDate
|
|
158
|
154
|
self.endDate = endDate
|
|
159
|
155
|
self.startTime = startTime
|
|
160
|
156
|
self.endTime = endTime
|
|
161
|
157
|
|
|
|
158
|
def addParameter(self, name, value):
|
|
|
159
|
|
|
|
160
|
id = len(self.parmObjList) + 1
|
|
|
161
|
|
|
|
162
|
parmObj = ParameterConf()
|
|
|
163
|
parmObj.setup(id, name, value)
|
|
|
164
|
|
|
|
165
|
self.parmObjList.append(parmObj)
|
|
|
166
|
|
|
|
167
|
return parmObj
|
|
|
168
|
|
|
162
|
169
|
def makeXml(self, projectElement):
|
|
163
|
170
|
|
|
164
|
171
|
readBranchElement = SubElement(projectElement, 'readBranch')
|
|
165
|
172
|
readBranchElement.set('id', str(self.id))
|
|
|
173
|
|
|
|
174
|
self.addParameter(name='dpath' , value=self.dpath)
|
|
|
175
|
self.addParameter(name='dataformat', value=self.dataformat)
|
|
|
176
|
self.addParameter(name='startDate' , value=self.startDate)
|
|
|
177
|
self.addParameter(name='endDate' , value=self.endDate)
|
|
|
178
|
self.addParameter(name='startTime' , value=self.startTime)
|
|
|
179
|
self.addParameter(name='endTime' , value=self.endTime)
|
|
|
180
|
self.addParameter(name='readMode' , value=str(self.readMode))
|
|
|
181
|
|
|
|
182
|
for parmObj in self.parmObjList:
|
|
|
183
|
parmObj.makeXml(readBranchElement)
|
|
|
184
|
|
|
|
185
|
def readXml(self, readBranchElement):
|
|
|
186
|
|
|
|
187
|
self.id = readBranchElement.get('id')
|
|
|
188
|
|
|
|
189
|
self.parmObjList = []
|
|
|
190
|
|
|
|
191
|
parmElementList = readBranchElement.getiterator('Parameter')
|
|
|
192
|
|
|
|
193
|
for parmElement in parmElementList:
|
|
|
194
|
parmObj = Parameter()
|
|
|
195
|
parmObj.readXml(parmElement)
|
|
|
196
|
self.parmObjList.append(parmObj)
|
|
166
|
197
|
|
|
167
|
|
se = SubElement(readBranchElement, 'parameter', name='dpath' , value=self.dpath)
|
|
168
|
|
se = SubElement(readBranchElement, 'parameter', name='dataformat', value=self.dataformat)
|
|
169
|
|
se = SubElement(readBranchElement, 'parameter', name='startDate' , value=self.startDate)
|
|
170
|
|
se = SubElement(readBranchElement, 'parameter', name='endDate' , value=self.endDate)
|
|
171
|
|
se = SubElement(readBranchElement, 'parameter', name='startTime' , value=self.startTime)
|
|
172
|
|
se = SubElement(readBranchElement, 'parameter', name='endTime' , value=self.endTime)
|
|
173
|
|
se = SubElement(readBranchElement, 'parameter', name='readMode' , value=str(self.readMode))
|
|
174
|
|
|
|
175
|
198
|
|
|
176
|
199
|
class ProcBranch():
|
|
177
|
200
|
|
|
178
|
201
|
id = None
|
|
179
|
202
|
name = None
|
|
180
|
203
|
|
|
181
|
204
|
upObjList = None
|
|
182
|
205
|
|
|
183
|
|
def __init__(self, id, name):
|
|
|
206
|
def __init__(self):
|
|
|
207
|
pass
|
|
|
208
|
|
|
|
209
|
def setup(self, id, name):
|
|
184
|
210
|
|
|
185
|
211
|
self.id = id
|
|
186
|
212
|
self.name = name
|
|
187
|
213
|
|
|
188
|
214
|
self.upObjList = []
|
|
189
|
215
|
|
|
190
|
216
|
def addUP(self, name, type):
|
|
191
|
217
|
|
|
192
|
218
|
id = len(self.upObjList) + 1
|
|
193
|
219
|
|
|
194
|
|
upObj = UPConf(id, name, type)
|
|
|
220
|
upObj = UPConf()
|
|
|
221
|
upObj.setup(id, name, type)
|
|
195
|
222
|
|
|
196
|
223
|
self.upObjList.append(upObj)
|
|
197
|
224
|
|
|
198
|
225
|
return upObj
|
|
199
|
226
|
|
|
200
|
227
|
def makeXml(self, projectElement):
|
|
201
|
228
|
|
|
202
|
229
|
procBranchElement = SubElement(projectElement, 'procBranch')
|
|
203
|
230
|
procBranchElement.set('id', str(self.id))
|
|
204
|
231
|
procBranchElement.set('name', self.name)
|
|
205
|
232
|
|
|
206
|
233
|
for upObj in self.upObjList:
|
|
207
|
234
|
upObj.makeXml(procBranchElement)
|
|
208
|
235
|
|
|
|
236
|
def readXml(self, procBranchElement):
|
|
|
237
|
|
|
|
238
|
self.id = procBranchElement.get('id')
|
|
|
239
|
self.name = procBranchElement.get('name')
|
|
|
240
|
|
|
|
241
|
self.upObjList = []
|
|
|
242
|
|
|
|
243
|
upElementList = procBranchElement.getiterator('UP')
|
|
|
244
|
|
|
|
245
|
for upElement in upElementList:
|
|
|
246
|
upObj = UPConf()
|
|
|
247
|
#upObj.readXml(upElement)
|
|
|
248
|
self.upObjList.append(upObj)
|
|
|
249
|
|
|
209
|
250
|
class UPConf():
|
|
210
|
251
|
|
|
211
|
252
|
id = None
|
|
212
|
253
|
name = None
|
|
213
|
254
|
type = None
|
|
214
|
255
|
|
|
215
|
256
|
opObjList = []
|
|
216
|
257
|
|
|
217
|
|
def __init__(self, id, name, type):
|
|
|
258
|
def __init__(self):
|
|
|
259
|
pass
|
|
|
260
|
|
|
|
261
|
def setup(self, id, name, type):
|
|
218
|
262
|
|
|
219
|
263
|
self.id = id
|
|
220
|
264
|
self.name = name
|
|
221
|
265
|
self.type = type
|
|
222
|
266
|
|
|
223
|
267
|
self.opObjList = []
|
|
224
|
268
|
|
|
225
|
269
|
def addOperation(self, name, priority, type='self'):
|
|
226
|
270
|
|
|
227
|
271
|
id = len(self.opObjList) + 1
|
|
228
|
272
|
|
|
229
|
|
opObj = OperationConf(id, name, priority, type)
|
|
|
273
|
opObj = OperationConf()
|
|
|
274
|
opObj.setup(id, name, priority, type)
|
|
230
|
275
|
|
|
231
|
276
|
self.opObjList.append(opObj)
|
|
232
|
277
|
|
|
233
|
278
|
return opObj
|
|
234
|
279
|
|
|
235
|
280
|
def makeXml(self, procBranchElement):
|
|
236
|
281
|
|
|
237
|
282
|
upElement = SubElement(procBranchElement, 'UP')
|
|
238
|
283
|
upElement.set('id', str(self.id))
|
|
239
|
284
|
upElement.set('name', self.name)
|
|
240
|
285
|
upElement.set('type', self.type)
|
|
241
|
286
|
|
|
242
|
287
|
for opObj in self.opObjList:
|
|
243
|
288
|
opObj.makeXml(upElement)
|
|
244
|
289
|
|
|
|
290
|
def readXml(self, upElement):
|
|
|
291
|
|
|
|
292
|
self.id = upElement.get('id')
|
|
|
293
|
self.name = upElement.get('name')
|
|
|
294
|
self.type = upElement.get('type')
|
|
|
295
|
|
|
|
296
|
opElementList = upElement.getiterator('Operation')
|
|
|
297
|
|
|
|
298
|
for opElement in opElementList:
|
|
|
299
|
pass
|
|
|
300
|
|
|
245
|
301
|
def getOperationObjList(self):
|
|
246
|
302
|
|
|
247
|
303
|
return self.opObjList
|
|
248
|
304
|
|
|
249
|
305
|
class OperationConf():
|
|
250
|
306
|
|
|
251
|
307
|
id = 0
|
|
252
|
308
|
name = None
|
|
253
|
309
|
priority = None
|
|
254
|
310
|
type = 'self'
|
|
255
|
311
|
|
|
256
|
312
|
parmObjList = []
|
|
257
|
313
|
|
|
258
|
|
def __init__(self, id, name, priority, type):
|
|
|
314
|
def __init__(self):
|
|
|
315
|
pass
|
|
|
316
|
|
|
|
317
|
def setup(self, id, name, priority, type):
|
|
259
|
318
|
|
|
260
|
319
|
self.id = id
|
|
261
|
320
|
self.name = name
|
|
262
|
321
|
self.priority = priority
|
|
263
|
322
|
self.type = type
|
|
264
|
323
|
|
|
265
|
324
|
self.parmObjList = []
|
|
266
|
325
|
|
|
267
|
326
|
def addParameter(self, name, value):
|
|
268
|
327
|
|
|
269
|
328
|
id = len(self.parmObjList) + 1
|
|
270
|
329
|
|
|
271
|
|
parmObj = ParameterConf(id, name, value)
|
|
|
330
|
parmObj = ParameterConf()
|
|
|
331
|
parmObj.setup(id, name, value)
|
|
272
|
332
|
|
|
273
|
333
|
self.parmObjList.append(parmObj)
|
|
274
|
334
|
|
|
275
|
335
|
return parmObj
|
|
276
|
336
|
|
|
277
|
337
|
def makeXml(self, upElement):
|
|
278
|
338
|
|
|
279
|
339
|
opElement = SubElement(upElement, 'Operation')
|
|
280
|
340
|
opElement.set('id', str(self.id))
|
|
281
|
341
|
opElement.set('name', self.name)
|
|
282
|
342
|
opElement.set('priority', str(self.priority))
|
|
283
|
343
|
|
|
284
|
344
|
for parmObj in self.parmObjList:
|
|
285
|
345
|
parmObj.makeXml(opElement)
|
|
|
346
|
|
|
|
347
|
def readXml(self, opElement):
|
|
|
348
|
|
|
|
349
|
self.id = opElement.get('id')
|
|
|
350
|
self.name = opElement.get('name')
|
|
|
351
|
self.type = opElement.get('type')
|
|
|
352
|
|
|
|
353
|
parmElementList = opElement.getiterator('Parameter')
|
|
|
354
|
|
|
|
355
|
for parmElement in parmElementList:
|
|
|
356
|
pass
|
|
286
|
357
|
|
|
287
|
358
|
def getParameterObjList(self):
|
|
288
|
359
|
|
|
289
|
360
|
return self.parmObjList
|
|
290
|
361
|
|
|
291
|
362
|
class ParameterConf():
|
|
292
|
363
|
|
|
293
|
364
|
id = None
|
|
294
|
365
|
name = None
|
|
295
|
366
|
value = None
|
|
296
|
367
|
|
|
297
|
|
def __init__(self, id, name, value):
|
|
|
368
|
def __init__(self):
|
|
|
369
|
pass
|
|
|
370
|
|
|
|
371
|
def setup(self, id, name, value):
|
|
298
|
372
|
|
|
299
|
373
|
self.id = id
|
|
300
|
374
|
self.name = name
|
|
301
|
375
|
self.value = value
|
|
302
|
376
|
|
|
303
|
377
|
def makeXml(self, opElement):
|
|
304
|
378
|
|
|
305
|
379
|
parmElement = SubElement(opElement, 'Parameter')
|
|
306
|
380
|
parmElement.set('name', self.name)
|
|
307
|
381
|
parmElement.set('value', self.value)
|
|
308
|
382
|
|
|
309
|
|
def readXml(self, opElement):
|
|
310
|
|
|
|
|
383
|
def readXml(self, parmElement):
|
|
311
|
384
|
|
|
312
|
|
pass
|
|
313
|
|
# se = SubElement(parmElement, 'value')#ESTO ES LO ULTIMO QUE SE TRABAJO
|
|
314
|
|
# se.text = self.value
|
|
|
385
|
self.id = parmElement.get('id')
|
|
|
386
|
self.name = parmElement.get('name')
|
|
|
387
|
self.value = parmElement.get('value')
|
|
315
|
388
|
|
|
316
|
389
|
if __name__ == '__main__':
|
|
317
|
390
|
|
|
318
|
391
|
desc = "Este es un test"
|
|
319
|
392
|
filename = "test.xml"
|
|
320
|
393
|
|
|
321
|
394
|
projectObj = Controller()
|
|
322
|
395
|
|
|
323
|
396
|
projectObj.setParms(id = '11', name='test01', description=desc)
|
|
324
|
397
|
|
|
325
|
398
|
readBranchObj = projectObj.addReadBranch(dpath='mydata', dataformat='rawdata', readMode=0, startDate='1', endDate='3', startTime='4', endTime='5')
|
|
326
|
399
|
|
|
327
|
400
|
procBranchObj = projectObj.addProcBranch(name='Branch1')
|
|
328
|
401
|
|
|
329
|
402
|
procBranchObj1 = projectObj.addProcBranch(name='Branch2')
|
|
330
|
403
|
upObj1 = procBranchObj.addUP(name='UP1', type='Voltage')
|
|
331
|
404
|
upObj2 = procBranchObj.addUP(name='UP2', type='Voltage')
|
|
332
|
405
|
|
|
333
|
406
|
opObj11 = upObj1.addOperation(name='removeDC', priority=1)
|
|
334
|
407
|
opObj11.addParameter(name='type', value='1')
|
|
335
|
408
|
|
|
336
|
409
|
|
|
337
|
410
|
opObj12 = upObj1.addOperation(name='decodification', priority=2)
|
|
338
|
411
|
opObj12.addParameter(name='ncode', value='2')
|
|
339
|
412
|
opObj12.addParameter(name='nbauds', value='8')
|
|
340
|
413
|
opObj12.addParameter(name='code1', value='001110011')
|
|
341
|
414
|
opObj12.addParameter(name='code2', value='001110011')
|
|
342
|
415
|
|
|
343
|
416
|
print "Escribiendo el XML"
|
|
344
|
417
|
|
|
345
|
418
|
projectObj.writeXml(filename)
|
|
346
|
419
|
|
|
347
|
420
|
print "Leyendo el XML"
|
|
348
|
421
|
projectObj.readXml(filename)
|
|
349
|
422
|
No newline at end of file
|