summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMac Mollison <mollison@cs.unc.edu>2009-02-01 15:39:05 -0500
committerMac Mollison <mollison@cs.unc.edu>2009-02-01 15:39:05 -0500
commit8471eb80c262a6ad66b4c20effaaf3a59adf9aef (patch)
treea4112432d484dc76a271d9cf12e2a447b59e1eb1
parent645d2388371d97cd106f6e68cd9ef7a722010166 (diff)
Created Trace object
-rwxr-xr-xsta.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/sta.py b/sta.py
index 4a53b6e..14617ef 100755
--- a/sta.py
+++ b/sta.py
@@ -10,24 +10,24 @@ from sta_output import *
10from sta_types import * 10from sta_types import *
11 11
12 12
13
14
15################## 13##################
16# Business logic # 14# Business logic #
17################## 15##################
18 16class Trace:
19def trace_iter(files): 17 def __init__(self,files):
20 """Returns an iterator for iterating over trace(s) and producing records.""" 18 self.iter = self.make_iter(files)
21 for file in files: 19 def make_iter(self, files):
22 f = open(file,'rb') 20 for file in files:
23 while True: 21 f = open(file,'rb')
24 try: 22 while True:
25 data = f.read(st_record_size) 23 try:
26 typenum = struct.unpack_from('<b',data)[0] 24 data = f.read(st_record_size)
27 type = get_type(typenum) 25 typenum = struct.unpack_from('<b',data)[0]
28 values = struct.unpack_from(StHeader.format + type.format,data) 26 type = get_type(typenum)
29 record = dict(zip(type.keys,values)) 27 values = struct.unpack_from(StHeader.format +
30 yield record 28 type.format,data)
31 except struct.error: 29 record = dict(zip(type.keys,values))
32 f.close() 30 yield record
33 break 31 except struct.error:
32 f.close()
33 break