ScriptCollection 3.5.120__py3-none-any.whl → 3.5.121__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/SCLog.py CHANGED
@@ -5,6 +5,7 @@ from .GeneralUtilities import GeneralUtilities
5
5
 
6
6
 
7
7
  class LogLevel(Enum):
8
+ Quiet = 0
8
9
  Error = 1
9
10
  Warning = 2
10
11
  Information = 3
@@ -19,10 +20,10 @@ class SCLog:
19
20
  log_file: str
20
21
  add_overhead: bool
21
22
 
22
- def __init__(self, log_file: str = None):
23
- self.add_overhead = False
24
- self.loglevel = LogLevel.Information
23
+ def __init__(self, log_file: str = None, loglevel: LogLevel = None, add_overhead: bool = False):
25
24
  self.log_file = log_file
25
+ self.loglevel = loglevel
26
+ self.add_overhead = add_overhead
26
27
 
27
28
  @GeneralUtilities.check_arguments
28
29
  def log_exception(self, message: str, ex: Exception, current_traceback):
@@ -1,4 +1,3 @@
1
- import sys
2
1
  from datetime import timedelta, datetime
3
2
  import json
4
3
  import binascii
@@ -32,8 +31,9 @@ from .GeneralUtilities import GeneralUtilities
32
31
  from .ProgramRunnerBase import ProgramRunnerBase
33
32
  from .ProgramRunnerPopen import ProgramRunnerPopen
34
33
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
34
+ from .SCLog import SCLog, LogLevel
35
35
 
36
- version = "3.5.120"
36
+ version = "3.5.121"
37
37
  __version__ = version
38
38
 
39
39
 
@@ -47,11 +47,13 @@ class ScriptCollectionCore:
47
47
  __mocked_program_calls: list = None
48
48
  program_runner: ProgramRunnerBase = None
49
49
  call_program_runner_directly: bool = None
50
+ log: SCLog = None
50
51
 
51
52
  def __init__(self):
52
53
  self.program_runner = ProgramRunnerPopen()
53
54
  self.call_program_runner_directly = None
54
55
  self.__mocked_program_calls = list[ScriptCollectionCore.__MockProgramCall]()
56
+ self.log = SCLog(None, LogLevel.Quiet, False)
55
57
 
56
58
  @staticmethod
57
59
  @GeneralUtilities.check_arguments
@@ -428,10 +430,10 @@ class ScriptCollectionCore:
428
430
  self.git_stage_all_changes(directory)
429
431
  else:
430
432
  if no_changes_behavior == 0:
431
- GeneralUtilities.write_message_to_stdout(f"Commit '{message}' will not be done because there are no changes to commit in repository '{directory}'")
433
+ self.log.log(f"Commit '{message}' will not be done because there are no changes to commit in repository '{directory}'", LogLevel.Debug)
432
434
  do_commit = False
433
435
  elif no_changes_behavior == 1:
434
- GeneralUtilities.write_message_to_stdout(f"There are no changes to commit in repository '{directory}'. Commit '{message}' will be done anyway.")
436
+ self.log.log(f"There are no changes to commit in repository '{directory}'. Commit '{message}' will be done anyway.", LogLevel.Debug)
435
437
  do_commit = True
436
438
  elif no_changes_behavior == 2:
437
439
  raise RuntimeError(f"There are no changes to commit in repository '{directory}'. Commit '{message}' will not be done.")
@@ -439,7 +441,7 @@ class ScriptCollectionCore:
439
441
  raise ValueError(f"Unknown value for no_changes_behavior: {GeneralUtilities.str_none_safe(no_changes_behavior)}")
440
442
 
441
443
  if do_commit:
442
- GeneralUtilities.write_message_to_stdout(f"Commit changes in '{directory}'")
444
+ self.log.log(f"Commit changes in '{directory}'", LogLevel.Information)
443
445
  self.run_program_argsasarray("git", argument, directory, throw_exception_if_exitcode_is_not_zero=True, verbosity=0)
444
446
 
445
447
  return self.git_get_commit_id(directory)
@@ -581,7 +583,7 @@ class ScriptCollectionCore:
581
583
  counter = 0
582
584
  for tag in tags:
583
585
  counter = counter+1
584
- GeneralUtilities.write_message_to_stdout(f"Process tag {counter}/{tags_count}.")
586
+ self.log.log(f"Process tag {counter}/{tags_count}.", LogLevel.Information)
585
587
  # tag is on source-branch
