1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 import os
40 import xml.dom.minidom
41
42
44
46 self.dir = dir
47 self.params = params
48 self.files = self.get_files()
49
51 list = []
52 for root, dirs, files in os.walk(self.dir):
53 for file in files:
54 list.append(file)
55 return list
56
58 self.files = self.get_files()
59 return file in self.files
60
62 path = self.dir + os.sep + file
63 f = open(path, 'w')
64 f.write(data)
65 f.close()
66
68 path = self.dir + os.sep + file
69 f = open(path, 'r')
70 data = f.read()
71 f.close()
72 return data
73
75 path = self.dir + os.sep + file
76 chunk_size = 0x1000
77 f = open(path, 'r')
78 while True:
79 _chunk = f.read(chunk_size)
80 if not len(_chunk):
81 break
82 yield _chunk
83 f.close()
84
86 file_object.write(chunk)
87
89 list = []
90 path = self.dir + os.sep + file
91 doc = xml.dom.minidom.parse(path)
92 for data in doc.documentElement.getElementsByTagName('data') :
93 name = data.getAttribute('name')
94 id = data.getAttribute('id')
95 unit = data.getAttribute('unit')
96 value = data.getAttribute('value')
97 list.append({'name': name, 'id': id, 'unit': unit, 'value': value})
98 return list
99
101 path = self.dir + os.sep + file
102 doc = xml.dom.minidom.Document()
103 root = doc.createElement('telemeta')
104 doc.appendChild(root)
105 for data in data_list:
106 name = data['name']
107 id = data['id']
108 unit = data['unit']
109 value = data['value']
110 node = doc.createElement('data')
111 node.setAttribute('name', name)
112 node.setAttribute('id', id)
113 node.setAttribute('unit', unit)
114 node.setAttribute('value', str(value))
115 root.appendChild(node)
116 f = open(path, "w")
117 f.write(xml.dom.minidom.Document.toprettyxml(doc))
118 f.close()
119