ScriptCollection 3.5.103__py3-none-any.whl → 3.5.104__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.
@@ -21,6 +21,7 @@ from os.path import isfile, join, isdir
21
21
  from pathlib import Path
22
22
  from shutil import copyfile
23
23
  import typing
24
+ import psutil
24
25
  from defusedxml.minidom import parse
25
26
  from OpenSSL import crypto
26
27
 
@@ -1027,3 +1028,38 @@ class GeneralUtilities:
1027
1028
  GeneralUtilities.assert_condition("." in plain_str)
1028
1029
  splitted: list[str] = plain_str.split(".")
1029
1030
  return splitted[0].zfill(leading_zeroplaces)+"."+splitted[1].ljust(trailing_zeroplaces, '0')
1031
+
1032
+ @staticmethod
1033
+ @check_arguments
1034
+ def process_is_running_by_name(process_name: str) -> bool:
1035
+ processes: list[psutil.Process] = list(psutil.process_iter())
1036
+ for p in processes:
1037
+ if p.name() == process_name:
1038
+ return True
1039
+ return False
1040
+
1041
+
1042
+ @staticmethod
1043
+ @check_arguments
1044
+ def process_is_running_by_id(process_id: int) -> bool:
1045
+ processes: list[psutil.Process] = list(psutil.process_iter())
1046
+ for p in processes:
1047
+ if p.pid == process_id:
1048
+ return True
1049
+ return False
1050
+
1051
+
1052
+ @staticmethod
1053
+ @check_arguments
1054
+ def kill_process(process_id:int,include_child_processes:bool) -> bool:
1055
+ if GeneralUtilities. process_is_running_by_id(process_id):
1056
+ GeneralUtilities.write_message_to_stdout(f"Process with id {process_id} is running. Terminating it...")
1057
+ process = psutil.Process(process_id)
1058
+ if include_child_processes:
1059
+ for child in process.children(recursive=True):
1060
+ if GeneralUtilities.process_is_running_by_id(child.pid):
1061
+ child.kill()
1062
+ if GeneralUtilities.process_is_running_by_id(process_id):
1063
+ process.kill()
1064
+ else:
1065
+ GeneralUtilities.write_message_to_stdout(f"Process with id {process_id} is not running anymore.")
ScriptCollection/SCLog.py CHANGED
@@ -1,2 +1,68 @@
1
+
2
+ from enum import Enum
3
+ from datetime import datetime
4
+ from .GeneralUtilities import GeneralUtilities
5
+
6
+
7
+ class LogLevel(Enum):
8
+ Error = 1
9
+ Warning = 2
10
+ Information = 3
11
+ Debug = 4
12
+
13
+ def __int__(self):
14
+ return self.value
15
+
16
+
1
17
  class SCLog:
