ScriptCollection 3.3.23__py3-none-any.whl → 4.0.78__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.
Files changed (47) hide show
  1. ScriptCollection/AnionBuildPlatform.py +206 -0
  2. ScriptCollection/{UpdateCertificates.py → CertificateUpdater.py} +149 -128
  3. ScriptCollection/Executables.py +868 -292
  4. ScriptCollection/GeneralUtilities.py +609 -107
  5. ScriptCollection/ImageUpdater.py +648 -0
  6. ScriptCollection/ProcessesRunner.py +41 -0
  7. ScriptCollection/ProgramRunnerBase.py +47 -42
  8. ScriptCollection/ProgramRunnerMock.py +2 -0
  9. ScriptCollection/ProgramRunnerPopen.py +57 -50
  10. ScriptCollection/ProgramRunnerSudo.py +108 -0
  11. ScriptCollection/SCLog.py +115 -0
  12. ScriptCollection/ScriptCollectionCore.py +2541 -1383
  13. ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +95 -0
  14. ScriptCollection/TFCPS/Docker/__init__.py +0 -0
  15. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py +8 -0
  16. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py +6 -0
  17. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py +7 -0
  18. ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +485 -0
  19. ScriptCollection/TFCPS/DotNet/__init__.py +0 -0
  20. ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +130 -0
  21. ScriptCollection/TFCPS/Flutter/__init__.py +0 -0
  22. ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py +74 -0
  23. ScriptCollection/TFCPS/Go/__init__.py +0 -0
  24. ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +131 -0
  25. ScriptCollection/TFCPS/NodeJS/__init__.py +0 -0
  26. ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py +227 -0
  27. ScriptCollection/TFCPS/Python/__init__.py +0 -0
  28. ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +418 -0
  29. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py +128 -0
  30. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +136 -0
  31. ScriptCollection/TFCPS/TFCPS_CreateRelease.py +95 -0
  32. ScriptCollection/TFCPS/TFCPS_Generic.py +43 -0
  33. ScriptCollection/TFCPS/TFCPS_MergeToMain.py +122 -0
  34. ScriptCollection/TFCPS/TFCPS_MergeToStable.py +350 -0
  35. ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py +47 -0
  36. ScriptCollection/TFCPS/TFCPS_Tools_General.py +1356 -0
  37. ScriptCollection/TFCPS/__init__.py +0 -0
  38. {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/METADATA +26 -21
  39. scriptcollection-4.0.78.dist-info/RECORD +43 -0
  40. {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/WHEEL +1 -1
  41. scriptcollection-4.0.78.dist-info/entry_points.txt +64 -0
  42. ScriptCollection/Hardening.py +0 -59
  43. ScriptCollection/ProgramRunnerEpew.py +0 -122
  44. ScriptCollection/TasksForCommonProjectStructure.py +0 -1170
  45. ScriptCollection-3.3.23.dist-info/RECORD +0 -15
  46. ScriptCollection-3.3.23.dist-info/entry_points.txt +0 -24
  47. {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/top_level.txt +0 -0
@@ -1,42 +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) -> Popen:
12
- raise NotImplementedError
13
-
14
- # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
15
- @abstractmethod
16
- @GeneralUtilities.check_arguments
17
- def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
18
- raise NotImplementedError
19
-
20
- # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
21
- @abstractmethod
22
- @GeneralUtilities.check_arguments
23
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
24
- raise NotImplementedError
25
-
26
- # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
27
- @abstractmethod
28
- @GeneralUtilities.check_arguments
29
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
30
- raise NotImplementedError
31
-
32
- # Return-values program_runner: Pid
33
- @abstractmethod
34
- @GeneralUtilities.check_arguments
35
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> int:
36
- raise NotImplementedError
37
-
38
- # Return-values program_runner: Pid
39
- @abstractmethod
40
- @GeneralUtilities.check_arguments
41
- def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object) -> int:
42
- 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
+ raise NotImplementedError
13
+
14
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
15
+ @abstractmethod
16
+ @GeneralUtilities.check_arguments
17
+ def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
18
+ raise NotImplementedError
19
+
20
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
21
+ @abstractmethod
22
+ @GeneralUtilities.check_arguments
23
+ 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]:
24
+ raise NotImplementedError
25
+
26
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
27
+ @abstractmethod
28
+ @GeneralUtilities.check_arguments
29
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
30
+ raise NotImplementedError
31
+
32
+ # Return-values program_runner: Pid
33
+ @abstractmethod
34
+ @GeneralUtilities.check_arguments
35
+ 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:
36
+ raise NotImplementedError
37
+
38
+ # Return-values program_runner: Pid
39
+ @abstractmethod
40
+ @GeneralUtilities.check_arguments
41
+ def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False) -> int:
42
+ raise NotImplementedError
43
+
44
+ @abstractmethod
45
+ @GeneralUtilities.check_arguments
46
+ def will_be_executed_locally(self) -> bool:
47
+ raise NotImplementedError
@@ -0,0 +1,2 @@
1
+ class ProgramRunnerPopen():
2
+ pass
@@ -1,50 +1,57 @@
1
- import os
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) -> 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
- cwd = os.getcwd()
17
- try:
18
- os.chdir(working_directory)
19
- result = Popen(arguments_for_process, stdout=PIPE, stderr=PIPE, shell=False) # pylint: disable=consider-using-with
20
- finally:
21
- os.chdir(cwd)
22
- return result
23
-
24
- # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
25
- @GeneralUtilities.check_arguments
26
- def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
27
- pid = process.pid
28
- stdout, stderr = process.communicate()
29
- exit_code = process.wait()
30
- stdout = GeneralUtilities.bytes_to_string(stdout).replace('\r', '')
31
- stderr = GeneralUtilities.bytes_to_string(stderr).replace('\r', '')
32
- result = (exit_code, stdout, stderr, pid)
33
- return result
34
-
35
- @GeneralUtilities.check_arguments
36
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
37
- process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument)
38
- return self.wait(process, custom_argument)
39
-
40
- @GeneralUtilities.check_arguments
41
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
42
- return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
43
-
44
- @GeneralUtilities.check_arguments
45
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> int:
46
- return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument).pid
47
-
48
- @GeneralUtilities.check_arguments
49
- def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None) -> int:
50
- return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
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, text=True, 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, text=True) # pylint: disable=consider-using-with
21
+ except FileNotFoundError as fileNotFoundError:
22
+ raise FileNotFoundError(f"Starting '{program}' in '{working_directory}' resulted in a FileNotFoundError: '{str(fileNotFoundError)}'")
23
+ except NotADirectoryError as notADirectoryError:
24
+ raise NotADirectoryError(f"Starting '{program}' in '{working_directory}' resulted in a NotADirectoryError: '{str(notADirectoryError)}'")
25
+ return result
26
+
27
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
28
+ @GeneralUtilities.check_arguments
29
+ def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
30
+ pid = process.pid
31
+ stdout, stderr = process.communicate()
32
+ exit_code = process.wait()
33
+ stdout = GeneralUtilities.bytes_to_string(stdout).replace('\r', '')
34
+ stderr = GeneralUtilities.bytes_to_string(stderr).replace('\r', '')
35
+ result = (exit_code, stdout, stderr, pid)
36
+ return result
37
+
38
+ @GeneralUtilities.check_arguments
39
+ 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]:
40
+ process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive)
41
+ return self.wait(process, custom_argument)
42
+
43
+ @GeneralUtilities.check_arguments
44
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
45
+ return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
46
+
47
+ @GeneralUtilities.check_arguments
48
+ 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:
49
+ return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive).pid
50
+
51
+ @GeneralUtilities.check_arguments
52
+ def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> int:
53
+ return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument, interactive)
54
+
55
+ @GeneralUtilities.check_arguments
56
+ def will_be_executed_locally(self) -> bool:
57
+ return True
@@ -0,0 +1,108 @@
1
+ from subprocess import Popen
2
+ from .GeneralUtilities import GeneralUtilities
3
+ from .ProgramRunnerBase import ProgramRunnerBase
4
+ from .ScriptCollectionCore import ScriptCollectionCore
5
+
6
+
7
+ class SudoPopenReader:
8
+ content: bytes = None
9
+
10
+ def __init__(self, content: bytes):
11
+ self.content = content
12
+
13
+ def readable(self) -> bool:
14
+ return True
15
+
16
+ def read(self) -> bytes:
17
+ return self.content
18
+
19
+
20
+ class SudoPopen:
21
+ returncode: int = None
22
+ stdout_str: str = None
23
+ stderr_str: str = None
24
+ pid: int = None
25
+ stdout: bytes = None
26
+ stderr: bytes = None
27
+
28
+ def __init__(self, exitcode: int, stdout: str, stderr: str, pid: int):
29
+ self.returncode: int = exitcode
30
+ self.stdout_str: str = stdout
31
+ self.stdout = str.encode(self.stdout_str)
32
+ self.stderr_str: str = stderr
33
+ self.stderr = str.encode(self.stderr_str)
34
+ self.pid = pid
35
+
36
+ def communicate(self):
37
+ return (self.stdout, self.stderr)
38
+
39
+ def wait(self):
40
+ return self.returncode
41
+
42
+ def poll(self) -> object:
43
+ return self.returncode
44
+
45
+ def __enter__(self):
46
+ return self
47
+
48
+ def __exit__(self, exc_type, exc_value, traceback):
49
+ pass
50
+
51
+
52
+ class ProgramRunnerSudo(ProgramRunnerBase):
53
+ __sc: ScriptCollectionCore
54
+ __password: str
55
+
56
+ @GeneralUtilities.check_arguments
57
+ def __init__(self,user_password:str):
58
+ GeneralUtilities.assert_condition(GeneralUtilities.current_system_is_linux(), "SudoRunner can only be only executed on Linux.")
59
+ self.__sc = ScriptCollectionCore()
60
+ self.__password = user_password
61
+
62
+ @GeneralUtilities.check_arguments
63
+ def will_be_executed_locally(self) -> bool:
64
+ return True
65
+
66
+ @GeneralUtilities.check_arguments
67
+ def run_program_internal(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
68
+ argument = program+" " + ' '.join(GeneralUtilities.args_array_surround_with_quotes_if_required(arguments_as_array))
69
+ argument = f"echo {self.__password} | sudo -k -S {argument}" # TODO maybe add "exit" somewhere before argument or before sudo to correctly return the exit-code"
70
+ result = self.__sc.run_program_argsasarray("sh", ["-c", argument], working_directory)
71
+ return result
72
+
73
+ @GeneralUtilities.check_arguments
74
+ 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:
75
+ if interactive:
76
+ raise ValueError("Interactive execution is not supported in Sudo-runner")
77
+ r: tuple[int, str, str, int] = self.run_program_internal(program, arguments_as_array, working_directory, custom_argument)
78
+ popen: SudoPopen = SudoPopen(r[0], r[1], r[2], r[3])
79
+ return popen
80
+
81
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
82
+ @GeneralUtilities.check_arguments
83
+ def wait(self, process: Popen, custom_argument: object) -> tuple[int, str, str, int]:
84
+ raise ValueError("Wait is not supported in Sudo-runner")
85
+
86
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
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
+ if interactive:
90
+ raise ValueError("Interactive execution is not supported in Sudo-runner")
91
+ return self.run_program_internal(program, arguments_as_array, working_directory, custom_argument)
92
+
93
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
94
+ @GeneralUtilities.check_arguments
95
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
96
+ if interactive:
97
+ raise ValueError("Interactive execution is not supported in Sudo-runner")
98
+ return self.run_program_internal(program, arguments.split(" "), working_directory, custom_argument)
99
+
100
+ # Return-values program_runner: Pid
101
+ @GeneralUtilities.check_arguments
102
+ 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:
103
+ raise ValueError("Async execution is not supported in Sudo-runner")
104
+
105
+ # Return-values program_runner: Pid
106
+ @GeneralUtilities.check_arguments
107
+ def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False) -> int:
108
+ raise ValueError("Async execution is not supported in Sudo-runner")
@@ -0,0 +1,115 @@
1
+ import traceback
2
+ from enum import Enum
3
+ from datetime import datetime
4
+ from .GeneralUtilities import GeneralUtilities
5
+
6
+
7
+ class LogLevel(Enum):
8
+ Quiet = 0
9
+ Error = 1
10
+ Warning = 2
11
+ Information = 3
12
+ Debug = 4
13
+ Diagnostic = 5
14
+
15
+ def __int__(self):
16
+ return self.value
17
+
18
+
19
+ class SCLog:
20
+ loglevel: LogLevel#minimum loglevel
21
+ log_file: str
22
+ add_overhead_to_console: bool
23
+ add_overhead_to_logfile: bool
24
+ print_as_color: bool
25
+ add_milliseconds_to_logfile_entry: bool
26
+
27
+ def __init__(self, log_file: str = None, loglevel: LogLevel = None, print_as_color: bool = True):
28
+ self.log_file = log_file
29
+ if loglevel is None:
30
+ self.loglevel = LogLevel.Information
31
+ else:
32
+ self.loglevel = loglevel
33
+ self.add_overhead_to_console = False
34
+ self.add_overhead_to_logfile = False
35
+ self.add_milliseconds_to_logfile_entry = False
36
+ self.print_as_color = print_as_color
37
+
38
+ @GeneralUtilities.check_arguments
39
+ def log_exception(self, message: str, ex: Exception,loglevel:LogLevel = LogLevel.Error):
40
+ self.log(f"Exception: {message}; Exception-details: {str(ex)}; Traceback: {traceback.format_exc()}", loglevel)
41
+
42
+ @GeneralUtilities.check_arguments
43
+ def log(self, message: str, loglevel: LogLevel = None):
44
+ for line in GeneralUtilities.string_to_lines(message, True, False):
45
+ self.__log_line(line, loglevel)
46
+
47
+ @GeneralUtilities.check_arguments
48
+ def __log_line(self, message: str, loglevel: LogLevel = None):
49
+
50
+ print_to_console: bool = True
51
+ print_to_logfile: bool = self.log_file is not None
52
+
53
+ if loglevel is None:
54
+ loglevel = LogLevel.Information
55
+
56
+ if int(self.loglevel)<int(loglevel):
57
+ return
58
+
59
+ if message.endswith("\n"):
60
+ GeneralUtilities.write_message_to_stderr(f"invalid line: '{message}'") # TODO remove this
61
+
62
+ part1: str = GeneralUtilities.empty_string
63
+ part2: str = GeneralUtilities.empty_string
64
+ part3: str = message
65
+
66
+ if loglevel == LogLevel.Warning:
67
+ part3 = f"Warning: {message}"
68
+ if loglevel == LogLevel.Debug:
69
+ part3 = f"Debug: {message}"
70
+ if loglevel == LogLevel.Diagnostic:
71
+ part3 = f"Diagnostic: {message}"
72
+
73
+ moment: datetime = datetime.now(datetime.now().astimezone().tzinfo)
74
+
75
+ part1 = f"[{GeneralUtilities.datetime_to_string_for_logfile_entry(moment, self.add_milliseconds_to_logfile_entry)}] ["
76
+ if loglevel == LogLevel.Information:
77
+ part2 = f"Information"
78
+ elif loglevel == LogLevel.Error:
79
+ part2 = f"Error"
80
+ elif loglevel == LogLevel.Warning:
81
+ part2 = f"Warning"
82
+ elif loglevel == LogLevel.Debug:
83
+ part2 = f"Debug"
84
+ elif loglevel == LogLevel.Diagnostic:
85
+ part2 = f"Diagnostic"
86
+ else:
87
+ raise ValueError("Unknown loglevel.")
88
+ part3 = f"] {message}"
89
+
90
+ if print_to_console:
91
+ print_to_std_out: bool = loglevel in (LogLevel.Debug, LogLevel.Information)
92
+ if self.add_overhead_to_console:
93
+ GeneralUtilities.print_text(part1, print_to_std_out)
94
+ if loglevel == LogLevel.Information:
95
+ GeneralUtilities.print_text_in_green(part2, print_to_std_out, self.print_as_color)
96
+ elif loglevel == LogLevel.Error:
97
+ GeneralUtilities.print_text_in_red(part2, print_to_std_out, self.print_as_color)
98
+ elif loglevel == LogLevel.Warning:
99
+ GeneralUtilities.print_text_in_yellow(part2, print_to_std_out, self.print_as_color)
100
+ elif loglevel == LogLevel.Debug:
101
+ GeneralUtilities.print_text_in_cyan(part2, print_to_std_out, self.print_as_color)
102
+ elif loglevel == LogLevel.Diagnostic:
103
+ GeneralUtilities.print_text_in_cyan(part2, print_to_std_out, self.print_as_color)
104
+ else:
105
+ raise ValueError("Unknown loglevel.")
106
+ GeneralUtilities.print_text(part3+"\n", print_to_std_out)
107
+ else:
108
+ GeneralUtilities.print_text(message+"\n", print_to_std_out)
109
+
110
+ if print_to_logfile:
111
+ GeneralUtilities.ensure_file_exists(self.log_file)
112
+ if self.add_overhead_to_logfile:
113
+ GeneralUtilities.append_line_to_file(self.log_file, part1+part2+part3)
114
+ else:
115
+ GeneralUtilities.append_line_to_file(self.log_file, message)