ScriptCollection 4.2.124__py3-none-any.whl → 4.2.126__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.
@@ -1,7 +1,6 @@
1
1
  import argparse
2
2
  import os
3
3
  from .TFCPS.TFCPS_CodeUnit_BuildCodeUnits import TFCPS_CodeUnit_BuildCodeUnits
4
- from .TFCPS.TFCPS_Tools_General import TFCPS_Tools_General
5
4
  from .SCLog import LogLevel
6
5
  from .GeneralUtilities import GeneralUtilities
7
6
  from .ScriptCollectionCore import ScriptCollectionCore
@@ -56,7 +55,7 @@ class AnionBuildPlatform:
56
55
  build_repo_folder:str=self.__configuration.build_repositories_folder
57
56
  GeneralUtilities.assert_condition(build_repo_folder.endswith("Build"),f"buildrepositoriesfolder {build_repo_folder} must end with 'Build'")
58
57
  self.__sc.assert_is_git_repository(build_repo_folder)
59
- product_name = TFCPS_Tools_General(self.__sc).get_product_name(build_repo_folder)
58
+ product_name = os.path.basename(build_repo_folder)[:-len("Build")]
60
59
  repository:str=os.path.join(build_repo_folder,"Submodules",product_name)
61
60
  self.__sc.assert_is_git_repository(repository)
62
61
  reference_repo:str=os.path.join(build_repo_folder,"Submodules",product_name+"Reference")
@@ -6,7 +6,7 @@ import traceback
6
6
  import shutil
7
7
  import keyboard
8
8
  from .ScriptCollectionCore import ScriptCollectionCore
9
- from .GeneralUtilities import GeneralUtilities
9
+ from .GeneralUtilities import GeneralUtilities, VersionEcholon
10
10
  from .SCLog import LogLevel, SCLog
11
11
  from .TFCPS.TFCPS_CodeUnit_BuildCodeUnits import TFCPS_CodeUnit_BuildCodeUnits
12
12
  from .TFCPS.TFCPS_Tools_General import TFCPS_Tools_General
@@ -299,7 +299,7 @@ def UpdateDependencies() -> int:
299
299
  parser.add_argument('--targetenvironment', required=False, default="QualityCheck")
300
300
  parser.add_argument('--additionalargumentsfile', required=False, default=None)
301
301
  parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
302
- args = parser.parse_args()
302
+ args = parser.parse_args()
303
303
  verbosity=LogLevel(int(args.verbosity))
304
304
  repo:str=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
305
305
  t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,False,False)
@@ -748,14 +748,34 @@ def OCRAnalysisOfRepository() -> int:
748
748
 
749
749
 
750
750
  def UpdateImagesInDockerComposeFile() -> int:
751
- parser = argparse.ArgumentParser(description="This function updates images in a Docker Compose file.")
752
- parser.add_argument('-f', '--file', required=False,default="./docker-compose.yml")
753
- #TODO add possibility to set version-echolon for each image specifically and pass this information to OCIImageManager
751
+ echolon_values = ", ".join(f"{e.value}={e.name}" for e in VersionEcholon)
752
+ parser = argparse.ArgumentParser(
753
+ description=(
754
+ "This function updates images in a Docker Compose file.\n"
755
+ "\n"
756
+ "Example (default LatestPatch for everything, but override per image):\n"
757
+ " scupdateimagesindockercomposefile -f docker-compose.yml -e 0 "
758
+ "-i Debian=3 -i PostgreSQL=1 -i Syft=5\n"
759
+ " -> Debian uses LatestVersion (3), PostgreSQL uses LatestPatchOrLatestMinor (1),\n"
760
+ " Syft is not updated (5=NoUpdate), all others use the default LatestPatch (0)."
761
+ ),
762
+ formatter_class=argparse.RawDescriptionHelpFormatter,
763
+ )
764
+ parser.add_argument('-f', '--file', required=False, default="./docker-compose.yml")
765
+ parser.add_argument('-e', '--echolon', type=int, required=False, default=None, help=f"Default version-echolon applied to all images that have no specific override. Possible values: {echolon_values}. If not set, the image-handler default is used.")
766
+ parser.add_argument('-i', '--image-echolon', action='append', default=[], help="Per-image echolon override in the format 'imagename=echolon' (e.g. 'Debian=3'). Can be specified multiple times.")
754
767
  args = parser.parse_args()
755
768
  sc = ScriptCollectionCore()