2
- pass # TODO
18
+ loglevel: LogLevel
19
+ log_file: str
20
+ add_overhead: bool
21
+
22
+ def __init__(self, log_file: str = None):
23
+ self.add_overhead = False
24
+ self.loglevel = LogLevel.Information
25
+ self.log_file = log_file
26
+
27
+ @GeneralUtilities.check_arguments
28
+ def log_exception(self, message: str, ex: Exception, current_traceback):
29
+ self.log(f"Exception: {message}; Exception-details: {str(ex)}; Traceback: {current_traceback.format_exc()}", LogLevel.Error)
30
+
31
+ @GeneralUtilities.check_arguments
32
+ def log(self, message: str, loglevel: LogLevel):
33
+ if loglevel is None:
34
+ loglevel = LogLevel.Information
35
+
36
+ if int(loglevel) > int(self.loglevel):
37
+ return
38
+
39
+ if loglevel == LogLevel.Warning:
40
+ message = f"Warning: {message}"
41
+ if self.add_overhead:
42
+ if loglevel == LogLevel.Error:
43
+ message = f"[Error] {message}"
44
+ elif loglevel == LogLevel.Warning:
45
+ message = f"[Warning] {message}"
46
+ elif loglevel == LogLevel.Debug:
47
+ message = f"[Debug] {message}"
48
+ elif loglevel == LogLevel.Information:
49
+ message = f"[Information] {message}"
50
+ else:
51
+ raise ValueError("Unknown loglevel.")
52
+
53
+ message = f"[{GeneralUtilities.datetime_to_string_for_logfile_entry(datetime.now())}] {message}"
54
+
55
+ if loglevel == LogLevel.Error:
56
+ GeneralUtilities.write_message_to_stderr(message)
57
+ elif loglevel == LogLevel.Warning:
58
+ GeneralUtilities.write_message_to_stderr(message)
59
+ elif loglevel == LogLevel.Debug:
60
+ GeneralUtilities.write_message_to_stdout(message)
61
+ elif loglevel == LogLevel.Information:
62
+ GeneralUtilities.write_message_to_stdout(message)
63
+ else:
64
+ raise ValueError("Unknown loglevel.")
65
+
66
+ if self.log_file is not None:
67
+ GeneralUtilities.ensure_file_exists(self.log_file)
68
+ GeneralUtilities.append_line_to_file(self.log_file, message)
@@ -33,7 +33,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
33
33
  from .ProgramRunnerPopen import ProgramRunnerPopen
34
34
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
35
35
 
36
- version = "3.5.103"
36
+ version = "3.5.104"
37
37
  __version__ = version
38
38
 
39
39
 
@@ -2354,10 +2354,11 @@ class TasksForCommonProjectStructure:
2354
2354
 
2355
2355
  if append_cli_args_at_end:
2356
2356
  command_with_args = f"{command_with_args} {{{{.CLI_ARGS}}}}"
2357
+ cwd_literal = cwd.replace("\\", "\\\\")
2357
2358
  lines.append(f" {name}:")
2358
2359
  lines.append(f' desc: "{description}"')
2359
2360
  lines.append(' silent: true')
2360
- lines.append(f' dir: "{cwd}"')
2361
+ lines.append(f' dir: "{cwd_literal}"')
2361
2362
  lines.append(" cmds:")
2362
2363
  lines.append(f" - {command_with_args}")
2363
2364
  lines.append(' aliases:')
@@ -27,7 +27,7 @@ class CertificateUpdater:
27
27
  @GeneralUtilities.check_arguments
28
28
  def __get_latest_index_by_domain(self, domain: str) -> int:
29
29
  result = self.__get_latest_index_by_filelist(GeneralUtilities.get_all_files_of_folder(os.path.join(self.__letsencrypt_archive_folder, domain)))
30
- GeneralUtilities.write_message_to_stdout(f"Debug: Latest found existing number for domain {domain}: {result}")
30
+ #GeneralUtilities.write_message_to_stdout(f"Debug: Latest found existing number for domain {domain}: {result}")
31
31
  return result
32
32
 
33
33
  @GeneralUtilities.check_arguments
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 3.5.103
3
+ Version: 3.5.104
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Home-page: https://github.com/anionDev/ScriptCollection
6
6
  Author: Marius Göcke
@@ -23,7 +23,7 @@ Classifier: Topic :: Utilities
23
23
  Requires-Python: >=3.10
24
24
  Description-Content-Type: text/markdown
25
25
  Requires-Dist: build>=1.2.2.post1
26
- Requires-Dist: coverage>=7.7.1
26
+ Requires-Dist: coverage>=7.8.0
27
27
  Requires-Dist: cyclonedx-bom>=5.3.0
28
28
  Requires-Dist: defusedxml>=0.7.1
29
29
  Requires-Dist: keyboard>=0.13.5
@@ -38,7 +38,7 @@ Requires-Dist: pyOpenSSL>=25.0.0
38
38
  Requires-Dist: PyPDF>=5.4.0
39
39
  Requires-Dist: pytest>=8.3.5
40
40
  Requires-Dist: PyYAML>=6.0.2
