Skip to content

Commit 9d28aa0

Browse files
committed
feat: log installed and supported streamer
Signed-off-by: Patrick Gehrsitz <[email protected]>
1 parent 7e60446 commit 9d28aa0

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

crowsnest.py

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ async def main():
114114
logger.set_log_level(crowsnest.parameters['log_level'].value)
115115

116116
logging_helper.log_host_info()
117+
logging_helper.log_streamer()
117118
logging_helper.log_config(args.config)
118119
logging_helper.log_cams()
119120

pylibs/components/streamer/streamer.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import textwrap
44
from configparser import SectionProxy
55
from abc import ABC
6+
from os import listdir
7+
from os.path import isfile, join
68

79
from ..section import Section
810
from ...parameter import Parameter
@@ -42,7 +44,8 @@ def __init__(self, name: str) -> None:
4244
self.missing_bin_txt = textwrap.dedent("""\
4345
'%s' executable not found!
4446
Please make sure everything is installed correctly and up to date!
45-
Run 'make update' inside the crowsnest directory to install and update everything.""")
47+
Run 'make update' inside the crowsnest directory to install and update everything."""
48+
)
4649

4750
def parse_config_section(self, config_section: SectionProxy, *args, **kwargs) -> bool:
4851
success = super().parse_config_section(config_section, *args, **kwargs)
@@ -62,5 +65,24 @@ def parse_config_section(self, config_section: SectionProxy, *args, **kwargs) ->
6265
return False
6366
return True
6467

68+
def load_all_streamers():
69+
streamer_path = 'pylibs/components/streamer'
70+
streamer_files = [
71+
f for f in listdir(streamer_path)
72+
if isfile(join(streamer_path, f)) and f.endswith('.py')
73+
]
74+
for streamer_file in streamer_files:
75+
streamer_name = streamer_file[:-3]
76+
try:
77+
streamer = utils.load_component(streamer_name,
78+
'temp',
79+
path=streamer_path.replace('/', '.'))
80+
except NotImplementedError:
81+
continue
82+
Streamer.binaries[streamer_name] = utils.get_executable(
83+
streamer.binary_names,
84+
streamer.binary_paths
85+
)
86+
6587
def load_component(name: str):
6688
raise NotImplementedError("If you see this, something went wrong!!!")

pylibs/logging_helper.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77

88
from . import utils, logger, camera
9+
from .components.streamer.streamer import Streamer, load_all_streamers
910

1011
def log_initial():
1112
logger.log_quiet('crowsnest - A webcam Service for multiple Cams and Stream Services.')
@@ -14,21 +15,6 @@ def log_initial():
1415
logger.log_quiet(f'Version: {version}')
1516
logger.log_quiet('Prepare Startup ...')
1617

17-
def log_config(config_path):
18-
logger.log_info("Print Configfile: '" + config_path + "'")
19-
with open(config_path, 'r') as file:
20-
config_txt = file.read()
21-
# Remove comments
22-
config_txt = re.sub(r'#.*$', "", config_txt, flags=re.MULTILINE)
23-
# Remove multiple whitespaces next to each other at the end of a line
24-
config_txt = re.sub(r'\s*$', "", config_txt, flags=re.MULTILINE)
25-
# Add newlines before sections
26-
config_txt = re.sub(r'(\[.*\])$', "\n\\1", config_txt, flags=re.MULTILINE)
27-
# Remove leading and trailing whitespaces
28-
config_txt = config_txt.strip()
29-
# Split the config file into lines
30-
logger.log_multiline(config_txt, logger.log_info, logger.indentation)
31-
3218
def log_host_info():
3319
logger.log_info("Host Information:")
3420
log_pre = logger.indentation
@@ -75,6 +61,30 @@ def log_host_info():
7561
free = utils.bytes_to_gigabytes(free)
7662
logger.log_info(f'Diskspace (avail. / total): {free}G / {total}G', log_pre)
7763

64+
def log_streamer():
65+
logger.log_info("Found Streamer:")
66+
load_all_streamers()
67+
log_pre = logger.indentation
68+
for bin in Streamer.binaries:
69+
if Streamer.binaries[bin] is None:
70+
continue
71+
logger.log_info(f'{bin}: {Streamer.binaries[bin]}', log_pre)
72+
73+
def log_config(config_path):
74+
logger.log_info("Print Configfile: '" + config_path + "'")
75+
with open(config_path, 'r') as file:
76+
config_txt = file.read()
77+
# Remove comments
78+
config_txt = re.sub(r'#.*$', "", config_txt, flags=re.MULTILINE)
79+
# Remove multiple whitespaces next to each other at the end of a line
80+
config_txt = re.sub(r'\s*$', "", config_txt, flags=re.MULTILINE)
81+
# Add newlines before sections
82+
config_txt = re.sub(r'(\[.*\])$', "\n\\1", config_txt, flags=re.MULTILINE)
83+
# Remove leading and trailing whitespaces
84+
config_txt = config_txt.strip()
85+
# Split the config file into lines
86+
logger.log_multiline(config_txt, logger.log_info, logger.indentation)
87+
7888
def log_cams():
7989
logger.log_info("Detect available Devices")
8090
libcamera = camera.camera_manager.init_camera_type(camera.Libcamera)

0 commit comments

Comments
 (0)