756
- file=GeneralUtilities.resolve_relative_path(args.file, os.getcwd())
757
- oci=OCIImageManager(sc)
758
- oci.update_image_in_docker_compose_file(file)
769
+ file = GeneralUtilities.resolve_relative_path(args.file, os.getcwd())
770
+ default_echolon: VersionEcholon = VersionEcholon(args.echolon) if args.echolon is not None else None
771
+ per_image_echolons: dict[str, VersionEcholon] = {}
772
+ for item in args.image_echolon:
773
+ if "=" not in item:
774
+ raise ValueError(f"Invalid value for --image-echolon: '{item}'. Expected format: 'imagename=echolon'.")
775
+ name_part, echolon_part = item.split("=", 1)
776
+ per_image_echolons[name_part.strip()] = VersionEcholon(int(echolon_part.strip()))
777
+ oci = OCIImageManager(sc)
778
+ oci.update_image_in_docker_compose_file(file, default_echolon, per_image_echolons)
759
779
  return 0
760
780
 
761
781
 
@@ -35,6 +35,7 @@ class VersionEcholon(Enum):
35
35
  LatestPatchOrLatestMinorOrNextMajor = 2
36
36
  LatestVersion = 3
37
37
  CustomAlgorithm = 4
38
+ NoUpdate = 5
38
39
 
39
40
  class Platform(Enum):
40
41
  Windows_AMD64 = 0
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import yaml
2
3
  from packaging.version import Version
3
4
  from ..GeneralUtilities import GeneralUtilities
4
5
  from ..ScriptCollectionCore import ScriptCollectionCore
@@ -170,15 +171,46 @@ class OCIImageManager:
170
171
  @GeneralUtilities.check_arguments
171
172
  def get_images_used_in_docker_compose_file(self,docker_compose_file:str)->dict[str,tuple[str,str,str]]:#returns dict[service_name,[image_name,image_address,current_tag]]
172
173
  GeneralUtilities.assert_file_exists(docker_compose_file)
173
- return {}#TODO implement function
174
+ result: dict[str, tuple[str, str, str]] = {}
175
+ with open(docker_compose_file, "r", encoding="utf-8") as f:
176
+ compose_data = yaml.safe_load(f)
177
+ services = (compose_data or {}).get("services", {}) or {}
178
+ for service_name, service_definition in services.items():
179
+ if not isinstance(service_definition, dict):
180
+ continue
181
+ image_value = service_definition.get("image")
182
+ if not isinstance(image_value, str) or not image_value:
183
+ continue
184
+ last_colon = image_value.rfind(":")
185
+ last_slash = image_value.rfind("/")
186
+ if last_colon == -1 or last_colon < last_slash:
187
+ image_address = image_value
188
+ current_tag = "latest"
189
+ else:
190
+ image_address = image_value[:last_colon]
191
+ current_tag = image_value[last_colon + 1:]
192
+ image_name = image_address.rsplit("/", 1)[-1]
193
+ result[service_name] = (image_name, image_address, current_tag)
194
+ return result
174
195
 
175
196
  @GeneralUtilities.check_arguments
176
- def update_image_in_docker_compose_file(self,docker_compose_file:str)->None:
177
- for service,service_information in self.get_images_used_in_docker_compose_file(docker_compose_file).items():#pylint:disable=unused-variable
197
+ def update_image_in_docker_compose_file(self,docker_compose_file:str,default_echolon:VersionEcholon=None,per_image_echolons:dict[str,VersionEcholon]=None)->None:
198
+ if per_image_echolons is None:
199
+ per_image_echolons = {}
200
+ for service,service_information in self.get_images_used_in_docker_compose_file(docker_compose_file).items():
178
201
  image_name=service_information[0]
179
202
  image_address=service_information[1]
180
203
  current_tag=service_information[2]
181
204
  image_handler=self.get_image_handler(image_name)
182
- new_versions_for_address=self.get_available_versions_of_image_which_are_newer(image_name,image_address,self.tag_to_version(image_name,current_tag),image_handler.get_default_echolon_for_update())
183
- new_tag=self.version_to_tag(image_name,new_versions_for_address)#pylint:disable=unused-variable
184
- #TODO update tag for service in docker-compose-file to new_tag
205
+ effective_echolon=per_image_echolons.get(image_name,default_echolon)
206
+ if effective_echolon is None:
207
+ effective_echolon=image_handler.get_default_echolon_for_update()
208
+ new_versions_for_address=self.get_available_versions_of_image_which_are_newer(image_name,image_address,self.tag_to_version(image_name,current_tag),effective_echolon)
209
+ new_tag=self.version_to_tag(image_name,new_versions_for_address)
210
+ if new_tag is not None and new_tag != current_tag:
211
+ new_image_reference = f"{image_address}:{new_tag}"
212
+ with open(docker_compose_file, "r", encoding="utf-8") as f:
213
+ compose_data = yaml.safe_load(f)
214
+ compose_data["services"][service]["image"] = new_image_reference
215
+ with open(docker_compose_file, "w", encoding="utf-8") as f:
216
+ yaml.safe_dump(compose_data, f, default_flow_style=False, sort_keys=False)
@@ -38,7 +38,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
38
38
  from .ProgramRunnerPopen import ProgramRunnerPopen
