ScriptCollection 3.5.148__py3-none-any.whl → 3.5.149__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,3 +1,4 @@
1
+ import base64
1
2
  import os
2
3
  import argparse
3
4
  import time
@@ -412,12 +413,6 @@ def FolderExists() -> int:
412
413
  return 2
413
414
 
414
415
 
415
- def SetContentOfFile() -> int:
416
- GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
417
- # TODO implement function
418
- return 1
419
-
420
-
421
416
  def PrintFileContent() -> int:
422
417
  parser = argparse.ArgumentParser(description="This function prints the size of a file")
423
418
  parser.add_argument('-p', '--path', required=True)
@@ -726,3 +721,30 @@ def UpdateImagesInDockerComposeFile() -> int:
726
721
  args.file = os.path.join(os.getcwd(), "docker-compose.yml")
727
722
  iu.update_all_services_in_docker_compose_file(args.file, VersionEcholon.LatestPatch, [])
728
723
  return 0
724
+
725
+
726
+ def SetFileContent() -> int:
727
+ parser = argparse.ArgumentParser(description="This function writes content into a file.")
728
+ parser.add_argument('-p', '--path', required=True)
729
+ parser.add_argument('-b', '--argumentisinbase64', action='store_true', required=False, default=False)
730
+ parser.add_argument('-c', '--content', required=True)
731
+ parser.add_argument('-e', '--encoding', required=False, default="utf-8")
732
+ args = parser.parse_args()
733
+ sc = ScriptCollectionCore()
734
+ content = args.content
735
+ if args.argumentisinbase64:
736
+ base64_string: str = args.content
737
+ base64_bytes = base64_string.encode('utf-8')
738
+ original_bytes = base64.b64decode(base64_bytes)
739
+ content = original_bytes.decode('utf-8')
740
+ sc.set_file_content(args.path, content, args.encoding)
741
+ return 0
742
+
743
+
744
+ def GenerateTaskfileFromWorkspacefile() -> int:
745
+ parser = argparse.ArgumentParser(description="Generates a taskfile.yml-file from a .code-workspace-file")
746
+ parser.add_argument('-f', '--repositoryfolder', required=True)
747
+ args = parser.parse_args()
748
+ t = TasksForCommonProjectStructure()
749
+ t.generate_tasksfile_from_workspace_file(args.repositoryfolder)
750
+ return 0
@@ -8,6 +8,7 @@ import time
8
8
  from io import BytesIO
9
9
  import itertools
10
10
  import math
11
+ import base64
11
12
  import os
12
13
  from queue import Queue, Empty
13
14
  from concurrent.futures import ThreadPoolExecutor
@@ -33,7 +34,7 @@ from .ProgramRunnerPopen import ProgramRunnerPopen
33
34
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
34
35
  from .SCLog import SCLog, LogLevel
35
36
 
36
- version = "3.5.148"
37
+ version = "3.5.149"
37
38
  __version__ = version
38
39
 
39
40
 
@@ -130,7 +131,8 @@ class ScriptCollectionCore:
130
131
 
131
132
  @GeneralUtilities.check_arguments
132
133
  def find_file_by_extension(self, folder: str, extension_without_dot: str):
133
- result = [file for file in GeneralUtilities.get_direct_files_of_folder(folder) if file.endswith(f".{extension_without_dot}")]
134
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
135
+ result = [file for file in self.list_content(folder, True, False, False) if file.endswith(f".{extension_without_dot}")]
134
136
  result_length = len(result)
135
137
  if result_length == 0:
136
138
  raise FileNotFoundError(f"No file available in folder '{folder}' with extension '{extension_without_dot}'.")
@@ -778,6 +780,26 @@ class ScriptCollectionCore:
778
780
  return False
779
781
  raise ValueError(f"Fatal error occurrs while checking whether folder '{path}' exists. StdErr: '{stderr}'")
780
782
 
783
+ @GeneralUtilities.check_arguments
784
+ def get_file_content(self, path: str, encoding: str = "utf-8") -> str:
785
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
786
+ if self.program_runner.will_be_executed_locally():
787
+ return GeneralUtilities.read_text_from_file(path, encoding)
788
+ else:
789
+ result = self.run_program_argsasarray("scprintfilecontent", ["--path", path, "--encofing", encoding]) # works platform-indepent
790
+ return result[1].replace("\\n", "\n")
791
+
792
+ @GeneralUtilities.check_arguments
793
+ def set_file_content(self, path: str, content: str, encoding: str = "utf-8") -> None:
794
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
795
+ if self.program_runner.will_be_executed_locally():
796
+ GeneralUtilities.write_text_to_file(path, content, encoding)
797
+ else:
798
+ content_bytes = content.encode('utf-8')
799
+ base64_bytes = base64.b64encode(content_bytes)
800
+ base64_string = base64_bytes.decode('utf-8')
801
+ self.run_program_argsasarray("scsetfilecontent", ["--path", path, "--argumentisinbase64", "--content", base64_string]) # works platform-indepent
802
+
781
803
  @GeneralUtilities.check_arguments
