9bc9d8c8a47515b6488c382ec12eaed88dacf275
7 from contextlib
import closing
9 def line_count(file_path
):
11 with
open(file_path
) as f
:
17 def sha256_checksum(filename
, block_size
=65536):
18 sha256
= hashlib
.sha256()
19 with
open(filename
, 'rb') as f
:
20 for block
in iter(lambda: f
.read(block_size
), b
''):
22 return sha256
.hexdigest()
25 # TODO: timeout as a parameter or Settings
26 # TODO: Custom exception
27 def wait_for_file(path
):
30 while not os
.path
.exists(path
):
34 raise Exception("File still does not exists. Timeout expired")
37 # TODO: find better exception
38 def create_empty_file(path
):
39 if os
.path
.exists(path
):
40 raise Exception("Path already exist")
41 open(path
, 'w').close()
44 def __dummy_sigusr1_handler():
48 def sessiond_spawn(runtime
):
49 agent_port
= find_free_port()
50 previous_handler
= signal
.signal(signal
.SIGUSR1
, __dummy_sigusr1_handler
)
51 sessiond
= runtime
.spawn_subprocess("lttng-sessiond -vvv -S --agent-tcp-port {}".format(agent_port
))
52 signal
.sigtimedwait({signal
.SIGUSR1
}, 60)
53 previous_handler
= signal
.signal(signal
.SIGUSR1
, previous_handler
)
58 # There is no guarantee that the port will be free at runtime but should be
60 with
closing(socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)) as s
:
62 return s
.getsockname()[1]
65 def file_contains(stderr_file
, list_of_string
):
66 with
open(stderr_file
, 'r') as stderr
:
68 for s
in list_of_string
:
This page took 0.031492 seconds and 4 git commands to generate.