1 | #!/usr/bin/env python |
2 |
|
3 | import sys |
4 | import os |
5 | import time |
6 | import ctypes |
7 |
|
8 | def exists(f): |
9 | return os.path.isfile(f) or os.path.isdir(f) |
10 |
|
11 | def milli(): |
12 | return int(round(time.time() * 1000)) |
13 |
|
14 | def enc(string): |
15 | return string.encode("latin-1") |
16 |
|
17 | def ushort(n): |
18 | return ctypes.c_ushort(n) |
19 |
|
20 | def uchar(n): |
21 | return ctypes.c_ubyte(n) |
22 |
|
23 | def ulonglong(n): |
24 | return ctypes.c_ulonglong(n) |
25 |
|
26 | if __name__ == "__main__": |
27 | try: |
28 | out = sys.argv[1] |
29 | except: |
30 | print("must provide an out location") |
31 | exit(1) |
32 |
|
33 | version = uchar(1) |
34 | queue_time = ulonglong(milli()) |
35 | open_statement = uchar(0) |
36 | close_statement = uchar(1) |
37 | open_event = uchar(2) |
38 | close_event = uchar(3) |
39 |
|
40 | ts2 = ulonglong(milli()) |
41 | verbosity = uchar(0) |
42 |
|
43 | tag = enc("INIT") |
44 | tag_len = uchar(len(tag)) |
45 |
|
46 | message = enc("HELLO") |
47 | message_len = ushort(len(message)) |
48 |
|
49 | try: |
50 | f = open(out, "wb") |
51 |
|
52 | f.write(version) |
53 | f.write(queue_time) |
54 | f.write(open_event) |
55 | f.write(open_statement) |
56 | f.write(ts2) |
57 | f.write(verbosity) |
58 | f.write(tag_len) |
59 | f.write(tag) |
60 | f.write(message_len) |
61 | f.write(message) |
62 | f.write(close_statement) |
63 | f.write(close_event) |
64 | finally: |
65 | f.close() |
66 | print(os.stat(out).st_size) |
67 |
|
68 |
|
69 |
|