39
39
  from .SCLog import SCLog, LogLevel
40
40
 
41
- version = "4.2.124"
41
+ version = "4.2.126"
42
42
  __version__ = version
43
43
 
44
44
  class VSCodeWorkspaceShellTask:
@@ -535,6 +535,15 @@ class ScriptCollectionCore:
535
535
  self.assert_is_git_repository(folder)
536
536
  self.run_program_argsasarray("git", ["push", remotename, "--delete", branchname], folder, throw_exception_if_exitcode_is_not_zero=True)
537
537
 
538
+ @GeneralUtilities.check_arguments
539
+ def git_create_branch(self, folder: str, new_branch_name: str, base: str = "HEAD", checkout: bool = True) -> None:
540
+ self.assert_is_git_repository(folder)
541
+ if checkout:
542
+ args = ["checkout", "-b", new_branch_name, base]
543
+ else:
544
+ args = ["branch", new_branch_name, base]
545
+ self.run_program_argsasarray("git", args, folder, throw_exception_if_exitcode_is_not_zero=True)
546
+
538
547
  @GeneralUtilities.check_arguments
539
548
  def git_push_with_retry(self, folder: str, remotename: str, localbranchname: str, remotebranchname: str, forcepush: bool = False, pushalltags: bool = True, verbosity: LogLevel = LogLevel.Quiet, amount_of_attempts: int = 5) -> None:
540
549
  GeneralUtilities.retry_action(lambda: self.git_push(folder, remotename, localbranchname, remotebranchname, forcepush, pushalltags, verbosity), amount_of_attempts)
@@ -101,7 +101,7 @@ class TFCPS_MergeToMain_CLI:
101
101
  build_repo=GeneralUtilities.resolve_relative_path("../../..",file)
102
102
  sc.assert_is_git_repository(build_repo)
103
103
 
104
- default_product_name=TFCPS_Tools_General(sc).get_product_name(build_repo)
104
+ default_product_name=os.path.basename(build_repo)[:-len("Build")]
105
105
 
106
106
  if args.mergesourcebranch is not None:
107
107
  default_merge_source_branch=args.mergesourcebranch#other/next-release
@@ -305,7 +305,7 @@ class TFCPS_MergeToStable_CLI:
305
305
  build_repo=GeneralUtilities.resolve_relative_path("../../..",file)
306
306
  sc.assert_is_git_repository(build_repo)
307
307
 
308
- default_product_name=TFCPS_Tools_General(sc).get_product_name(build_repo)
308
+ default_product_name=os.path.basename(build_repo)[:-len("Build")]
309
309
 
310
310
  if args.verbosity is not None:
311
311
  default_loglevel=LogLevel(int( args.verbosity))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.2.124
3
+ Version: 4.2.126
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Author-email: Marius Göcke <marius.goecke@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/anionDev/ScriptCollection
@@ -1,7 +1,7 @@
1
- ScriptCollection/AnionBuildPlatform.py,sha256=Ug9bUMJObWZXGFUX0SyiNFc1dNTwUkWp2vxdCBA7ag8,11858
1
+ ScriptCollection/AnionBuildPlatform.py,sha256=9h74ltLwt1Lt-C9NSdn3PBP5YryZhFSczkr4MBCqNAs,11783
2
2
  ScriptCollection/CertificateUpdater.py,sha256=dR5JpJDlZdjD4_pgMz7zCrt1IM7VfatmK6pULSczxQw,9693
3
- ScriptCollection/Executables.py,sha256=HaqvT6W3LAT2UOAqDPqPK-R6cT3x6d_2T24OQPyz9Zg,48610
4
- ScriptCollection/GeneralUtilities.py,sha256=4BmzJhTPAZmKQd5YlMuX0E5Dl6fhuVkmVaCpST0WzRk,67654
3
+ ScriptCollection/Executables.py,sha256=zWI6RxMnJ1n8K76hkauBlnSbhd3vKBwJrwNAXx6sqGQ,50087
4
+ ScriptCollection/GeneralUtilities.py,sha256=NOdih5ZSQTHBYwe-ncTXXGCmGkofdDjChA_PV6dj0is,67672
5
5
  ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
