ScriptCollection 3.5.121__py3-none-any.whl → 3.5.123__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.
@@ -211,6 +211,7 @@ class GeneralUtilities:
211
211
  @staticmethod
212
212
  @check_arguments
213
213
  def replace_xmltag_in_file(file: str, tag: str, new_value: str, encoding="utf-8") -> None:
214
+ GeneralUtilities.assert_condition(tag.isalnum(tag), f"Invalid tag: \"{tag}\"")
214
215
  GeneralUtilities.replace_regex_in_file(file, f"<{tag}>.*</{tag}>", f"<{tag}>{new_value}</{tag}>", encoding)
215
216
 
216
217
  @staticmethod
@@ -241,30 +242,44 @@ class GeneralUtilities:
241
242
  GeneralUtilities.write_text_to_file(file, text, encoding)
242
243
 
243
244
  @staticmethod
245
+ @check_arguments
244
246
  def print_text(text: str, print_to_stdout: bool = True):
245
- GeneralUtilities.__print_text_to_console(text, print_to_stdout)
247
+ stream: object = sys.stdout if print_to_stdout else sys.stderr
248
+ GeneralUtilities.__print_text_to_console(text, stream)
246
249
 
247
250
  @staticmethod
248
- def print_text_in_green(text: str, print_to_stdout: bool = True):
249
- GeneralUtilities.__print_text_to_console(f"\033[32m{text}\033[0m", print_to_stdout)
251
+ @check_arguments
252
+ def print_text_in_green(text: str, print_to_stdout: bool = True, print_as_color: bool = True):
253
+ GeneralUtilities.print_text_in_color(text, 32, print_to_stdout, print_as_color)
250
254
 
251
255
  @staticmethod
252
- def print_text_in_yellow(text: str, print_to_stdout: bool = True):
253
- GeneralUtilities.__print_text_to_console(f"\033[33m{text}\033[0m", print_to_stdout)
256
+ @check_arguments
257
+ def print_text_in_yellow(text: str, print_to_stdout: bool = True, print_as_color: bool = True):
258
+ GeneralUtilities.print_text_in_color(text, 33, print_to_stdout, print_as_color)
254
259
 
255
260
  @staticmethod
256
- def print_text_in_red(text: str, print_to_stdout: bool = True):
257
- GeneralUtilities.__print_text_to_console(f"\033[31m{text}\033[0m", print_to_stdout)
261
+ @check_arguments
262
+ def print_text_in_red(text: str, print_to_stdout: bool = True, print_as_color: bool = True):
263
+ GeneralUtilities.print_text_in_color(text, 31, print_to_stdout, print_as_color)
258
264
 
259
265
  @staticmethod
260
- def print_text_in_cyan(text: str, print_to_stdout: bool = True):
261
- GeneralUtilities.__print_text_to_console(f"\033[36m{text}\033[0m", print_to_stdout)
266
+ @check_arguments
267
+ def print_text_in_cyan(text: str, print_to_stdout: bool = True, print_as_color: bool = True):
268
+ GeneralUtilities.print_text_in_color(text, 36, print_to_stdout, print_as_color)
262
269
 
263
270
  @staticmethod
264
- def __print_text_to_console(text: str, print_to_stdout: bool = True):
265
- output = sys.stdout if print_to_stdout else sys.stderr
266
- output.write(text)
267
- output.flush()
271
+ @check_arguments
272
+ def print_text_in_color(text: str, colorcode: int, print_to_stdout: bool = True, print_as_color: bool = True):
273
+ stream: object = sys.stdout if print_to_stdout else sys.stderr
274
+ if print_as_color:
275
+ text = f"\033[{colorcode}m{text}\033[0m"
276
+ GeneralUtilities.__print_text_to_console(text, stream)
277
+
278
+ @staticmethod
279
+ @check_arguments
280
+ def __print_text_to_console(text: str, stream: object):
281
+ stream.write(text)
282
+ stream.flush()
268
283
 
269
284
  @staticmethod
270
285
  @check_arguments
@@ -276,7 +291,7 @@ class GeneralUtilities:
276
291
  @staticmethod
277
292
  @check_arguments
278
293
  def write_message_to_stdout_advanced(message: str, add_empty_lines: bool = True, adapt_lines: bool = True, append_linebreak: bool = True):
279
- new_line_character: str = "\n" if append_linebreak else ""
294
+ new_line_character: str = "\n" if append_linebreak else GeneralUtilities.empty_string
280
295
  for line in GeneralUtilities.string_to_lines(message, add_empty_lines, adapt_lines):
281
296
  sys.stdout.write(GeneralUtilities.str_none_safe(line)+new_line_character)
282
297
  sys.stdout.flush()
@@ -289,7 +304,7 @@ class GeneralUtilities:
289
304
  @staticmethod
290
305
  @check_arguments
