-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseterminal.py
More file actions
50 lines (44 loc) · 1.63 KB
/
baseterminal.py
File metadata and controls
50 lines (44 loc) · 1.63 KB
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
import sys
import time
import struct
class Error(BaseException):pass
class NotImplementedError(Error):
def __init__(self, functionName, *funtionArgs):
super(NotImplementedError, self).__init__("%s(%s)" % (functionName, ", ".join(funtionArgs)))
class BaseTerminal(object):
def __init__(self):
self.log = open("termdata.log", "w")
self.t0 = int(time.time())
self.notImplLog = open("notImplLog.txt", "w")
def close(self):
self.notImplLog.close();
def delay(self, *delaytime):
delaytime = ";".join(delaytime)
"Delay until relative time in seconds since start is less than the passed value"
#print >>sys.stderr, "".join([r"\x%x" % ord(c) for c in delaytime])
delaytime = struct.unpack("I", delaytime)[0]
resumeTime = self.t0 + delaytime / 1000
#print >>sys.stderr, resumeTime - int(time.time())
while int(time.time() * 1000) < resumeTime:
pass
#print >>sys.stderr,'done'
def render(self, object):
"Takes either a string or action tuple and renders it"
args = []
try:
if type(object) is str:
return self.printString(object)
else:
args = []
for n in object[1:]:
args.extend(n.split(";"))
print >>self.log, object
getattr(self, object[0])(*args)
except NotImplementedError as e:
print >>self.notImplLog, str(e)
self.notImplLog.flush()
except TypeError as e:
print str(e)
print object
print args
raise