Commit | Line | Data |
---|---|---|
a028c28a | 1 | import signal |
cb87ff89 | 2 | import hashlib |
bde0c540 JR |
3 | import os |
4 | import time | |
a028c28a | 5 | |
85a9e11c JR |
6 | def line_count(file_path): |
7 | line_count = 0 | |
8 | with open(file_path) as f: | |
9 | for line in f: | |
10 | line_count += 1 | |
11 | return line_count | |
a028c28a JR |
12 | |
13 | ||
cb87ff89 JR |
14 | def sha256_checksum(filename, block_size=65536): |
15 | sha256 = hashlib.sha256() | |
16 | with open(filename, 'rb') as f: | |
17 | for block in iter(lambda: f.read(block_size), b''): | |
18 | sha256.update(block) | |
19 | return sha256.hexdigest() | |
20 | ||
21 | ||
bde0c540 JR |
22 | # TODO: timeout as a parameter or Settings |
23 | # TODO: Custom exception | |
24 | def wait_for_file(path): | |
25 | i = 0 | |
26 | timeout = 60 | |
27 | while not os.path.exists(path): | |
28 | time.sleep(1) | |
29 | i = i + 1 | |
30 | if i > timeout: | |
31 | raise Exception("File still does not exists. Timeout expired") | |
32 | ||
33 | ||
34 | # TODO: find better exception | |
35 | def create_empty_file(path): | |
36 | if os.path.exists(path): | |
37 | raise Exception("Path already exist") | |
38 | open(path, 'w').close() | |
39 | ||
40 | ||
a028c28a JR |
41 | def __dummy_sigusr1_handler(): |
42 | pass | |
43 | ||
44 | ||
45 | def sessiond_spawn(runtime): | |
29cf55b3 JR |
46 | previous_handler = signal.signal(signal.SIGUSR1, __dummy_sigusr1_handler) |
47 | sessiond = runtime.spawn_subprocess("lttng-sessiond -vvv -S") | |
48 | signal.sigtimedwait({signal.SIGUSR1}, 60) | |
49 | previous_handler = signal.signal(signal.SIGUSR1, previous_handler) | |
50 | return sessiond | |
51 | ||
52 | ||
53 | ||
f4711e68 JR |
54 | |
55 | def file_contains(stderr_file, list_of_string): | |
56 | with open(stderr_file, 'r') as stderr: | |
57 | for line in stderr: | |
58 | for s in list_of_string: | |
59 | if s in line: | |
60 | return True |