291
306
  def write_message_to_stderr_advanced(message: str, add_empty_lines: bool = True, adapt_lines: bool = True, append_linebreak: bool = True):
292
- new_line_character: str = "\n" if append_linebreak else ""
307
+ new_line_character: str = "\n" if append_linebreak else GeneralUtilities.empty_string
293
308
  for line in GeneralUtilities.string_to_lines(message, add_empty_lines, adapt_lines):
294
309
  sys.stderr.write(GeneralUtilities.str_none_safe(line)+new_line_character)
295
310
  sys.stderr.flush()
@@ -532,6 +547,7 @@ class GeneralUtilities:
532
547
  @staticmethod
533
548
  @check_arguments
534
549
  def get_clusters_and_sectors_of_disk(diskpath: str) -> None:
550
+ GeneralUtilities.assert_condition(GeneralUtilities.current_system_is_windows(), "get_clusters_and_sectors_of_disk(diskpath) is only available on windows.")
535
551
  sectorsPerCluster = ctypes.c_ulonglong(0)
536
552
  bytesPerSector = ctypes.c_ulonglong(0)
537
553
  rootPathName = ctypes.c_wchar_p(diskpath)
ScriptCollection/SCLog.py CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  from enum import Enum
3
- from datetime import datetime
3
+ from datetime import datetime, timezone
4
4
  from .GeneralUtilities import GeneralUtilities
5
5
 
6
6
 
@@ -19,11 +19,14 @@ class SCLog:
19
19
  loglevel: LogLevel
20
20
  log_file: str
21
21
  add_overhead: bool
22
+ print_as_color: bool
23
+ zone_of_time: timezone = None
22
24
 
23
- def __init__(self, log_file: str = None, loglevel: LogLevel = None, add_overhead: bool = False):
25
+ def __init__(self, log_file: str = None, loglevel: LogLevel = None, add_overhead: bool = False, print_as_color: bool = True):
24
26
  self.log_file = log_file
25
27
  self.loglevel = loglevel
26
28
  self.add_overhead = add_overhead
29
+ self.print_as_color = print_as_color
27
30
 
28
31
  @GeneralUtilities.check_arguments
29
32
  def log_exception(self, message: str, ex: Exception, current_traceback):
@@ -42,8 +45,11 @@ class SCLog:
42
45
  if int(loglevel) > int(self.loglevel):
43
46
  return
44
47
 
45
- part1: str = ""
46
- part2: str = ""
48
+ if message.endswith("\n"):
49
+ GeneralUtilities.write_message_to_stderr(f"invalid line: '{message}'") # TODO remove this
50
+
51
+ part1: str = GeneralUtilities.empty_string
52
+ part2: str = GeneralUtilities.empty_string
47
53
  part3: str = message
48
54
 
49
55
  if loglevel == LogLevel.Warning:
@@ -51,7 +57,12 @@ class SCLog:
51
57
  if loglevel == LogLevel.Debug:
52
58
  part3 = f"Debug: {message}"
53
59
  if self.add_overhead:
54
- part1 = f"[{GeneralUtilities.datetime_to_string_for_logfile_entry(datetime.now())}] ["
60
+ moment: datetime = None
61
+ if self.zone_of_time is None:
62
+ moment = datetime.now()
63
+ else:
64
+ moment = datetime.now(self.zone_of_time)
65
+ part1 = f"[{GeneralUtilities.datetime_to_string_for_logfile_entry(moment)}] ["
55
66
  if loglevel == LogLevel.Information:
56
67
  part2 = f"Information"
57
68
  elif loglevel == LogLevel.Error:
@@ -66,15 +77,14 @@ class SCLog:
66
77
 
67
78
  print_to_std_out: bool = loglevel in (LogLevel.Debug, LogLevel.Information)
68
79
  GeneralUtilities.print_text(part1, print_to_std_out)
69
- # if the control-characters for colors cause problems then maybe it can be checked with sys.stdout.isatty() if colors should be printed
70
80
  if loglevel == LogLevel.Information:
71
- GeneralUtilities.print_text_in_green(part2, print_to_std_out)
81
+ GeneralUtilities.print_text_in_green(part2, print_to_std_out, self.print_as_color)
72
82
  elif loglevel == LogLevel.Error:
73
- GeneralUtilities.print_text_in_red(part2, print_to_std_out)
83
+ GeneralUtilities.print_text_in_red(part2, print_to_std_out, self.print_as_color)
74
84
  elif loglevel == LogLevel.Warning:
75
- GeneralUtilities.print_text_in_yellow(part2, print_to_std_out)
85
+ GeneralUtilities.print_text_in_yellow(part2, print_to_std_out, self.print_as_color)
76
86
  elif loglevel == LogLevel.Debug:
77
- GeneralUtilities.print_text_in_cyan(part2, print_to_std_out)
87
+ GeneralUtilities.print_text_in_cyan(part2, print_to_std_out, self.print_as_color)
78
88
  else:
