Skip to content

Commit 75b192f

Browse files
committed
Initial commit
Signed-off-by: Rouven Czerwinski <[email protected]>
0 parents  commit 75b192f

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

labgridhelper/__init__.py

Whitespace-only changes.

labgridhelper/barebox.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from labgrid.driver import BareboxDriver
2+
3+
4+
def get_commands(command):
5+
"""Returns the available commands of a running Barebox bootloader
6+
Args:
7+
command (BareboxDriver): An instance of the BareboxDriver
8+
Returns:
9+
list: list of the available commands
10+
"""
11+
assert isinstance(command, BareboxDriver)
12+
out = command.run_check("help")
13+
commands = []
14+
for line in out:
15+
if line and line[0] == " ":
16+
for cmd in line.split(','):
17+
commands.append(cmd.strip(',').strip(" "))
18+
return commands
19+
20+
def get_globals(command):
21+
"""Returns the global variables of a running Barebox bootloader
22+
Args:
23+
command (BareboxDriver): An instance of the BareboxDriver
24+
Returns:
25+
dict: name as key and value as key-value
26+
"""
27+
assert isinstance(command, BareboxDriver)
28+
out = command.run_check("global")
29+
out = map(lambda x: x[2:], out)
30+
global_variables = {}
31+
for line in out:
32+
sep = line.index(":")
33+
key = line[:sep]
34+
value = line[sep+2:]
35+
global_variables[key] = value
36+
return global_variables

labgridhelper/linux.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from labgrid.protocol import CommandProtocol
2+
3+
def get_systemd_status(command):
4+
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
5+
# TODO: Use busctl --json if systemd>239
6+
array_notation = "a(ssssssouso)"
7+
out = command.run_check(
8+
"busctl call --no-pager org.freedesktop.systemd1 \
9+
/org/freedesktop/systemd1 org.freedesktop.systemd1.Manager ListUnits"
10+
)
11+
12+
out = out[0]
13+
if array_notation not in out:
14+
raise ValueError("Systemd ListUnits output changed")
15+
out = out[len(array_notation):]
16+
array_length = int(out[:out.index('"')].strip(" "))
17+
out = out[out.index('"')+1:-1]
18+
out = out.split('\" \"')
19+
data = iter(out)
20+
services = {}
21+
for _ in range(array_length):
22+
name = next(data)
23+
services[name] = {}
24+
services[name]["description"] = next(data)
25+
services[name]["load"] = next(data)
26+
services[name]["active"] = next(data)
27+
services[name]["sub"] = next(data)
28+
services[name]["follow"] = next(data)
29+
path_and_id = next(data)
30+
pos = path_and_id.index('"')
31+
services[name]["path"] = path_and_id[:pos]
32+
services[name]["id"] = int(path_and_id[pos+1:-1].strip(" "))
33+
services[name]["type"] = path_and_id[path_and_id.rfind('"'):]
34+
services[name]["objpath"] = next(data)
35+
36+
return services
37+
38+
def get_commands(command, directories=None):
39+
"""Returns the commands of a running linux system
40+
Args:
41+
command (CommandProtocol): An instance of a Driver implementing the CommandProtocol
42+
directories (list): An optional list of directories to include
43+
Returns:
44+
list: list of commands available under linux
45+
"""
46+
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
47+
out = command.run_check("ls /usr/bin")
48+
out.extend(command.run_check("ls /usr/sbin"))
49+
if directories:
50+
assert isinstance(directories, list), "directories must be a list"
51+
for directory in directories:
52+
out.extend(command.run_check("ls {}".format(directory)))
53+
commands = []
54+
for line in out:
55+
for cmd in line.split(" "):
56+
if cmd:
57+
commands.append(cmd)
58+
59+
return commands

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
from setuptools import setup
4+
5+
setup(
6+
name='labgridhelper',
7+
description='labgridhelper: helper functions for the labgrid library',
8+
author='Rouven Czerwinski',
9+
author_email='[email protected]',
10+
license='LGPL-2.1',
11+
use_scm_version=True,
12+
url='https://github.com/labgrid-project',
13+
python_requires='>=3.5, <3.7',
14+
install_requires=[
15+
'labgrid>=0.1.0',
16+
],
17+
packages=[
18+
'labgridhelper',
19+
],
20+
# custom PyPI classifiers
21+
classifiers=[
22+
"Topic :: Software Development :: Testing",
23+
"Framework :: Pytest",
24+
"Programming Language :: Python :: 3 :: Only",
25+
"Programming Language :: Python :: 3.5",
26+
"Programming Language :: Python :: 3.6",
27+
],
28+
)

0 commit comments

Comments
 (0)