586
588
  if self.git_commit_is_ancestor(repository, tag, tag_source_branch):
587
589
  commit_id_old = self.git_get_commitid_of_tag(repository, tag)
@@ -1048,10 +1050,10 @@ class ScriptCollectionCore:
1048
1050
  elif (size_string.endswith("gib")):
1049
1051
  size = int(size_string[:-3]) * pow(2, 30)
1050
1052
  else:
1051
- GeneralUtilities.write_message_to_stderr("Wrong format")
1053
+ self.log.log("Wrong format", LogLevel.Error)
1052
1054
  return 1
1053
1055
  else:
1054
- GeneralUtilities.write_message_to_stderr("Wrong format")
1056
+ self.log.log("Wrong format", LogLevel.Error)
1055
1057
  return 1
1056
1058
  with open(name, "wb") as f:
1057
1059
  f.seek(size-1)
@@ -1115,7 +1117,7 @@ class ScriptCollectionCore:
1115
1117
 
1116
1118
  return 0
1117
1119
  else:
1118
- GeneralUtilities.write_message_to_stdout(f"File '{file}' does not exist")
1120
+ self.log.log(f"File '{file}' does not exist.", LogLevel.Error)
1119
1121
  return 1
1120
1122
 
1121
1123
  @GeneralUtilities.check_arguments
@@ -1194,8 +1196,7 @@ class ScriptCollectionCore:
1194
1196
  @GeneralUtilities.check_arguments
1195
1197
  def __print_qr_code_by_csv_line(self, displayname: str, website: str, emailaddress: str, key: str, period: str) -> None:
1196
1198
  qrcode_content = f"otpauth://totp/{website}:{emailaddress}?secret={key}&issuer={displayname}&period={period}"
1197
- GeneralUtilities.write_message_to_stdout(
1198
- f"{displayname} ({emailaddress}):")
1199
+ GeneralUtilities.write_message_to_stdout(f"{displayname} ({emailaddress}):")
1199
1200
  GeneralUtilities.write_message_to_stdout(qrcode_content)
1200
1201
  qr = qrcode.QRCode()
1201
1202
  qr.add_data(qrcode_content)
@@ -1447,7 +1448,6 @@ class ScriptCollectionCore:
1447
1448
  ls_result = self.run_program_argsasarray("ls", ["-ld", file_or_folder])
1448
1449
  GeneralUtilities.assert_condition(ls_result[0] == 0, f"'ls -ld {file_or_folder}' resulted in exitcode {str(ls_result[0])}. StdErr: {ls_result[2]}")
1449
1450
  GeneralUtilities.assert_condition(not GeneralUtilities.string_is_none_or_whitespace(ls_result[1]), f"'ls -ld' of '{file_or_folder}' had an empty output. StdErr: '{ls_result[2]}'")
1450
- GeneralUtilities.write_message_to_stdout(ls_result[1])
1451
1451
  output = ls_result[1]
1452
1452
  result = output.replace("\n", GeneralUtilities.empty_string)
1453
1453
  result = ' '.join(result.split()) # reduce multiple whitespaces to one
@@ -1460,7 +1460,6 @@ class ScriptCollectionCore:
1460
1460
  ls_result = self.run_program_argsasarray("ls", ["-la", file_or_folder])
1461
1461
  GeneralUtilities.assert_condition(ls_result[0] == 0, f"'ls -la {file_or_folder}' resulted in exitcode {str(ls_result[0])}. StdErr: {ls_result[2]}")
1462
1462
  GeneralUtilities.assert_condition(not GeneralUtilities.string_is_none_or_whitespace(ls_result[1]), f"'ls -la' of '{file_or_folder}' had an empty output. StdErr: '{ls_result[2]}'")
1463
- GeneralUtilities.write_message_to_stdout(ls_result[1])
1464
1463
  output = ls_result[1]
1465
1464
  result = output.split("\n")[3:] # skip the lines with "Total", "." and ".."
1466
1465
  result = [' '.join(line.split()) for line in result] # reduce multiple whitespaces to one
@@ -1520,7 +1519,7 @@ class ScriptCollectionCore:
1520
1519
  return False
1521
1520
 
1522
1521
  @staticmethod
1523
- def __read_popen_pipes(p: Popen, print_live_output: bool, print_errors_as_information: bool) -> tuple[list[str], list[str]]:
1522
+ def __read_popen_pipes(p: Popen, print_live_output: bool, print_errors_as_information: bool, log: SCLog) -> tuple[list[str], list[str]]:
1524
1523
  p_id = p.pid