6
6
  ScriptCollection/ProcessesRunner.py,sha256=o5raxIt3lknNPoPrjNzJ2bprRPJ3SnL0rrR7crraD7E,1523
7
7
  ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
@@ -9,10 +9,10 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
9
9
  ScriptCollection/ProgramRunnerPopen.py,sha256=8tP0xWKeRYoGlaNB3iUh4o61O-tKtcxrS7IUqtU85C4,4091
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=4lxbUFMIWMbthM5Q_QaFjvZfAsNpKlXeqfEbiofg_DI,5109
11
11
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
12
- ScriptCollection/ScriptCollectionCore.py,sha256=yMt73V_E_uK_KN9Y6QD0uaG6PdFe9fbbpPDcS_NItHE,205530
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=HYoh8Mj9kZXLrWNwC7hukPrpL-4GWkkM3dZz7yQE0PM,205987
13
13
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=o129UYDtLymCRjMZBP9Puaj19ueMHoNt6UTLspfnaRc,1758
15
- ScriptCollection/OCIImages/OCIImageManager.py,sha256=TaSGXaDH4KWxN8Iv30m9zyitcaDYhEZVEPdKO3C3zfs,10712
15
+ ScriptCollection/OCIImages/OCIImageManager.py,sha256=en97kK75sc7ZJOkX7VE_ZwycfasTBAQQCSQdPIYC91s,12451
16
16
  ScriptCollection/OCIImages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebian.py,sha256=rty9SnftreYWLIwvdUn4LhiHqCTevb_tWuYWoOnRJuo,732
18
18
  ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebianSlim.py,sha256=M-4qxKWBZRtKdYQ-uXgfrxRBoZTXEjgqCxFXyFxTyzc,736
@@ -29,8 +29,8 @@ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=wLOCoMJVkhqKilJrYA
29
29
  ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=884wbxBvYIIqx-5pT0AMDZXYodWuLBETEpvSX-ci5lk,19774
30
30
  ScriptCollection/TFCPS/TFCPS_CreateRelease.py,sha256=yqGstRjRfVVGbqrcBgtYStqth2x2SvBb3y2Ht8GsuMQ,6554
31
31
  ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=Tpzgiz6m3-cYCkObZOG5Uu7oM-EMoWFzzRpLl3Lblqo,2023
32
- ScriptCollection/TFCPS/TFCPS_MergeToMain.py,sha256=WgQ8V5T5gOmzJGP6J1NRH5wfQno5zO5I8ZhSVm72C6g,7488
33
- ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=mgGDXzphexHPjsrFvf_tx_wueLoOXi42j0AhjQ9S7Y4,22233
32
+ ScriptCollection/TFCPS/TFCPS_MergeToMain.py,sha256=Vwj7IWmvwIICXiv7I-c6MkxbqlRWCEwzaKW6dgEUjCM,7480
33
+ ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=m8YGyt3w31U2izXm-DsM2tHjJfXTsceSCu_VjfCilxA,22225
34
34
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=f0Uq1cA_4LvmL72cal0crrbKF6PcxL13D9wBKuQ1YBw,2328
35
35
  ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=j0erTZMbLKj50pXOEAxkqi9fXEWN3o6YwhLJdfCki2o,107454
36
36
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -53,8 +53,8 @@ ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=fqGhXNx8tK
53
53
  ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=WhOsMpJxNGqnQGA3nJ99ruyqymxBeJxCcpK98zJduTo,1680
55
55
  ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
- scriptcollection-4.2.124.dist-info/METADATA,sha256=b8JhjgFrmzeT7EDO_r4qAae0bG2AJwQZu5u05ocgbQg,7697
57
- scriptcollection-4.2.124.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
58
- scriptcollection-4.2.124.dist-info/entry_points.txt,sha256=ySZ09rptnBxyfpU-K62zmoUFH-0xWZUxzoPScoXubrg,5045
59
- scriptcollection-4.2.124.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
60
- scriptcollection-4.2.124.dist-info/RECORD,,
56
+ scriptcollection-4.2.126.dist-info/METADATA,sha256=ZL-hqS35Ciu5unX212NNP9aVm_3gjPQqhSFoCG1TT1o,7697
57
+ scriptcollection-4.2.126.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
58
+ scriptcollection-4.2.126.dist-info/entry_points.txt,sha256=ySZ09rptnBxyfpU-K62zmoUFH-0xWZUxzoPScoXubrg,5045
59
+ scriptcollection-4.2.126.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
60
+ scriptcollection-4.2.126.dist-info/RECORD,,