782
804
  def remove(self, path: str) -> None:
783
805
  """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
@@ -2383,64 +2383,67 @@ class TasksForCommonProjectStructure:
2383
2383
 
2384
2384
  @GeneralUtilities.check_arguments
2385
2385
  def generate_tasksfile_from_workspace_file(self, repository_folder: str, append_cli_args_at_end: bool = False) -> None:
2386
- self.__sc.assert_is_git_repository(repository_folder)
2387
- sc: ScriptCollectionCore = ScriptCollectionCore()
2388
- workspace_file: str = sc.find_file_by_extension(repository_folder, "code-workspace")
2389
- task_file: str = os.path.join(repository_folder, "Taskfile.yml")
2390
- lines: list[str] = ["version: '3'", GeneralUtilities.empty_string, "tasks:", GeneralUtilities.empty_string]
2391
- workspace_file_content: str = GeneralUtilities.read_text_from_file(workspace_file)
2392
- jsoncontent = json.loads(workspace_file_content)
2393
- tasks = jsoncontent["tasks"]["tasks"]
2394
- tasks.sort(key=lambda x: x["label"].split("/")[-1], reverse=False) # sort by the label of the task
2395
- for task in tasks:
2396
- if task["type"] == "shell":
2397
-
2398
- description: str = task["label"]
2399
- name: str = GeneralUtilities.to_pascal_case(description)
2400
- command = task["command"]
2401
- relative_script_file = task["command"]
2402
-
2403
- relative_script_file = "."
2404
- if "options" in task:
2405
- options = task["options"]
2406
- if "cwd" in options:
2407
- cwd: str = options["cwd"]
2408
- cwd = cwd.replace("${workspaceFolder}", ".")
2409
- relative_script_file = cwd
2410
- if len(relative_script_file) == 0:
2411
- relative_script_file = "."
2386
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
2387
+ if self.__sc.program_runner.will_be_executed_locally(): # works only locally, but much more performant than always running an external program
2388
+ self.__sc.assert_is_git_repository(repository_folder)
2389
+ workspace_file: str = self.__sc.find_file_by_extension(repository_folder, "code-workspace")
2390
+ task_file: str = repository_folder + "/Taskfile.yml"
2391
+ lines: list[str] = ["version: '3'", GeneralUtilities.empty_string, "tasks:", GeneralUtilities.empty_string]
2392
+ workspace_file_content: str = self.__sc.get_file_content(workspace_file)
2393
+ jsoncontent = json.loads(workspace_file_content)
2394
+ tasks = jsoncontent["tasks"]["tasks"]
2395
+ tasks.sort(key=lambda x: x["label"].split("/")[-1], reverse=False) # sort by the label of the task
2396
+ for task in tasks:
2397
+ if task["type"] == "shell":
2398
+
2399
+ description: str = task["label"]
2400
+ name: str = GeneralUtilities.to_pascal_case(description)
2401
+ command = task["command"]
2402
+ relative_script_file = task["command"]
2412
2403
 
2413
- command_with_args = command
2414
- if "args" in task:
2415
- args = task["args"]
2416
- if len(args) > 1:
2417
- command_with_args = f"{command_with_args} {' '.join(args)}"
2418
-
2419
- if "description" in task:
2420
- additional_description = task["description"]
2421
- description = f"{description} ({additional_description})"
2422
-
2423
- if append_cli_args_at_end:
2424
- command_with_args = f"{command_with_args} {{{{.CLI_ARGS}}}}"
2425
-
2426
- cwd_literal = cwd.replace("\\", "\\\\").replace('"', '\\"') # escape backslashes and double quotes for YAML
2427
- description_literal = description.replace("\\", "\\\\").replace('"', '\\"') # escape backslashes and double quotes for YAML
2428
-
2429
- lines.append(f" {name}:")
2430
- lines.append(f' desc: "{description_literal}"')
2431
- lines.append(' silent: true')
2432
- lines.append(f' dir: "{cwd_literal}"')
2433
- lines.append(" cmds:")
2434
- lines.append(f" - {command_with_args}")
2435
- lines.append(' aliases:')
2436
- lines.append(f' - {name.lower()}')
2437
- if "aliases" in task:
2438
- aliases = task["aliases"]
2439
- for alias in aliases:
2440
- lines.append(f' - {alias}')
2441
- lines.append(GeneralUtilities.empty_string)
2442
-
2443
- GeneralUtilities.write_lines_to_file(task_file, lines)
2404
+ relative_script_file = "."
2405
+ if "options" in task:
2406
+ options = task["options"]
2407
+ if "cwd" in options:
2408
+ cwd: str = options["cwd"]
2409
+ cwd = cwd.replace("${workspaceFolder}", ".")
2410
+ relative_script_file = cwd
2411
+ if len(relative_script_file) == 0:
2412
+ relative_script_file = "."
2413
+
2414
+ command_with_args = command
2415
+ if "args" in task:
2416
+ args = task["args"]
2417
+ if len(args) > 1:
2418
+ command_with_args = f"{command_with_args} {' '.join(args)}"
2419
+
2420
+ if "description" in task:
2421
+ additional_description = task["description"]
2422
+ description = f"{description} ({additional_description})"
2423
+
2424
+ if append_cli_args_at_end:
2425
+ command_with_args = f"{command_with_args} {{{{.CLI_ARGS}}}}"
2426
+
2427
+ cwd_literal = cwd.replace("\\", "\\\\").replace('"', '\\"') # escape backslashes and double quotes for YAML
2428
+ description_literal = description.replace("\\", "\\\\").replace('"', '\\"') # escape backslashes and double quotes for YAML
2429
+
2430
+ lines.append(f" {name}:")
2431
+ lines.append(f' desc: "{description_literal}"')
2432
+ lines.append(' silent: true')
2433
+ lines.append(f' dir: "{cwd_literal}"')
2434
+ lines.append(" cmds:")
2435
+ lines.append(f" - {command_with_args}")
2436
+ lines.append(' aliases:')
2437
+ lines.append(f' - {name.lower()}')
2438
+ if "aliases" in task:
2439
+ aliases = task["aliases"]
2440
+ for alias in aliases:
2441
+ lines.append(f' - {alias}')
2442
+ lines.append(GeneralUtilities.empty_string)
2443
+
2444
+ self.__sc.set_file_content(task_file, "\n".join(lines))
2445
+ else:
2446
+ self.__sc.run_program("scgeneratetasksfilefromworkspacefile", f"--repositoryfolder {repository_folder}")
2444
2447
 
2445
2448
  @GeneralUtilities.check_arguments
2446
2449
  def start_local_test_service(self, file: str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 3.5.148
3
+ Version: 3.5.149
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
@@ -22,21 +22,21 @@ Classifier: Topic :: Terminals
22
22
  Classifier: Topic :: Utilities
23
23
  Requires-Python: >=3.10
24
24
  Description-Content-Type: text/markdown
25
- Requires-Dist: build>=1.2.2.post1
26
- Requires-Dist: coverage>=7.9.1
27
- Requires-Dist: cyclonedx-bom>=6.1.1
25
+ Requires-Dist: build>=1.3.0
26
+ Requires-Dist: coverage>=7.10.2
27
+ Requires-Dist: cyclonedx-bom>=7.0.0
28
28
  Requires-Dist: defusedxml>=0.7.1
29
29
  Requires-Dist: keyboard>=0.13.5
30
30
  Requires-Dist: lcov-cobertura>=2.1.1
31
- Requires-Dist: lxml>=5.4.0
31
+ Requires-Dist: lxml>=6.0.0
32
32
  Requires-Dist: ntplib>=0.4.0
33
- Requires-Dist: Pillow>=11.2.1
33
+ Requires-Dist: Pillow>=11.3.0
34
34
  Requires-Dist: psutil>=7.0.0
35
35
  Requires-Dist: pycdlib>=1.14.0
36
36
  Requires-Dist: Pygments>=2.19.2
37
37
  Requires-Dist: pylint>=3.3.7
38
38
  Requires-Dist: pyOpenSSL>=25.1.0
39
- Requires-Dist: PyPDF>=5.7.0
39
+ Requires-Dist: PyPDF>=5.9.0
40
40
  Requires-Dist: pytest>=8.4.1
41
41
  Requires-Dist: PyYAML>=6.0.2
42
42
  Requires-Dist: qrcode>=8.2
@@ -1,5 +1,5 @@
1
1
  ScriptCollection/CertificateUpdater.py,sha256=OAxrG21k_o3W3niOOGNSZzUPJlvolOWc1lRB2dMhc3g,9212
2
- ScriptCollection/Executables.py,sha256=d9QkQuaS0nxTwNUGxtqKUk9dJqT5gS670LNuCz2YMw0,35349
2
+ ScriptCollection/Executables.py,sha256=eX94RLNBarpWoZKeDo02gcP_qzmJDZcIx8XBZFVCFNc,36396
3
3
  ScriptCollection/GeneralUtilities.py,sha256=PKdzq382RYVSWeSG_6z6FiHu-SiTOi2BavJKvP-0slU,47308
4
4
  ScriptCollection/ImageUpdater.py,sha256=3B5pgAMnyne3ZogWz-suqglZGIB9FAKyWn31P9E1ST0,24491
5
5
  ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
@@ -7,11 +7,11 @@ ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4b
7
7
  ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
8
8
  ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
9
9
  ScriptCollection/SCLog.py,sha256=GJ44S6VaBVwX5Dd6MIrdZn6I0dpaaYKVq9w-N0nMXlo,4496
10
- ScriptCollection/ScriptCollectionCore.py,sha256=ue-SRkt8EVrFEXTqSJ-g0V-EtaxbN67jbI1J3T3Lk_g,136482
11
- ScriptCollection/TasksForCommonProjectStructure.py,sha256=aVwQq2kQwZmL-NAhOVo_G4ikYHsI92SGvhkmmGJlSw8,240711
10
+ ScriptCollection/ScriptCollectionCore.py,sha256=2GF7AUB6QN2o3N3-KPhdHGzxwpZryfWQIPRGLUMRmRo,138093
11
+ ScriptCollection/TasksForCommonProjectStructure.py,sha256=GoIVDPIGua2ZJIGM4zeJL1nNLwh7X1W8BI-2z-ESgb0,241302
12
12
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- scriptcollection-3.5.148.dist-info/METADATA,sha256=5LUruhTUIaiA13P-RyZTSV_OSgRma7YCEpMuyO4KKG4,7694
14
- scriptcollection-3.5.148.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- scriptcollection-3.5.148.dist-info/entry_points.txt,sha256=AvmVO9iyWImExpvzL3YYQ9AOEiUIN9guPRRG_W_VNWY,4116
16
- scriptcollection-3.5.148.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
- scriptcollection-3.5.148.dist-info/RECORD,,
13
+ scriptcollection-3.5.149.dist-info/METADATA,sha256=Xt22-tDxFlz_5bbY-hDalMAXE7ndoPYu7QeEGLC822g,7689
14
+ scriptcollection-3.5.149.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ scriptcollection-3.5.149.dist-info/entry_points.txt,sha256=UyXXDpgVK6U0rkdbe2g-d3a7JFhLFWTUFSYWhcJE7IA,4214
16
+ scriptcollection-3.5.149.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
17
+ scriptcollection-3.5.149.dist-info/RECORD,,
@@ -28,6 +28,7 @@ scgeneratecertificate = ScriptCollection.Executables:GenerateCertificate
28
28
  scgeneratecertificateauthority = ScriptCollection.Executables:GenerateCertificateAuthority
29
29
  scgeneratecertificatesignrequest = ScriptCollection.Executables:GenerateCertificateSignRequest
30
30
  scgeneratesnkfiles = ScriptCollection.Executables:GenerateSnkFiles
31
+ scgeneratetasksfilefromworkspacefile = ScriptCollection.Executables:GenerateTaskfileFromWorkspacefile
31
32
  scgeneratethumbnail = ScriptCollection.Executables:GenerateThumbnail
32
33
  schealthcheck = ScriptCollection.Executables:Healthcheck
33
34
  sckeyboarddiagnosis = ScriptCollection.Executables:KeyboardDiagnosis
@@ -50,7 +51,7 @@ scremovefolder = ScriptCollection.Executables:RemoveFolder
50
51
  screname = ScriptCollection.Executables:Rename
51
52
  screplacesubstringsinfilenames = ScriptCollection.Executables:ReplaceSubstringsInFilenames
52
53
  scsearchinfiles = ScriptCollection.Executables:SearchInFiles
53
- scsetcontentoffile = ScriptCollection.Executables:SetContentOfFile
54
+ scsetfilecontent = ScriptCollection.Executables:SetFileContent
54
55
  scshow2faasqrcode = ScriptCollection.Executables:Show2FAAsQRCode
55
56
  scshowmissingfiles = ScriptCollection.Executables:ShowMissingFiles
56
57
  scsigncertificate = ScriptCollection.Executables:SignCertificate