1525
1524
  with ThreadPoolExecutor(2) as pool:
1526
1525
  q_stdout = Queue()
@@ -1543,9 +1542,10 @@ class ScriptCollectionCore:
1543
1542
  stdout_result.append(out_line)
1544
1543
  reading_stdout_last_time_resulted_in_exception = False
1545
1544
  if print_live_output:
1546
- print(out_line, end='\n', file=sys.stdout, flush=False)
1547
- if print_live_output:
1548
- sys.stdout.flush()
1545
+ # print(out_line, end='\n', file=sys.stdout, flush=False)
1546
+ log.log(out_line+"\n", LogLevel.Information)
1547
+ # if print_live_output:
1548
+ # sys.stdout.flush()
1549
1549
  except Empty:
1550
1550
  reading_stdout_last_time_resulted_in_exception = True
1551
1551
 
@@ -1557,12 +1557,13 @@ class ScriptCollectionCore:
1557
1557
  stderr_result.append(err_line)
1558
1558
  reading_stderr_last_time_resulted_in_exception = False
1559
1559
  if print_live_output:
1560
- print(err_line, end='\n', file=sys.stdout if print_errors_as_information else sys.stderr, flush=False)
1561
- if print_live_output:
1562
- if print_errors_as_information:
1563
- sys.stdout.flush()
1564
- else:
1565
- sys.stderr.flush()
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)
1562
+ # if print_live_output:
1563
+ # if print_errors_as_information:
1564
+ # sys.stdout.flush()
1565
+ # else:
1566
+ # sys.stderr.flush()
1566
1567
  except Empty:
1567
1568
  reading_stderr_last_time_resulted_in_exception = True
1568
1569
 
@@ -1597,7 +1598,7 @@ class ScriptCollectionCore:
1597
1598
 
1598
1599
  verbose = verbosity > 2
1599
1600
  if verbose:
1600
- GeneralUtilities.write_message_to_stdout(f"Run '{info_for_log}'.")
1601
+ self.log.log(f"Run '{info_for_log}'.", LogLevel.Debug)
1601
1602
 
1602
1603
  exit_code: int = None
1603
1604
  stdout: str = GeneralUtilities.empty_string
@@ -1610,7 +1611,7 @@ class ScriptCollectionCore:
1610
1611
  GeneralUtilities.ensure_file_exists(log_file)
1611
1612
  pid = process.pid
1612
1613
 
1613
- outputs: tuple[list[str], list[str]] = ScriptCollectionCore.__read_popen_pipes(process, print_live_output, print_errors_as_information)
1614
+ outputs: tuple[list[str], list[str]] = ScriptCollectionCore.__read_popen_pipes(process, print_live_output, print_errors_as_information, self.log)
1614
1615
 
1615
1616
  for out_line_plain in outputs[0]:
1616
1617
  if out_line_plain is not None:
@@ -1655,7 +1656,7 @@ class ScriptCollectionCore:
1655
1656
  result_message = f"Program '{info_for_log}' resulted in exitcode {exit_code}."
1656
1657
 
1657
1658
  if verbose:
1658
- GeneralUtilities.write_message_to_stdout(result_message)
1659
+ self.log.log(result_message, LogLevel.Debug)
1659
1660
 
1660
1661
  if throw_exception_if_exitcode_is_not_zero and exit_code != 0:
1661
1662
  raise ValueError(f"{result_message} (StdOut: '{stdout}', StdErr: '{stderr}')")
@@ -1969,56 +1970,16 @@ DNS = {domain}
1969
1970
  def update_dependencies_of_dotnet_project(self, csproj_file: str, verbosity: int, ignored_dependencies: list[str]):
1970
1971
  folder = os.path.dirname(csproj_file)
1971
1972
  csproj_filename = os.path.basename(csproj_file)
1972
- GeneralUtilities.write_message_to_stdout(f"Check for updates in {csproj_filename}")
1973
+ self.log.log(f"Check for updates in {csproj_filename}", LogLevel.Information)
1973
1974
  result = self.run_program_with_retry("dotnet", f"list {csproj_filename} package --outdated", folder, print_errors_as_information=True)
1974
1975
  for line in result[1].replace("\r", GeneralUtilities.empty_string).split("\n"):
1975
1976
  # Relevant output-lines are something like " > NJsonSchema 10.7.0 10.7.0 10.9.0"
1976
1977
  if ">" in line:
1977
1978
  package_name = line.replace(">", GeneralUtilities.empty_string).strip().split(" ")[0]
