ScriptCollection 3.5.3__py3-none-any.whl → 3.5.4__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.
- ScriptCollection/ProcessesRunner.py +41 -0
- ScriptCollection/RPStream.py +42 -0
- ScriptCollection/ScriptCollectionCore.py +137 -224
- ScriptCollection/TasksForCommonProjectStructure.py +121 -74
- ScriptCollection/UpdateCertificates.py +2 -2
- {ScriptCollection-3.5.3.dist-info → ScriptCollection-3.5.4.dist-info}/METADATA +2 -1
- ScriptCollection-3.5.4.dist-info/RECORD +16 -0
- {ScriptCollection-3.5.3.dist-info → ScriptCollection-3.5.4.dist-info}/WHEEL +1 -1
- ScriptCollection-3.5.3.dist-info/RECORD +0 -14
- {ScriptCollection-3.5.3.dist-info → ScriptCollection-3.5.4.dist-info}/entry_points.txt +0 -0
- {ScriptCollection-3.5.3.dist-info → ScriptCollection-3.5.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import psutil
|
|
2
|
+
from .ScriptCollectionCore import ScriptCollectionCore
|
|
3
|
+
|
|
4
|
+
# runs multiple processes in parallel and terminate all if at least one is terminated
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ProcessStartInformation:
|
|
8
|
+
workingdirectory: str = None
|
|
9
|
+
program: str = None
|
|
10
|
+
arguments: str = None
|
|
11
|
+
|
|
12
|
+
def __init__(self, workingdirectory: str, program: str, arguments: str):
|
|
13
|
+
self.workingdirectory = workingdirectory
|
|
14
|
+
self.program = program
|
|
15
|
+
self.arguments = arguments
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ProcessesRunner:
|
|
19
|
+
sc: ScriptCollectionCore
|
|
20
|
+
processes: list[ProcessStartInformation]
|
|
21
|
+
|
|
22
|
+
def __init__(self, processes: list[ProcessStartInformation]):
|
|
23
|
+
self.sc = ScriptCollectionCore()
|
|
24
|
+
self.processes = processes
|
|
25
|
+
|
|
26
|
+
def run(self):
|
|
27
|
+
pids: list[int] = list[int]()
|
|
28
|
+
for processstartinfo in self.processes:
|
|
29
|
+
pids.append(self.sc.run_program_async(processstartinfo.program, processstartinfo.argumentss, processstartinfo.workingdirectory))
|
|
30
|
+
enabled = True
|
|
31
|
+
while enabled:
|
|
32
|
+
for pid in pids:
|
|
33
|
+
if not psutil.pid_exists(pid):
|
|
34
|
+
enabled = False
|
|
35
|
+
# one program terminate so exit and terminate all now
|
|
36
|
+
processes = psutil.process_iter()
|
|
37
|
+
for pid in pids:
|
|
38
|
+
if psutil.pid_exists(pid):
|
|
39
|
+
for proc in processes:
|
|
40
|
+
if proc.pid == pid:
|
|
41
|
+
proc.kill()
|
|
@@ -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()
|