ScriptCollection 3.5.9__py3-none-any.whl → 3.5.12__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/Executables.py +358 -348
- ScriptCollection/GeneralUtilities.py +869 -869
- ScriptCollection/ProgramRunnerBase.py +47 -47
- ScriptCollection/ProgramRunnerEpew.py +122 -122
- ScriptCollection/ProgramRunnerPopen.py +51 -51
- ScriptCollection/ScriptCollectionCore.py +1798 -1781
- ScriptCollection/TasksForCommonProjectStructure.py +2617 -2617
- ScriptCollection/UpdateCertificates.py +126 -126
- {ScriptCollection-3.5.9.dist-info → ScriptCollection-3.5.12.dist-info}/METADATA +9 -9
- ScriptCollection-3.5.12.dist-info/RECORD +16 -0
- {ScriptCollection-3.5.9.dist-info → ScriptCollection-3.5.12.dist-info}/WHEEL +1 -1
- {ScriptCollection-3.5.9.dist-info → ScriptCollection-3.5.12.dist-info}/entry_points.txt +1 -0
- ScriptCollection-3.5.9.dist-info/RECORD +0 -16
- {ScriptCollection-3.5.9.dist-info → ScriptCollection-3.5.12.dist-info}/top_level.txt +0 -0
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
from subprocess import Popen
|
|
3
|
-
from .GeneralUtilities import GeneralUtilities
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ProgramRunnerBase:
|
|
7
|
-
|
|
8
|
-
# Return-values program_runner: Pid
|
|
9
|
-
@abstractmethod
|
|
10
|
-
@GeneralUtilities.check_arguments
|
|
11
|
-
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
12
|
-
# Verbosity:
|
|
13
|
-
# 0=Quiet (No output will be printed.)
|
|
14
|
-
# 1=Normal (If the exitcode of the executed program is not 0 then the StdErr will be printed.)
|
|
15
|
-
# 2=Full (Prints StdOut and StdErr of the executed program.)
|
|
16
|
-
# 3=Verbose (Same as "Full" but with some more information.)
|
|
17
|
-
raise NotImplementedError
|
|
18
|
-
|
|
19
|
-
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
20
|
-
@abstractmethod
|
|
21
|
-
@GeneralUtilities.check_arguments
|
|
22
|
-
def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
|
|
23
|
-
raise NotImplementedError
|
|
24
|
-
|
|
25
|
-
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
26
|
-
@abstractmethod
|
|
27
|
-
@GeneralUtilities.check_arguments
|
|
28
|
-
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
29
|
-
raise NotImplementedError
|
|
30
|
-
|
|
31
|
-
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
32
|
-
@abstractmethod
|
|
33
|
-
@GeneralUtilities.check_arguments
|
|
34
|
-
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
35
|
-
raise NotImplementedError
|
|
36
|
-
|
|
37
|
-
# Return-values program_runner: Pid
|
|
38
|
-
@abstractmethod
|
|
39
|
-
@GeneralUtilities.check_arguments
|
|
40
|
-
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
41
|
-
raise NotImplementedError
|
|
42
|
-
|
|
43
|
-
# Return-values program_runner: Pid
|
|
44
|
-
@abstractmethod
|
|
45
|
-
@GeneralUtilities.check_arguments
|
|
46
|
-
def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive:bool=False) -> int:
|
|
47
|
-
raise NotImplementedError
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from subprocess import Popen
|
|
3
|
+
from .GeneralUtilities import GeneralUtilities
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ProgramRunnerBase:
|
|
7
|
+
|
|
8
|
+
# Return-values program_runner: Pid
|
|
9
|
+
@abstractmethod
|
|
10
|
+
@GeneralUtilities.check_arguments
|
|
11
|
+
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
12
|
+
# Verbosity:
|
|
13
|
+
# 0=Quiet (No output will be printed.)
|
|
14
|
+
# 1=Normal (If the exitcode of the executed program is not 0 then the StdErr will be printed.)
|
|
15
|
+
# 2=Full (Prints StdOut and StdErr of the executed program.)
|
|
16
|
+
# 3=Verbose (Same as "Full" but with some more information.)
|
|
17
|
+
raise NotImplementedError
|
|
18
|
+
|
|
19
|
+
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
20
|
+
@abstractmethod
|
|
21
|
+
@GeneralUtilities.check_arguments
|
|
22
|
+
def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
|
|
23
|
+
raise NotImplementedError
|
|
24
|
+
|
|
25
|
+
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
26
|
+
@abstractmethod
|
|
27
|
+
@GeneralUtilities.check_arguments
|
|
28
|
+
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
29
|
+
raise NotImplementedError
|
|
30
|
+
|
|
31
|
+
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
32
|
+
@abstractmethod
|
|
33
|
+
@GeneralUtilities.check_arguments
|
|
34
|
+
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
|
|
37
|
+
# Return-values program_runner: Pid
|
|
38
|
+
@abstractmethod
|
|
39
|
+
@GeneralUtilities.check_arguments
|
|
40
|
+
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
41
|
+
raise NotImplementedError
|
|
42
|
+
|
|
43
|
+
# Return-values program_runner: Pid
|
|
44
|
+
@abstractmethod
|
|
45
|
+
@GeneralUtilities.check_arguments
|
|
46
|
+
def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive:bool=False) -> int:
|
|
47
|
+
raise NotImplementedError
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import base64
|
|
3
|
-
import tempfile
|
|
4
|
-
from subprocess import Popen
|
|
5
|
-
from uuid import uuid4
|
|
6
|
-
|
|
7
|
-
from .GeneralUtilities import GeneralUtilities
|
|
8
|
-
from .ProgramRunnerBase import ProgramRunnerBase
|
|
9
|
-
from .ProgramRunnerPopen import ProgramRunnerPopen
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CustomEpewArgument:
|
|
13
|
-
|
|
14
|
-
print_errors_as_information: bool
|
|
15
|
-
log_file: str
|
|
16
|
-
timeoutInSeconds: int
|
|
17
|
-
addLogOverhead: bool
|
|
18
|
-
title: str
|
|
19
|
-
log_namespace: str
|
|
20
|
-
verbosity: int
|
|
21
|
-
arguments_for_log: list[str]
|
|
22
|
-
tempdir = os.path.join(tempfile.gettempdir(), str(uuid4()))
|
|
23
|
-
stdoutfile = tempdir + ".epew.stdout.txt"
|
|
24
|
-
stderrfile = tempdir + ".epew.stderr.txt"
|
|
25
|
-
exitcodefile = tempdir + ".epew.exitcode.txt"
|
|
26
|
-
pidfile = tempdir + ".epew.pid.txt"
|
|
27
|
-
|
|
28
|
-
def __init__(self, print_errors_as_information: bool, log_file: str, timeoutInSeconds: int, addLogOverhead: bool, title: str, log_namespace: str, verbosity: int, arguments_for_log: list[str]):
|
|
29
|
-
self.print_errors_as_information = print_errors_as_information
|
|
30
|
-
self.log_file = log_file
|
|
31
|
-
self.timeoutInSeconds = timeoutInSeconds
|
|
32
|
-
self.addLogOverhead = addLogOverhead
|
|
33
|
-
self.title = title
|
|
34
|
-
self.log_namespace = log_namespace
|
|
35
|
-
self.verbosity = verbosity
|
|
36
|
-
self.arguments_for_log = arguments_for_log
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class ProgramRunnerEpew(ProgramRunnerBase):
|
|
40
|
-
|
|
41
|
-
@GeneralUtilities.check_arguments
|
|
42
|
-
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
43
|
-
if GeneralUtilities.epew_is_available():
|
|
44
|
-
custom_argument: CustomEpewArgument = custom_argument
|
|
45
|
-
args = []
|
|
46
|
-
|
|
47
|
-
base64argument = base64.b64encode(' '.join(arguments_as_array).encode('utf-8')).decode('utf-8')
|
|
48
|
-
args.append(f'-p "{program}"')
|
|
49
|
-
args.append(f'-a {base64argument}')
|
|
50
|
-
args.append('-b')
|
|
51
|
-
args.append(f'-w "{working_directory}"')
|
|
52
|
-
if custom_argument.stdoutfile is not None:
|
|
53
|
-
args.append(f'-o {custom_argument.stdoutfile}')
|
|
54
|
-
if custom_argument.stderrfile is not None:
|
|
55
|
-
args.append(f'-e {custom_argument.stderrfile}')
|
|
56
|
-
if custom_argument.exitcodefile is not None:
|
|
57
|
-
args.append(f'-x {custom_argument.exitcodefile}')
|
|
58
|
-
if custom_argument.pidfile is not None:
|
|
59
|
-
args.append(f'-r {custom_argument.pidfile}')
|
|
60
|
-
args.append(f'-d {str(custom_argument.timeoutInSeconds*1000)}')
|
|
61
|
-
args.append(f'-t "{custom_argument.title}"')
|
|
62
|
-
args.append(f'-l "{custom_argument.log_namespace}"')
|
|
63
|
-
if not GeneralUtilities.string_is_none_or_whitespace(custom_argument.log_file):
|
|
64
|
-
args.append(f'-f "{custom_argument.log_file}"')
|
|
65
|
-
if custom_argument.print_errors_as_information:
|
|
66
|
-
args.append("-i")
|
|
67
|
-
if custom_argument.addLogOverhead:
|
|
68
|
-
args.append("-g")
|
|
69
|
-
args.append("-v "+str(custom_argument.verbosity))
|
|
70
|
-
return ProgramRunnerPopen().run_program_argsasarray_async_helper("epew", args, working_directory,custom_argument,interactive)
|
|
71
|
-
else:
|
|
72
|
-
raise ValueError("Epew is not available.")
|
|
73
|
-
|
|
74
|
-
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
75
|
-
@GeneralUtilities.check_arguments
|
|
76
|
-
def wait(self, process: Popen, custom_argument: object = None) -> tuple[int, str, str, int]:
|
|
77
|
-
process.wait()
|
|
78
|
-
custom_argument: CustomEpewArgument = custom_argument
|
|
79
|
-
stdout = self.__load_text(custom_argument.output_file_for_stdout)
|
|
80
|
-
stderr = self.__load_text(custom_argument.output_file_for_stderr)
|
|
81
|
-
exit_code = self.__get_number_from_filecontent(self.__load_text(custom_argument.output_file_for_exit_code))
|
|
82
|
-
pid = self.__get_number_from_filecontent(self.__load_text(custom_argument.output_file_for_pid))
|
|
83
|
-
GeneralUtilities.ensure_directory_does_not_exist(custom_argument.tempdir)
|
|
84
|
-
result = (exit_code, stdout, stderr, pid)
|
|
85
|
-
return result
|
|
86
|
-
|
|
87
|
-
@GeneralUtilities.check_arguments
|
|
88
|
-
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
89
|
-
process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive)
|
|
90
|
-
return self.wait(process, custom_argument)
|
|
91
|
-
|
|
92
|
-
@GeneralUtilities.check_arguments
|
|
93
|
-
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
94
|
-
return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|
|
95
|
-
|
|
96
|
-
@GeneralUtilities.check_arguments
|
|
97
|
-
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
98
|
-
return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive).pid
|
|
99
|
-
|
|
100
|
-
@GeneralUtilities.check_arguments
|
|
101
|
-
def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
102
|
-
return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|
|
103
|
-
|
|
104
|
-
@GeneralUtilities.check_arguments
|
|
105
|
-
def __get_number_from_filecontent(self, filecontent: str) -> int:
|
|
106
|
-
for line in filecontent.splitlines():
|
|
107
|
-
try:
|
|
108
|
-
striped_line = GeneralUtilities.strip_new_line_character(line)
|
|
109
|
-
result = int(striped_line)
|
|
110
|
-
return result
|
|
111
|
-
except:
|
|
112
|
-
pass
|
|
113
|
-
raise ValueError(f"'{filecontent}' does not containe an int-line")
|
|
114
|
-
|
|
115
|
-
@GeneralUtilities.check_arguments
|
|
116
|
-
def __load_text(self, file: str) -> str:
|
|
117
|
-
if os.path.isfile(file):
|
|
118
|
-
content = GeneralUtilities.read_text_from_file(file).replace('\r', '')
|
|
119
|
-
os.remove(file)
|
|
120
|
-
return content
|
|
121
|
-
else:
|
|
122
|
-
raise ValueError(f"File '{file}' does not exist")
|
|
1
|
+
import os
|
|
2
|
+
import base64
|
|
3
|
+
import tempfile
|
|
4
|
+
from subprocess import Popen
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
|
|
7
|
+
from .GeneralUtilities import GeneralUtilities
|
|
8
|
+
from .ProgramRunnerBase import ProgramRunnerBase
|
|
9
|
+
from .ProgramRunnerPopen import ProgramRunnerPopen
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CustomEpewArgument:
|
|
13
|
+
|
|
14
|
+
print_errors_as_information: bool
|
|
15
|
+
log_file: str
|
|
16
|
+
timeoutInSeconds: int
|
|
17
|
+
addLogOverhead: bool
|
|
18
|
+
title: str
|
|
19
|
+
log_namespace: str
|
|
20
|
+
verbosity: int
|
|
21
|
+
arguments_for_log: list[str]
|
|
22
|
+
tempdir = os.path.join(tempfile.gettempdir(), str(uuid4()))
|
|
23
|
+
stdoutfile = tempdir + ".epew.stdout.txt"
|
|
24
|
+
stderrfile = tempdir + ".epew.stderr.txt"
|
|
25
|
+
exitcodefile = tempdir + ".epew.exitcode.txt"
|
|
26
|
+
pidfile = tempdir + ".epew.pid.txt"
|
|
27
|
+
|
|
28
|
+
def __init__(self, print_errors_as_information: bool, log_file: str, timeoutInSeconds: int, addLogOverhead: bool, title: str, log_namespace: str, verbosity: int, arguments_for_log: list[str]):
|
|
29
|
+
self.print_errors_as_information = print_errors_as_information
|
|
30
|
+
self.log_file = log_file
|
|
31
|
+
self.timeoutInSeconds = timeoutInSeconds
|
|
32
|
+
self.addLogOverhead = addLogOverhead
|
|
33
|
+
self.title = title
|
|
34
|
+
self.log_namespace = log_namespace
|
|
35
|
+
self.verbosity = verbosity
|
|
36
|
+
self.arguments_for_log = arguments_for_log
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ProgramRunnerEpew(ProgramRunnerBase):
|
|
40
|
+
|
|
41
|
+
@GeneralUtilities.check_arguments
|
|
42
|
+
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
43
|
+
if GeneralUtilities.epew_is_available():
|
|
44
|
+
custom_argument: CustomEpewArgument = custom_argument
|
|
45
|
+
args = []
|
|
46
|
+
|
|
47
|
+
base64argument = base64.b64encode(' '.join(arguments_as_array).encode('utf-8')).decode('utf-8')
|
|
48
|
+
args.append(f'-p "{program}"')
|
|
49
|
+
args.append(f'-a {base64argument}')
|
|
50
|
+
args.append('-b')
|
|
51
|
+
args.append(f'-w "{working_directory}"')
|
|
52
|
+
if custom_argument.stdoutfile is not None:
|
|
53
|
+
args.append(f'-o {custom_argument.stdoutfile}')
|
|
54
|
+
if custom_argument.stderrfile is not None:
|
|
55
|
+
args.append(f'-e {custom_argument.stderrfile}')
|
|
56
|
+
if custom_argument.exitcodefile is not None:
|
|
57
|
+
args.append(f'-x {custom_argument.exitcodefile}')
|
|
58
|
+
if custom_argument.pidfile is not None:
|
|
59
|
+
args.append(f'-r {custom_argument.pidfile}')
|
|
60
|
+
args.append(f'-d {str(custom_argument.timeoutInSeconds*1000)}')
|
|
61
|
+
args.append(f'-t "{custom_argument.title}"')
|
|
62
|
+
args.append(f'-l "{custom_argument.log_namespace}"')
|
|
63
|
+
if not GeneralUtilities.string_is_none_or_whitespace(custom_argument.log_file):
|
|
64
|
+
args.append(f'-f "{custom_argument.log_file}"')
|
|
65
|
+
if custom_argument.print_errors_as_information:
|
|
66
|
+
args.append("-i")
|
|
67
|
+
if custom_argument.addLogOverhead:
|
|
68
|
+
args.append("-g")
|
|
69
|
+
args.append("-v "+str(custom_argument.verbosity))
|
|
70
|
+
return ProgramRunnerPopen().run_program_argsasarray_async_helper("epew", args, working_directory,custom_argument,interactive)
|
|
71
|
+
else:
|
|
72
|
+
raise ValueError("Epew is not available.")
|
|
73
|
+
|
|
74
|
+
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
75
|
+
@GeneralUtilities.check_arguments
|
|
76
|
+
def wait(self, process: Popen, custom_argument: object = None) -> tuple[int, str, str, int]:
|
|
77
|
+
process.wait()
|
|
78
|
+
custom_argument: CustomEpewArgument = custom_argument
|
|
79
|
+
stdout = self.__load_text(custom_argument.output_file_for_stdout)
|
|
80
|
+
stderr = self.__load_text(custom_argument.output_file_for_stderr)
|
|
81
|
+
exit_code = self.__get_number_from_filecontent(self.__load_text(custom_argument.output_file_for_exit_code))
|
|
82
|
+
pid = self.__get_number_from_filecontent(self.__load_text(custom_argument.output_file_for_pid))
|
|
83
|
+
GeneralUtilities.ensure_directory_does_not_exist(custom_argument.tempdir)
|
|
84
|
+
result = (exit_code, stdout, stderr, pid)
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
@GeneralUtilities.check_arguments
|
|
88
|
+
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
89
|
+
process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive)
|
|
90
|
+
return self.wait(process, custom_argument)
|
|
91
|
+
|
|
92
|
+
@GeneralUtilities.check_arguments
|
|
93
|
+
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
94
|
+
return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|
|
95
|
+
|
|
96
|
+
@GeneralUtilities.check_arguments
|
|
97
|
+
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
98
|
+
return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive).pid
|
|
99
|
+
|
|
100
|
+
@GeneralUtilities.check_arguments
|
|
101
|
+
def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
102
|
+
return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|
|
103
|
+
|
|
104
|
+
@GeneralUtilities.check_arguments
|
|
105
|
+
def __get_number_from_filecontent(self, filecontent: str) -> int:
|
|
106
|
+
for line in filecontent.splitlines():
|
|
107
|
+
try:
|
|
108
|
+
striped_line = GeneralUtilities.strip_new_line_character(line)
|
|
109
|
+
result = int(striped_line)
|
|
110
|
+
return result
|
|
111
|
+
except:
|
|
112
|
+
pass
|
|
113
|
+
raise ValueError(f"'{filecontent}' does not containe an int-line")
|
|
114
|
+
|
|
115
|
+
@GeneralUtilities.check_arguments
|
|
116
|
+
def __load_text(self, file: str) -> str:
|
|
117
|
+
if os.path.isfile(file):
|
|
118
|
+
content = GeneralUtilities.read_text_from_file(file).replace('\r', '')
|
|
119
|
+
os.remove(file)
|
|
120
|
+
return content
|
|
121
|
+
else:
|
|
122
|
+
raise ValueError(f"File '{file}' does not exist")
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
from subprocess import PIPE, Popen
|
|
3
|
-
from .GeneralUtilities import GeneralUtilities
|
|
4
|
-
from .ProgramRunnerBase import ProgramRunnerBase
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ProgramRunnerPopen(ProgramRunnerBase):
|
|
8
|
-
|
|
9
|
-
@GeneralUtilities.check_arguments
|
|
10
|
-
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
11
|
-
arguments_for_process = [program]
|
|
12
|
-
arguments_for_process.extend(arguments_as_array)
|
|
13
|
-
# "shell=True" is not allowed because it is not recommended and also something like
|
|
14
|
-
# "ScriptCollectionCore().run_program('curl', 'https://example.com/dataset?id=1&format=json')"
|
|
15
|
-
# would not be possible anymore because the ampersand will be treated as shell-command.
|
|
16
|
-
try:
|
|
17
|
-
if interactive:
|
|
18
|
-
result = Popen(arguments_for_process, cwd=working_directory , stdout=PIPE, stderr=PIPE, shell=False, stdin = sys.stdin) # pylint: disable=consider-using-with
|
|
19
|
-
else:
|
|
20
|
-
result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False) # pylint: disable=consider-using-with
|
|
21
|
-
except FileNotFoundError as fileNotFoundError:
|
|
22
|
-
raise FileNotFoundError(f"Starting '{program}' in '{working_directory}' resulted in a FileNotFoundError: '{fileNotFoundError.filename}'")
|
|
23
|
-
return result
|
|
24
|
-
|
|
25
|
-
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
26
|
-
@GeneralUtilities.check_arguments
|
|
27
|
-
def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
|
|
28
|
-
pid = process.pid
|
|
29
|
-
stdout, stderr = process.communicate()
|
|
30
|
-
exit_code = process.wait()
|
|
31
|
-
stdout = GeneralUtilities.bytes_to_string(stdout).replace('\r', '')
|
|
32
|
-
stderr = GeneralUtilities.bytes_to_string(stderr).replace('\r', '')
|
|
33
|
-
result = (exit_code, stdout, stderr, pid)
|
|
34
|
-
return result
|
|
35
|
-
|
|
36
|
-
@GeneralUtilities.check_arguments
|
|
37
|
-
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
38
|
-
process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive)
|
|
39
|
-
return self.wait(process, custom_argument)
|
|
40
|
-
|
|
41
|
-
@GeneralUtilities.check_arguments
|
|
42
|
-
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
43
|
-
return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
|
|
44
|
-
|
|
45
|
-
@GeneralUtilities.check_arguments
|
|
46
|
-
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
47
|
-
return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive).pid
|
|
48
|
-
|
|
49
|
-
@GeneralUtilities.check_arguments
|
|
50
|
-
def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
51
|
-
return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|
|
1
|
+
import sys
|
|
2
|
+
from subprocess import PIPE, Popen
|
|
3
|
+
from .GeneralUtilities import GeneralUtilities
|
|
4
|
+
from .ProgramRunnerBase import ProgramRunnerBase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ProgramRunnerPopen(ProgramRunnerBase):
|
|
8
|
+
|
|
9
|
+
@GeneralUtilities.check_arguments
|
|
10
|
+
def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> Popen:
|
|
11
|
+
arguments_for_process = [program]
|
|
12
|
+
arguments_for_process.extend(arguments_as_array)
|
|
13
|
+
# "shell=True" is not allowed because it is not recommended and also something like
|
|
14
|
+
# "ScriptCollectionCore().run_program('curl', 'https://example.com/dataset?id=1&format=json')"
|
|
15
|
+
# would not be possible anymore because the ampersand will be treated as shell-command.
|
|
16
|
+
try:
|
|
17
|
+
if interactive:
|
|
18
|
+
result = Popen(arguments_for_process, cwd=working_directory , stdout=PIPE, stderr=PIPE, shell=False, stdin = sys.stdin) # pylint: disable=consider-using-with
|
|
19
|
+
else:
|
|
20
|
+
result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False) # pylint: disable=consider-using-with
|
|
21
|
+
except FileNotFoundError as fileNotFoundError:
|
|
22
|
+
raise FileNotFoundError(f"Starting '{program}' in '{working_directory}' resulted in a FileNotFoundError: '{fileNotFoundError.filename}'")
|
|
23
|
+
return result
|
|
24
|
+
|
|
25
|
+
# Return-values program_runner: Exitcode, StdOut, StdErr, Pid
|
|
26
|
+
@GeneralUtilities.check_arguments
|
|
27
|
+
def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
|
|
28
|
+
pid = process.pid
|
|
29
|
+
stdout, stderr = process.communicate()
|
|
30
|
+
exit_code = process.wait()
|
|
31
|
+
stdout = GeneralUtilities.bytes_to_string(stdout).replace('\r', '')
|
|
32
|
+
stderr = GeneralUtilities.bytes_to_string(stderr).replace('\r', '')
|
|
33
|
+
result = (exit_code, stdout, stderr, pid)
|
|
34
|
+
return result
|
|
35
|
+
|
|
36
|
+
@GeneralUtilities.check_arguments
|
|
37
|
+
def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
38
|
+
process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive)
|
|
39
|
+
return self.wait(process, custom_argument)
|
|
40
|
+
|
|
41
|
+
@GeneralUtilities.check_arguments
|
|
42
|
+
def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> tuple[int, str, str, int]:
|
|
43
|
+
return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
|
|
44
|
+
|
|
45
|
+
@GeneralUtilities.check_arguments
|
|
46
|
+
def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
47
|
+
return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument,interactive).pid
|
|
48
|
+
|
|
49
|
+
@GeneralUtilities.check_arguments
|
|
50
|
+
def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive:bool=False) -> int:
|
|
51
|
+
return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument,interactive)
|