ScriptCollection 4.4.36__py3-none-any.whl → 4.4.38__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.
@@ -1375,6 +1375,14 @@ class GeneralUtilities:
1375
1375
  @staticmethod
1376
1376
  @check_arguments
1377
1377
  def retry_action(action, amount_of_attempts: int, action_name: str = None,delay_in_seconds:int=2) -> None:
1378
+ return GeneralUtilities.retry_action_if(action, lambda exception: True, amount_of_attempts, action_name, delay_in_seconds)
1379
+
1380
+ @staticmethod
1381
+ @check_arguments
1382
+ def retry_action_if(action, exception_is_retryable, amount_of_attempts: int, action_name: str = None,delay_in_seconds:int=2) -> None:
1383
+ """Executes action and retries it if it throws an exception for which exception_is_retryable returns True.
1384
+ An exception for which exception_is_retryable returns False is propagated immediately without any further attempt,
1385
+ because retrying an action which failed for a permanent reason can not succeed."""
1378
1386
  amount_of_fails = 0
1379
1387
  last_exception:Exception=None
1380
1388
  GeneralUtilities.assert_condition(0<amount_of_attempts,"amount_of_attempts must be greater than 0.")
@@ -1383,6 +1391,8 @@ class GeneralUtilities:
1383
1391
  result = action()
1384
1392
  return result
1385
1393
  except Exception as e:
1394
+ if not exception_is_retryable(e):
1395
+ raise
1386
1396
  time.sleep(delay_in_seconds)
1387
1397
  amount_of_fails = amount_of_fails+1
1388
1398
  last_exception=e
@@ -40,7 +40,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
40
40
  from .ProgramRunnerPopen import ProgramRunnerPopen
41
41
  from .SCLog import SCLog, LogLevel
42
42
 
43
- version = "4.4.36"
43
+ version = "4.4.38"
44
44
  __version__ = version
45
45
 
46
46
  class VSCodeWorkspaceShellTask:
@@ -223,6 +223,9 @@ class ScriptCollectionCore:
223
223
  # Kinds which are allowed in the environment-variables-configuration-file (see get_environment_variables_configuration_file).
224
224
  __allowed_environment_variable_kinds: list[str] = ["literal", "hostenvvariable", "file"]
225
225
 
226
+ # Indicators which occur in the error-message of a failed program-call when the call failed because an operation ran into a timeout. See __error_is_timeout_error.
227
+ __timeout_error_indicators: list[str] = ["timeout", "timed out", "context deadline exceeded"]
228
+
226
229
  def __init__(self):
227
230
  self.program_runner = ProgramRunnerPopen()
228
231
  self.call_program_runner_directly = None
@@ -508,6 +511,28 @@ class ScriptCollectionCore:
508
511
  result = tag in tags
509
512
  return result
510
513
 
514
+ @staticmethod
515
+ @GeneralUtilities.check_arguments
516
+ def __error_is_timeout_error(exception: Exception) -> bool:
517
+ """Returns True if and only if the message of the given exception indicates that the failed operation ran into a timeout."""
518
+ message = str(exception).lower()
519
+ return any(indicator in message for indicator in ScriptCollectionCore.__timeout_error_indicators)
520
+
521
+ @GeneralUtilities.check_arguments
522
+ def docker_login(self, registry: str, username: str, password: str) -> None:
523
+ """Logs in to the given docker-registry."""
524
+ arg = f"login {registry} -u {username} -p {password}"
525
+ arg_for_log = f"login {registry} -u {username} -p ***"
526
+ self.run_program("docker", arg, arguments_for_log=arg_for_log, print_live_output=self.log.loglevel == LogLevel.Debug)
527
+
528
+ @GeneralUtilities.check_arguments
529
+ def docker_login_with_retry(self, registry: str, username: str, password: str, amount_of_attempts: int = 5) -> None:
530
+ """Does the same as docker_login but retries the login if it failed due to a timeout.
531
+ A timeout (for example a tls-handshake-timeout, whose duration is hardcoded in the docker-daemon and therefore not configurable) occurs
532
+ sporadically when the registry or the connection to it is temporarily slow, so in this case a further attempt can succeed. Errors with a
533
+ permanent cause like wrong credentials would fail again in every further attempt, so only timeout-errors are retried."""
534
+ GeneralUtilities.retry_action_if(lambda: self.docker_login(registry, username, password), ScriptCollectionCore.__error_is_timeout_error, amount_of_attempts)
535
+
511
536
  def login_to_defined_docker_registries(self)->None:
