Skip to content

Commit 55d35d5

Browse files
committed
linux: add get_systemd_version()
Signed-off-by: Adam Trhon <[email protected]>
1 parent 9cec7bc commit 55d35d5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

labgridhelper/linux.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
from labgrid.protocol import CommandProtocol
2+
import re
3+
4+
def get_systemd_version(command):
5+
"""Returns systemd version retrieved by parsing output of `systemd --version`
6+
7+
Args:
8+
command (CommandProtocol): An instance of a Driver implementing the CommandProtocol
9+
10+
Returns:
11+
int: systemd version number
12+
"""
13+
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
14+
15+
out = command.run_check("systemctl --version")
16+
out = out[0]
17+
18+
parsed = re.search(r'^systemd\s+(?P<version>\d+)\s+', out)
19+
if not parsed:
20+
raise ValueError("Systemd version output changed")
21+
return int(parsed.group("version"))
222

323
def get_systemd_status(command):
424
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"

0 commit comments

Comments
 (0)