This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburt.py
80 lines (73 loc) · 1.91 KB
/
burt.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
"""
usage:
import burt
burt.write("myBurtSnapshotFile.snap", verbose=1)
"""
import sys
import ca
from ca_util import *
# Human readable exception description
# try:
# x = x + 1
# except:
# print formatExceptionInfo()
import sys
import traceback
def formatExceptionInfo(maxTBlevel=5):
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
try:
excArgs = exc.__dict__["args"]
except KeyError:
excArgs = "<no args>"
excTb = traceback.format_tb(trbk, maxTBlevel)
return (excName, excArgs, excTb)
def write(snapFile, verbose=0):
file = open(snapFile, "r")
inBurtHeader = 0
failed_puts = {}
for rawLine in file:
#print "inBurtHeader = ", inBurtHeader, " rawLine=", rawLine
if inBurtHeader:
# look for end
if rawLine[:19] == '--- End BURT header':
inBurtHeader = 0
continue
else:
if rawLine[:21] == '--- Start BURT header':
inBurtHeader = 1
continue
# parse lines of the form: <name> <num> <value>
words = rawLine.split(' ',2)
if len(words) < 3 :
continue
words[2] = words[2].strip('\n').lstrip(' ')
if verbose: print "words=", words
if int(words[1]) != 1:
print "burt.py: Not ready for arrays"
else:
if words[2] == '\\0': words[2] = ""
if (len(words[2]) > 1) and (words[2][0] == '"') and (words[2][-1] == '"'):
words[2] = words[2].strip('"')
if words[2] == ' ': words[2] = ""
if verbose:
print "\ncaput('%s', '%s')" % (words[0], words[2])
try:
caput(words[0], words[2], req_type=ca.DBR_STRING, timeout=3, retries=10, read_check_tolerance=0.001)
except:
failed_puts[words[0]] = words[2]
if verbose:
print formatExceptionInfo()
file.close()
for key in failed_puts.keys():
print "failed to set '%s' to the value '%s'" % (key, failed_puts[key])
del failed_puts
def main():
#print "sys.arvg:", sys.argv
if len(sys.argv) < 2:
print "usage: burt <snapFile>"
return
write(sys.argv[1])
if __name__ == "__main__":
main()