1978
1979
  if not (package_name in ignored_dependencies):
1979
- GeneralUtilities.write_message_to_stdout(f"Update package {package_name}...")
1980
+ self.log.log(f"Update package {package_name}...", LogLevel.Debug)
1980
1981
  self.run_program("dotnet", f"add {csproj_filename} package {package_name}", folder, print_errors_as_information=True)
1981
1982
 
1982
- @GeneralUtilities.check_arguments
1983
- def dotnet_package_is_available(self, package_name: str, package_version: str, source: str):
1984
- default_source_address = "nuget.org"
1985
- if source == default_source_address:
1986
- GeneralUtilities.write_message_to_stdout(f"Wait until package {package_name} v{package_version} is available on {source}.")
1987
- headers = {'Cache-Control': 'no-cache'}
1988
- r = requests.get(f"https://api.{default_source_address}/v3-flatcontainer/{package_name.lower()}/{package_version}/{package_name.lower()}.nuspec", timeout=5, headers=headers)
1989
- return r.status_code == 200
1990
- else:
1991
- raise ValueError(f"dotnet_package_is_available is not implemented yet for other sources than {default_source_address}.")
1992
-
1993
- @GeneralUtilities.check_arguments
1994
- def wait_until_dotnet_package_is_available(self, package_name: str, package_version: str, source: str):
1995
- return # TODO fix this
1996
- try: # pylint: disable=unreachable
1997
- while not self.dotnet_package_is_available(package_name, package_version, source):
1998
- time.sleep(30)
1999
- except:
2000
- pass
2001
-
2002
- @GeneralUtilities.check_arguments
2003
- def python_package_is_available(self, package_name: str, package_version: str, source: str):
2004
- default_source_address = "pypi.org"
2005
- if source == default_source_address:
2006
- GeneralUtilities.write_message_to_stdout(f"Wait until package {package_name} v{package_version} is available on {source}.")
2007
- headers = {'Cache-Control': 'no-cache'}
2008
- r = requests.get(f"https://{default_source_address}/pypi/{package_name}/{package_version}/json", timeout=5, headers=headers)
2009
- return r.status_code == 200
2010
- else:
2011
- raise ValueError(f"python_package_is_available is not implemented yet for other sources than {default_source_address}.")
2012
-
2013
- @GeneralUtilities.check_arguments
2014
- def wait_until_python_package_is_available(self, package_name: str, package_version: str, source: str):
2015
- return # TODO fix this
2016
- try: # pylint: disable=unreachable
2017
- while not self.python_package_is_available(package_name, package_version, source):
2018
- time.sleep(30)
2019
- except:
2020
- pass
2021
-
2022
1983
  @GeneralUtilities.check_arguments
2023
1984
  def create_deb_package(self, toolname: str, binary_folder: str, control_file_content: str, deb_output_folder: str, verbosity: int, permission_of_executable_file_as_octet_triple: int) -> None:
2024
1985
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 3.5.120
3
+ Version: 3.5.121
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
@@ -6,12 +6,12 @@ ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZ
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=lTNw2Th5xvjf9V_pQw6DSsZPdeLAdqOelfZPW8fCC-s,3063
10
- ScriptCollection/ScriptCollectionCore.py,sha256=9kyDdGMDZNKR7j579zjUSt3vvTLHA-vPw4_Sd2YhWmc,130059
9
+ ScriptCollection/SCLog.py,sha256=GEvh0m4OXz_0703XgY-LyAy9RDYg8x1baNZSrWhhu2A,3127
10
+ ScriptCollection/ScriptCollectionCore.py,sha256=eoVmIEoaU_B8sIgaJTN1e7ocurjsLyT2VzxvrsQLyV4,127859
11
11
  ScriptCollection/TasksForCommonProjectStructure.py,sha256=4aEuIf89jbgKE4uMYm4DlPDe9Iu1Zujo8wPOzDld09w,234867
12
12
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- scriptcollection-3.5.120.dist-info/METADATA,sha256=PbbVXi9-z9CwClIIuMdlLWkxve1wKz53TMNJYiLsdMA,7694
14
- scriptcollection-3.5.120.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
15
- scriptcollection-3.5.120.dist-info/entry_points.txt,sha256=3qMbfZEMhc_VTJj-bcLwB8AWcn9iXSB3l0AWpuu52Bs,3689
16
- scriptcollection-3.5.120.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
- scriptcollection-3.5.120.dist-info/RECORD,,
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,,