b8a1b37a0ca2a95089a3e22c279467eb4e29c328
[deliverable/lttng-ivc.git] / lttng_ivc / utils / utils.py
1 import signal
2 import hashlib
3 import os
4 import time
5
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
12
13
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
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
41 def __dummy_sigusr1_handler():
42 pass
43
44
45 def sessiond_spawn(runtime):
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
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
This page took 0.030748 seconds and 4 git commands to generate.