ScriptCollection 3.4.56__py3-none-any.whl → 3.5.45__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import os
2
+ import psutil
3
+ from .GeneralUtilities import GeneralUtilities
4
+ from .ProcessesRunner import ProcessStartInformation, ProcessesRunner
5
+ # streams the local libcam-vid-stream to a rtsp-server
6
+
7
+
8
+ class RPStream:
9
+
10
+ __working_directory: str = None
11
+ __pid_file: str = None
12
+
13
+ def __init__(self, working_directory: str):
14
+ self.__working_directory = working_directory
15
+ self.__pid_file = os.path.join(self.__working_directory, "pid.txt")
16
+
17
+ def __get_pid(self) -> str:
18
+ GeneralUtilities.ensure_file_exists(self.__pid_file)
19
+ return GeneralUtilities.read_text_from_file(self.__pid_file)
20
+
21
+ def __set_pid(self, pid: str):
22
+ GeneralUtilities.ensure_file_exists(self.__pid_file)
23
+ GeneralUtilities.write_text_to_file(self.__pid_file, pid)
24
+
25
+ def __ensure_previous_process_is_not_running(self):
26
+ pid = self.__get_pid()
27
+ if GeneralUtilities.string_has_content(pid):
28
+ for proc in psutil.process_iter():
29
+ if proc.pid == pid and proc.name() == "python":
30
+ proc.kill()
31
+
32
+ def __start_stream(self):
33
+ prinfo: list[ProcessStartInformation] = list[ProcessStartInformation]()
34
+ prinfo.append(ProcessStartInformation(None, "", ""))
35
+ prinfo.append(ProcessStartInformation(None, "", ""))
36
+ processesRunner: ProcessesRunner = ProcessesRunner(prinfo)
37
+ self.__set_pid(str(os.getpid()))
38
+ processesRunner.run()
39
+
40
+ def start(self):
41
+ self.__ensure_previous_process_is_not_running()
42
+ self.__start_stream()