| 9 | |
| 10 | |
| 11 | def readLogFile(filename, verbose=True): |
| 12 | f = open(filename, 'rb') |
| 13 | |
| 14 | print('Opened'), |
| 15 | print(filename) |
| 16 | |
| 17 | keys = f.readline().decode('utf8').rstrip('\n').split(',') |
| 18 | fmt = f.readline().decode('utf8').rstrip('\n') |
| 19 | |
| 20 | # The byte number of one record |
| 21 | sz = struct.calcsize(fmt) |
| 22 | # The type number of one record |
| 23 | ncols = len(fmt) |
| 24 | |
| 25 | if verbose: |
| 26 | print('Keys:'), |
| 27 | print(keys) |
| 28 | print('Format:'), |
| 29 | print(fmt) |
| 30 | print('Size:'), |
| 31 | print(sz) |
| 32 | print('Columns:'), |
| 33 | print(ncols) |
| 34 | |
| 35 | lenChunk = sz |
| 36 | log = list() |
| 37 | chunkIndex = 0 |
| 38 | while (lenChunk): |
| 39 | check = f.read(2) |
| 40 | lenChunk = 0 |
| 41 | if (check == b'\xaa\xbb'): |
| 42 | mychunk = f.read(sz) |
| 43 | lenChunk = len(mychunk) |
| 44 | chunks = [mychunk] |
| 45 | if verbose: |
| 46 | print("num chunks:") |
| 47 | print(len(chunks)) |
| 48 | |
| 49 | for chunk in chunks: |
| 50 | print("len(chunk)=", len(chunk), " sz = ", sz) |
| 51 | if len(chunk) == sz: |
| 52 | print("chunk #", chunkIndex) |
| 53 | chunkIndex = chunkIndex + 1 |
| 54 | values = struct.unpack(fmt, chunk) |
| 55 | record = list() |
| 56 | for i in range(ncols): |
| 57 | record.append(values[i]) |
| 58 | if verbose: |
| 59 | print(" ", keys[i], "=", values[i]) |
| 60 | |
| 61 | log.append(record) |
| 62 | else: |
| 63 | print("Error, expected aabb terminal") |
| 64 | return log |
| 65 | |
| 66 | |
| 67 | numArgs = len(sys.argv) |