79
89
  raise ValueError("Unknown loglevel.")
80
90
  GeneralUtilities.print_text(part3+"\n", print_to_std_out)
@@ -33,7 +33,7 @@ from .ProgramRunnerPopen import ProgramRunnerPopen
33
33
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
34
34
  from .SCLog import SCLog, LogLevel
35
35
 
36
- version = "3.5.121"
36
+ version = "3.5.123"
37
37
  __version__ = version
38
38
 
39
39
 
@@ -1543,7 +1543,7 @@ class ScriptCollectionCore:
1543
1543
  reading_stdout_last_time_resulted_in_exception = False
1544
1544
  if print_live_output:
1545
1545
  # print(out_line, end='\n', file=sys.stdout, flush=False)
1546
- log.log(out_line+"\n", LogLevel.Information)
1546
+ log.log(out_line, LogLevel.Information)
1547
1547
  # if print_live_output:
1548
1548
  # sys.stdout.flush()
1549
1549
  except Empty:
@@ -1558,7 +1558,7 @@ class ScriptCollectionCore:
1558
1558
  reading_stderr_last_time_resulted_in_exception = False
1559
1559
  if print_live_output:
1560
1560
  # print(err_line, end='\n', file=sys.stdout if print_errors_as_information else sys.stderr, flush=False)
1561
- log.log(err_line+"\n", LogLevel.Error if print_errors_as_information else LogLevel.Information)
1561
+ log.log(err_line, LogLevel.Error if print_errors_as_information else LogLevel.Information)
1562
1562
  # if print_live_output:
1563
1563
  # if print_errors_as_information:
1564
1564
  # sys.stdout.flush()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 3.5.121
3
+ Version: 3.5.123
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
@@ -1,17 +1,17 @@
1
1
  ScriptCollection/CertificateUpdater.py,sha256=OAxrG21k_o3W3niOOGNSZzUPJlvolOWc1lRB2dMhc3g,9212
2
2
  ScriptCollection/Executables.py,sha256=ht-RZFu4g34Sr09b_L0c2QpKcjLWX-wFtKSMDMZYqsw,32266
3
- ScriptCollection/GeneralUtilities.py,sha256=hqAKRF99uu2RCSBgjX4qjYn3IlImwm6rehRvt8hbNFQ,46407
3
+ ScriptCollection/GeneralUtilities.py,sha256=PKdzq382RYVSWeSG_6z6FiHu-SiTOi2BavJKvP-0slU,47308
4
4
  ScriptCollection/ImageUpdater.py,sha256=lel1nevTN7fgdoCDE6Xg8YY6XPsZaOQiCIyWXbmVnh0,20882
5
5
  ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
6
6
  ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
7
7
  ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
8
8
  ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
9
- ScriptCollection/SCLog.py,sha256=GEvh0m4OXz_0703XgY-LyAy9RDYg8x1baNZSrWhhu2A,3127
10
- ScriptCollection/ScriptCollectionCore.py,sha256=eoVmIEoaU_B8sIgaJTN1e7ocurjsLyT2VzxvrsQLyV4,127859
9
+ ScriptCollection/SCLog.py,sha256=HDSxCDU3TJPA_3S3ELpxpJrrLfZUAGYbhjuo4DnLNEM,3589
10
+ ScriptCollection/ScriptCollectionCore.py,sha256=G8L79m35lsHomhd9n25GTpz-Ik3i57MOZQ2yV4hDf3k,127849
11
11
  ScriptCollection/TasksForCommonProjectStructure.py,sha256=4aEuIf89jbgKE4uMYm4DlPDe9Iu1Zujo8wPOzDld09w,234867
12
12
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- scriptcollection-3.5.121.dist-info/METADATA,sha256=guQOcS7sLrfO50qZx1bILbJ5sgUGP2b4IdJb-BG5ZcE,7694
14
- scriptcollection-3.5.121.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
15
- scriptcollection-3.5.121.dist-info/entry_points.txt,sha256=3qMbfZEMhc_VTJj-bcLwB8AWcn9iXSB3l0AWpuu52Bs,3689
16
- scriptcollection-3.5.121.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
- scriptcollection-3.5.121.dist-info/RECORD,,
13
+ scriptcollection-3.5.123.dist-info/METADATA,sha256=T_zcyjXAMOgzYQAH3qctDIaxNNQxouhANDzTaP1VFNQ,7694
14
+ scriptcollection-3.5.123.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
15
+ scriptcollection-3.5.123.dist-info/entry_points.txt,sha256=3qMbfZEMhc_VTJj-bcLwB8AWcn9iXSB3l0AWpuu52Bs,3689
16
+ scriptcollection-3.5.123.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
+ scriptcollection-3.5.123.dist-info/RECORD,,