41
- Requires-Dist: qrcode>=8.0
41
+ Requires-Dist: qrcode>=8.1
42
42
  Requires-Dist: send2trash>=1.8.3
43
43
  Requires-Dist: twine>=6.1.0
44
44
  Requires-Dist: xmlschema>=3.4.5
@@ -0,0 +1,16 @@
1
+ ScriptCollection/Executables.py,sha256=HI9Pxs5Z9QxPGyqeJU2lWslEggFyGYANCqYVQZp6eJ0,30490
2
+ ScriptCollection/GeneralUtilities.py,sha256=jkJu6y8Wv-j_braS_0zsjF6JzDo46NshMeeAphsXGX4,43848
3
+ ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
4
+ ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
5
+ ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
6
+ ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
7
+ ScriptCollection/SCLog.py,sha256=Gw27Oclcb0ten7_89PD5CdNMoO-at2hGUOYbF-x1HPQ,2296
8
+ ScriptCollection/ScriptCollectionCore.py,sha256=08UGdNP-Ji04KIkoG_1Ks7EdbLlSpnM-dI0WBNMzrOc,125705
9
+ ScriptCollection/TasksForCommonProjectStructure.py,sha256=4EcmpWaLxfJHPSW47EXeJivk4hypqPasgbX-joj9isE,229844
10
+ ScriptCollection/UpdateCertificates.py,sha256=xRebqD2etBD7ILHL-7fg-Y-kPF0Tbmnwexv4FhwDntQ,7791
11
+ ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ scriptcollection-3.5.104.dist-info/METADATA,sha256=oZ-T6ilqqw29o0VDog_vtgJvC7yYrKWd2Tm1PT_BDJE,7664
13
+ scriptcollection-3.5.104.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
14
+ scriptcollection-3.5.104.dist-info/entry_points.txt,sha256=fYCGWGNGijBQHhFe6UAO-BEpfEOxLyNJemukt5ElSzs,3644
15
+ scriptcollection-3.5.104.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
16
+ scriptcollection-3.5.104.dist-info/RECORD,,
@@ -1,42 +0,0 @@
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()
@@ -1,17 +0,0 @@
1
- ScriptCollection/Executables.py,sha256=HI9Pxs5Z9QxPGyqeJU2lWslEggFyGYANCqYVQZp6eJ0,30490
2
- ScriptCollection/GeneralUtilities.py,sha256=unOZbHDqlxwPHXY1epy4gdGYwDbHEETF1XKZYPGX2hw,42429
3
- ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
4
- ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
5
- ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
6
- ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
7
- ScriptCollection/RPStream.py,sha256=NRRHL3YSP3D9MuAV2jB_--0KUKCsvJGxeKnxgrRZ9kY,1545
8
- ScriptCollection/SCLog.py,sha256=l4aekBiGoNkKGtvO_Er3NY_K7ts4ZWtIGlhq07I-4LY,30
9
- ScriptCollection/ScriptCollectionCore.py,sha256=p9ofnNkzI-3_QsJwbh4auBAGSh-IkWKGlrLSh0eZyBE,125705
10
- ScriptCollection/TasksForCommonProjectStructure.py,sha256=MpyvFNyJG7njRYvV9KULJmbn7WonR18YDeS7oI_O3UU,229780
11
- ScriptCollection/UpdateCertificates.py,sha256=Eynbgu7k9jLxApP2D_8Il77B6BFjJap6K7oTeEAZYbk,7790
12
- ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- scriptcollection-3.5.103.dist-info/METADATA,sha256=q07vsHzykcNIo0Vixjx1YEAUj21qm1UVbgW70afB0O8,7664
14
- scriptcollection-3.5.103.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
- scriptcollection-3.5.103.dist-info/entry_points.txt,sha256=fYCGWGNGijBQHhFe6UAO-BEpfEOxLyNJemukt5ElSzs,3644
16
- scriptcollection-3.5.103.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
- scriptcollection-3.5.103.dist-info/RECORD,,