512
537
  """Logs in to every registry for which credentials are available on this machine (see get_docker_registry_credentials_from_environment_variables).
513
538
  The login is only executed once per instance: the credentials do not change while a process runs, and the login has to be
@@ -520,9 +545,7 @@ class ScriptCollectionCore:
520
545
  self.log.log("No docker registry credentials defined. Skipping docker login.",LogLevel.Debug)
521
546
  else:
522
547
  for registry,username,password in registries:
523
- arg=f"login {registry} -u {username} -p {password}"
524
- arg_for_log=f"login {registry} -u {username} -p ***"
525
- self.run_program("docker",arg,arguments_for_log=arg_for_log,print_live_output=self.log.loglevel==LogLevel.Debug)
548
+ self.docker_login_with_retry(registry,username,password)
526
549
 
527
550
  @staticmethod
528
551
  @GeneralUtilities.check_arguments
@@ -1826,7 +1849,7 @@ class ScriptCollectionCore:
1826
1849
  os.remove(thumbnail_to_delete)
1827
1850
 
1828
1851
  @GeneralUtilities.check_arguments
1829
- def start_rtsp_test_stream(self, target_address: str, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None) -> int:
1852
+ def start_rtsp_test_stream(self, target_address: str, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None, background_color: str = "black") -> int:
1830
1853
  """Starts a video-stream which shows a number that is counted up once per second and publishes it to the
1831
1854
  given rtsp-address. Returns the process-id of the running ffmpeg, which can be passed to
1832
1855
  GeneralUtilities.kill_process to stop the stream again.
@@ -1844,9 +1867,11 @@ stream; ffmpeg does not open a port by itself.
1844
1867
  for the filter-syntax of ffmpeg, and a stream which only exists for testcases does not
1845
1868
  need a text which requires that.
1846
1869
  :param font_file: The font which is used. When it is not given then a font of the operating-system is used.
1870
+ :param background_color: The color of the background, in the notation ffmpeg uses for a color (a name like
1871
+ "black" or "blue", or "0xRRGGBB", or "#RRGGBB").
1847
1872
  """
1848
1873
  GeneralUtilities.assert_condition(target_address.startswith("rtsp://"), f"'{target_address}' is not a rtsp-address.")
1849
- argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file) + [
1874
+ argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file, background_color) + [
1850
1875
  "-f", "rtsp",
1851
1876
  # Tcp instead of udp, because udp loses pictures under load, which would make a screenshot show
1852
1877
  # something else than the number which belongs to the moment it was taken.
@@ -1855,7 +1880,7 @@ stream; ffmpeg does not open a port by itself.
1855
1880
  return self.run_program_argsasarray_async("ffmpeg", argument, working_directory, title=f"RTSP-test-stream ({target_address})")
1856
1881
 
1857
1882
  @GeneralUtilities.check_arguments
1858
- def create_test_stream_video(self, target_file: str, duration_in_seconds: int, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None) -> None:
1883
+ def create_test_stream_video(self, target_file: str, duration_in_seconds: int, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None, background_color: str = "black") -> None:
1859
1884
  """Writes a video-file which shows the same picture as start_rtsp_test_stream, but into a file instead of
1860
1885
  to a rtsp-address and as fast as possible instead of in realtime.
1861
1886
 
@@ -1865,18 +1890,23 @@ are the same, so a picture of this file can be used as the baseline for a pictur
1865
1890
  :param target_file: The video-file which is written.
