-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetFileData.py
93 lines (71 loc) · 2.91 KB
/
GetFileData.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
81
82
83
84
85
86
87
88
89
90
91
92
93
import GlobalDefinitions
import AISData
from GlobalDefinitions import Global
import time
class FileData:
def __init__(self):
try:
self.f = open("AISdatastream.txt", "r")
except Exception as e:
raise RuntimeError("couldn't open data file " + Global.AISFileName) from e
def ReadAISFile(self):
# reads data from a previously recorded file iof AIS input;
diagnostic = Global.diagnostic
diagnostic2 = Global.diagnostic2
diagnostic3 = Global.diagnostic3
# parameter to allow remote stopping of file read
_keepgoing = True
if diagnostic:
print(" into get File data")
# now start getting tha data - preprocessed then sent on to the Main program via queue
while _keepgoing:
try:
if diagnostic3:
print("Getting Data")
# Blocks until a message returns on this socket from a remote host.
pass
try:
time.sleep(0.1)
stringer = self.f.readline()
except Exception as e:
raise RuntimeError("Error getting data from file", e) from e
if diagnostic3:
if len(stringer) > 0:
print(
" input item from file = ", stringer[0: len(stringer) - 1]
)
if len(stringer) > 0 and ord(stringer[0]) == 33:
# got a record stating with an "!"
if diagnostic3:
print("Got data")
pass
if Global.inputqueue.full():
raise RuntimeError
if diagnostic3:
print("Global Input Queue status = ", Global.inputqueue.full())
if not Global.inputqueue.full():
try:
if diagnostic3:
print("Putting Data into queue", stringer)
pass
Global.inputqueue.put(stringer)
except Exception as e:
raise RuntimeError("error putting item on queue", e) from e
# now throttle this back a bit so we dont choke the main program
else:
# dump record
pass
else:
# dump data
pass
# check if we need stop
_keepgoing = Global._keepgoing
except KeyboardInterrupt as e:
self.f.close()
raise KeyboardInterrupt from e
except Exception as e:
raise RuntimeError("Exception in Get File Data", e) from e
def main(self):
pass
if __name__ == 'main':
main()