Add statedump regen and star globing for ust testing
[deliverable/lttng-ivc.git] / lttng_ivc / utils / utils.py
CommitLineData
a028c28a 1import signal
cb87ff89 2import hashlib
bde0c540
JR
3import os
4import time
a028c28a 5
85a9e11c
JR
6def 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
14def 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
24def 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
35def 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
41def __dummy_sigusr1_handler():
42 pass
43
44
45def 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
This page took 0.025586 seconds and 5 git commands to generate.