1866
1891
  :param duration_in_seconds: How long the video is. The number is counted up once per second, so a video of ten
1867
1892
  seconds contains the numbers 0 to 9.
1893
+ :param background_color: The color of the background. It has to be the one the stream is started with, otherwise
1894
+ a picture of this file does not show the same as a picture of that stream.
1868
1895
  """
1869
- argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file, realtime=False) + [
1896
+ argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file, background_color, realtime=False) + [
1870
1897
  "-t", str(duration_in_seconds),
1871
1898
  "-y", target_file]
1872
1899
  self.run_program_argsasarray("ffmpeg", argument, working_directory, throw_exception_if_exitcode_is_not_zero=True)
1873
1900
 
1874
1901
  @GeneralUtilities.check_arguments
1875
- def __get_arguments_for_test_stream(self, additional_text: str, width: int, height: int, frames_per_second: int, font_file: str, realtime: bool = True) -> list[str]:
1902
+ def __get_arguments_for_test_stream(self, additional_text: str, width: int, height: int, frames_per_second: int, font_file: str, background_color: str, realtime: bool = True) -> list[str]:
1876
1903
  """Returns the ffmpeg-arguments which produce the picture of a test-stream. The picture is defined here
1877
1904
  only once, so that the video which is used as the expected result really shows the same as the stream."""
1878
1905
  if additional_text is not None:
1879
1906
  GeneralUtilities.assert_condition(re.fullmatch("[a-zA-Z0-9 ]+", additional_text) is not None, f"The additional text must consist of letters, digits and spaces only, but it is '{additional_text}'.")
1907
+ # The color is put into the description of the lavfi-source, whose parts are separated by colons, so a
1908
+ # value which contains one would not be a color anymore but an additional option of that source.
1909
+ GeneralUtilities.assert_condition(re.fullmatch("[a-zA-Z0-9#]+", background_color) is not None, f"The background-color must consist of letters, digits and the number-sign only, but it is '{background_color}'.")
1880
1910
  if font_file is None:
1881
1911
  font_file = self.__get_font_file_for_drawing_text()
1882
1912
  # "%{eif:t:d}" is the amount of seconds the stream is running, rounded down to an integer, so the number
@@ -1893,7 +1923,7 @@ only once, so that the video which is used as the expected result really shows t
1893
1923
  result.append("-re")
1894
1924
  result = result + [
1895
1925
  "-f", "lavfi",
1896
- "-i", f"color=c=black:s={width}x{height}:r={frames_per_second}",
1926
+ "-i", f"color=c={background_color}:s={width}x{height}:r={frames_per_second}",
1897
1927
  "-vf", ",".join(text_filters),
1898
1928
  "-c:v", "libx264",
1899
1929
  "-preset", "ultrafast",
@@ -3586,7 +3616,7 @@ TXDX
3586
3616
  "link", "meta", "param", "source", "track", "wbr"}
3587
3617
 
3588
3618
  class _Node:
3589
- __slots__ = ("tag", "attrs", "children", "text", "is_void", "raw")
3619
+ __slots__ = ("tag", "attrs", "children", "text", "is_void", "raw", "text_ends_with_whitespace")
3590
3620
  def __init__(self, tag=None, attrs=(), text=None, is_void=False, raw=None):
3591
3621
  self.tag = tag
3592
3622
  self.attrs = list(attrs)
@@ -3594,6 +3624,9 @@ TXDX
3594
3624
  self.text = text
3595
3625
  self.is_void = is_void
3596
3626
  self.raw = raw
3627
+ # Whether the text of this node was followed by whitespace in the input. It is needed to append
3628
+ # further text to this node with the whitespace which was between both, see _Builder._append_text.
3629
+ self.text_ends_with_whitespace = False
3597
3630
 
3598
3631
  class _Builder(HTMLParser):
3599
3632
  def __init__(self):
@@ -3622,16 +3655,40 @@ TXDX
3622
3655
  if len(self.stack) > 1 and self.stack[-1].tag == tag:
3623
3656
  self.stack.pop()
3624
3657
 
3658
+ def _append_text(self, text, whitespace_before, whitespace_after):
3659
+ # Text which belongs together has to end up in one node, because the serializer writes every node
3660
+ # into a line of its own. The parser hands out the text of an element in several pieces: it reports
3661
+ # an ampersand which does not begin a character-reference separately (which is what happens to the
3662
+ # "&&" of an angular-expression) and it reports every character-reference separately. Without joining
3663
+ # them here, "@if (a && b) {" would become three lines and would not be parsable anymore, and
3664
+ # "Tom &amp; Jerry" would lose the spaces around the ampersand.
3665
+ children = self._top().children
3666
+ if children and children[-1].text is not None:
3667
+ previous = children[-1]
3668
+ separator = " " if previous.text_ends_with_whitespace or whitespace_before else ""
3669
+ previous.text = previous.text + separator + text
3670
+ previous.text_ends_with_whitespace = whitespace_after
3671
+ else:
3672
+ node = _Node(text=text)
3673
+ node.text_ends_with_whitespace = whitespace_after
3674
+ children.append(node)
3675
+
3625
3676
  def handle_data(self, data):
3626
3677
  t = " ".join(data.split())
3627
3678
  if t:
3628
- self._top().children.append(_Node(text=t))
3679
+ self._append_text(t, data[:1].isspace(), data[-1:].isspace())
3680
+ else:
3681
+ # The piece consists of whitespace only. It carries no text, but it separates the text before it
3682
+ # from the text after it, which has to be kept.
3683
+ children = self._top().children
3684
+ if data and children and children[-1].text is not None:
3685
+ children[-1].text_ends_with_whitespace = True
3629
3686
 
3630
3687
  def handle_entityref(self, name):
3631
- self._top().children.append(_Node(text=f"&{name};"))
3688
+ self._append_text(f"&{name};", False, False)
3632
3689
 
3633
3690
  def handle_charref(self, name):
3634
- self._top().children.append(_Node(text=f"&#{name};"))
3691
+ self._append_text(f"&#{name};", False, False)
3635
3692
 
3636
3693
  def handle_comment(self, data):
3637
3694
  self._top().children.append(_Node(raw=f"<!--{data}-->"))
@@ -213,7 +213,8 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
213
213
  for unit in root.findall(f".//{ns_prefix}unit"):
214
214
  for segment in unit.findall(f"{ns_prefix}segment"):
215
215
  segment.set("state", "initial")
216
- tree.write(target_file, encoding="utf-8", xml_declaration=True)
216
+ with open(target_file, "wb") as f:#binary mode (as opposed to passing the filename directly to tree.write): guarantees LF line-endings regardless of the OS' default line-ending, since binary mode never translates "\n" to "\r\n". The line-endings of the content copied from the base-file are normalized to LF too, because an XML-parser normalizes "\r\n" and "\r" to "\n" while parsing.
217
+ tree.write(f, encoding="utf-8", xml_declaration=True)
217
218
 
218
219
  angular_json_file=self.get_codeunit_folder()+"/angular.json"
219
220
  if os.path.isfile(angular_json_file):
@@ -226,7 +227,7 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
226
227
  for lang in languages
227
228
  }
228
229
  i18n_config.setdefault("locales", {}).update(new_locales)
229
- with angular_json_path.open("w", encoding="utf-8") as f:
230
+ with angular_json_path.open("w", encoding="utf-8", newline="\n") as f:#newline="\n": guarantees LF line-endings regardless of the OS' default line-ending, since without this Python would translate "\n" to "\r\n" on Windows.
230
231
  json.dump(angular_config, f, ensure_ascii=False, indent=2)
231
232
 
232
233
  @GeneralUtilities.check_arguments
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.4.36
3
+ Version: 4.4.38
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Author-email: Marius Göcke <marius.goecke@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -2,7 +2,7 @@ ScriptCollection/AnionBuildPlatform.py,sha256=LF9b4f4iqgsjgXZjS0RHiEBw73tQANfu0O
2
2
  ScriptCollection/ArbTranslationsOrganizer.py,sha256=FLJcNP6qFTQOkxL7es0Sq3O7kb_TgoRreqH-uogR4xA,12201
3
3
  ScriptCollection/CertificateUpdater.py,sha256=bD0VhKQsD2cNRTG1kzMkhgpd0BZw7igbG30goKw5p1A,9749
4
4
  ScriptCollection/Executables.py,sha256=Ovq6LVhtP6mqCPmBxch9WgTmePBk7F8MLyZUBkQloAE,74171
5
- ScriptCollection/GeneralUtilities.py,sha256=JO95CNaNjH_ooZ0db56kwRjRDgT_-RdWAvClItlnQBM,72045
5
+ ScriptCollection/GeneralUtilities.py,sha256=znIrHp9wV3yPwLHb5300LjxQ2MTj0NJC6Z0my3LY0Mk,72759
6
6
  ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
7
7
  ScriptCollection/ProcessesRunner.py,sha256=Va9O-ohWoRfe4pO2gPBzc940gkM5BpP4Txcu1CmLOvg,1494
8
8
  ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
@@ -12,7 +12,7 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=ot9Ib-plQ8wejR9M2XXfnx6GR-va9k8SH1g
12
12
  ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
13
13
  ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=rD8eC5lMUe5MHmCBHfYft_G-N9IbvtsFGkU7EMwPjrY,5779
14
14
  ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
15
- ScriptCollection/ScriptCollectionCore.py,sha256=oqRxDHa1Pd1rl9XNh5i-gRIuu_X8_vrqLVx5oIL6h6s,300376
15
+ ScriptCollection/ScriptCollectionCore.py,sha256=4sZqrMAYWjux5TWaUUniqF6bNmNceDbVjIeXOjpGkVE,305107
16
16
  ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
17
17
  ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
18
18
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -65,7 +65,7 @@ ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py,sha256=m4Pax-U6o5XuspLnLf
65
65
  ScriptCollection/TFCPS/Go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
66
  ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py,sha256=HDZlU70lF4nxUgsi7-TaFrFpbw_imw6dBagfgL6tDW8,10593
67
67
  ScriptCollection/TFCPS/Maven/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
68
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=U2J_jZxy9-tJdShx_bhDkASgDbkL0BsHGtDdEYFhb7o,16534
68
+ ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=kYh2C1B6cKfDeRR-CkOqGBV5T3VA9Z-tNKthU5GR6S4,17096
69
69
  ScriptCollection/TFCPS/NodeJS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
70
70
  ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=Wi9anRljuvW1-UplYhI_QNR2szxaitHiXVJ6p4nUEI8,21089
71
71
  ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -73,8 +73,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
73
73
  ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
75
75
  ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
- scriptcollection-4.4.36.dist-info/METADATA,sha256=57adtdGzdU5J1VzI3KzV9XVpbUoNLjppxnOB7PS6Kv0,7646
77
- scriptcollection-4.4.36.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
78
- scriptcollection-4.4.36.dist-info/entry_points.txt,sha256=GNma7tN0J59EvK71su-G1w22RnZ05bXcPrELyLx3AL0,6151
79
- scriptcollection-4.4.36.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
80
- scriptcollection-4.4.36.dist-info/RECORD,,
76
+ scriptcollection-4.4.38.dist-info/METADATA,sha256=4XDPfDtKEPzPKGljWrd0zqJGHTbZDHK0K7K1nXagJ-4,7646
77
+ scriptcollection-4.4.38.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
78
+ scriptcollection-4.4.38.dist-info/entry_points.txt,sha256=GNma7tN0J59EvK71su-G1w22RnZ05bXcPrELyLx3AL0,6151
79
+ scriptcollection-4.4.38.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
80
+ scriptcollection-4.4.38.dist-info/RECORD,,