ScriptCollection 3.5.67__py3-none-any.whl → 3.5.69__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.
@@ -3,6 +3,7 @@ import argparse
3
3
  import time
4
4
  import traceback
5
5
  import sys
6
+ import shutil
6
7
  import keyboard
7
8
  from .TasksForCommonProjectStructure import TasksForCommonProjectStructure
8
9
  from .ScriptCollectionCore import ScriptCollectionCore
@@ -528,13 +529,30 @@ def Rename() -> int:
528
529
  return 0
529
530
 
530
531
 
532
+ def Copy() -> int:
533
+ parser = argparse.ArgumentParser(description="This function copies a file or folder.")
534
+ parser.add_argument('-s', '--source', required=True)
535
+ parser.add_argument('-t', '--target', required=True)
536
+ args = parser.parse_args()
537
+ if os.path.isfile(args.target) or os.path.isdir(args.target):
538
+ raise ValueError(f"Can not copy to '{args.target}' because the target already exists.")
539
+ if os.path.isfile(args.source):
540
+ shutil.copyfile(args.source, args.target)
541
+ elif os.path.isdir(args.source):
542
+ GeneralUtilities.ensure_directory_exists(args.target)
543
+ GeneralUtilities.copy_content_of_folder(args.source,args.target)
544
+ else:
545
+ raise ValueError(f"'{args.source}' can not be copied because the path does not exist.")
546
+ return 0
547
+
548
+
531
549
  def PrintOSName() -> int:
532
550
  GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
533
551
  if GeneralUtilities.current_system_is_windows():
534
552
  GeneralUtilities.write_message_to_stdout("Windows")
535
553
  elif GeneralUtilities.current_system_is_linux():
536
554
  GeneralUtilities.write_message_to_stdout("Linux")
537
- # TODO also consider Mac, Unix, etc.
555
+ # TODO consider Mac, Unix, etc. too
538
556
  else:
539
557
  GeneralUtilities.write_message_to_stderr("Unknown OS.")
540
558
  return 1
@@ -548,19 +566,29 @@ def PrintCurrecntWorkingDirectory() -> int:
548
566
 
549
567
  def ListFolderContent() -> int:
550
568
  GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
551
- # TODO implement function
552
- # TODO add option to include/exclude full path
553
- # TODO add option to also list transitively list subfolder
554
- # TODO add option to print only folder
555
- # TODO add option to print only files
556
569
  parser = argparse.ArgumentParser(description="This function lists folder-content.")
557
570
  parser.add_argument('-p', '--path', required=True)
571
+ parser.add_argument('-f', '--excludefiles', action='store_true', required=False,default=False)
572
+ parser.add_argument('-d', '--excludedirectories', action='store_true', required=False,default=False)
573
+ parser.add_argument('-n', '--printonlynamewithoutpath', action='store_true', required=False,default=False)
574
+ # TODO add option to also list transitively list subfolder
575
+ # TODO add option to show only content which matches a filter by extension or regex or glob-pattern
558
576
  args=parser.parse_args()
559
577
  folder=args.path
560
578
  if not os.path.isabs(folder):
561
579
  folder=GeneralUtilities.resolve_relative_path(folder,os.getcwd())
562
- for file in GeneralUtilities.get_direct_files_of_folder(folder):
563
- GeneralUtilities.write_message_to_stdout(file)
580
+ content=[]
581
+ if not args.excludefiles:
582
+ content=content+GeneralUtilities.get_direct_files_of_folder(folder)
583
+ if not args.excludedirectories:
584
+ content=content+GeneralUtilities.get_direct_folders_of_folder(folder)
585
+ for contentitem in content:
586
+ content_to_print:str=None
587
+ if args.printonlynamewithoutpath:
588
+ content_to_print=os.path.basename(contentitem)
589
+ else:
590
+ content_to_print= contentitem
591
+ GeneralUtilities.write_message_to_stdout(content_to_print)
564
592
  return 0
565
593
 
566
594
 
@@ -32,7 +32,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
32
32
  from .ProgramRunnerPopen import ProgramRunnerPopen
33
33
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
34
34
 
35
- version = "3.5.67"
35
+ version = "3.5.69"
36
36
  __version__ = version
37
37
 
38
38
 
@@ -619,11 +619,34 @@ class ScriptCollectionCore:
619
619
  os.rename(renamed_item, original_name)
620
620
 
621
621
  @GeneralUtilities.check_arguments
622
- def list_files(self, path: str) -> list[str]:
622
+ def is_git_repository(self, folder: str) -> bool:
623
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
624
+ combined = f"{folder}/.git"
625
+ # TODO consider check for bare-repositories
626
+ return self.is_folder(combined) or self.is_file(combined)
627
+
628
+ @GeneralUtilities.check_arguments
629
+ def assert_is_git_repository(self, folder: str) -> str:
630
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
631
+ GeneralUtilities.assert_condition(self.is_git_repository(folder), f"'{folder}' is not a git-repository.")
632
+
633
+ @GeneralUtilities.check_arguments
634
+ def list_content(self, path: str,include_files:bool,include_folder:bool) -> list[str]:
635
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
623
636
  if self.program_runner.will_be_executed_locally():
624
- return GeneralUtilities.get_direct_files_of_folder(path)
637
+ result=[]
638
+ if include_files:
639
+ result=result + GeneralUtilities.get_direct_files_of_folder(path)
640
+ if include_folder:
641
+ result=result + GeneralUtilities.get_direct_folders_of_folder(path)
642
+ return result
625
643
  else:
626
- exit_code, stdout, stderr, _ = self.run_program_argsasarray("scfileexists", ["--path", path])
644
+ arguments=["--path", path]
645
+ if not include_files:
646
+ arguments=arguments+["--excludefiles"]
647
+ if not include_folder:
648
+ arguments=arguments+["--excludedirectories"]
649
+ exit_code, stdout, stderr, _ = self.run_program_argsasarray("sclistfoldercontent", arguments)
627
650
  if exit_code == 0:
628
651
  result:list[str]=[]
629
652
  for line in stdout.split("\n"):
@@ -635,6 +658,7 @@ class ScriptCollectionCore:
635
658
 
636
659
  @GeneralUtilities.check_arguments
637
660
  def is_file(self, path: str) -> bool:
661
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
638
662
  if self.program_runner.will_be_executed_locally():
639
663
  return os.path.isfile(path) # works only locally, but much more performant than always running an external program
640
664
  else:
@@ -649,6 +673,7 @@ class ScriptCollectionCore:
649
673
 
650
674
  @GeneralUtilities.check_arguments
651
675
  def is_folder(self, path: str) -> bool:
676
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
652
677
  if self.program_runner.will_be_executed_locally(): # works only locally, but much more performant than always running an external program
653
678
  return os.path.isdir(path)
654
679
  else:
@@ -662,14 +687,22 @@ class ScriptCollectionCore:
662
687
  raise ValueError(f"Fatal error occurrs while checking whether folder '{path}' exists. StdErr: '{stderr}'")
663
688
 
664
689
  @GeneralUtilities.check_arguments
665
- def is_git_repository(self, folder: str) -> bool:
666
- combined = f"{folder}/.git"
667
- # TODO consider check for bare-repositories
668
- return self.is_file(combined) or self.is_folder(combined)
669
-
670
- @GeneralUtilities.check_arguments
671
- def assert_is_git_repository(self, folder: str) -> str:
672
- GeneralUtilities.assert_condition(self.is_git_repository(folder), f"'{folder}' is not a git-repository.")
690
+ def remove(self, path: str) ->None:
691
+ """This function works platform-independent also for non-local-executions if the ScriptCollection commandline-commands are available as global command on the target-system."""
692
+ if self.program_runner.will_be_executed_locally(): # works only locally, but much more performant than always running an external program
693
+ if os.path.isdir(path):
694
+ GeneralUtilities.ensure_directory_does_not_exist(path)
695
+ if os.path.isfile(path):
696
+ GeneralUtilities.ensure_file_does_not_exist(path)
697
+ else:
698
+ if self.is_file(path):
699
+ exit_code, _, stderr, _ = self.run_program_argsasarray("scremovefile", ["--path", path], throw_exception_if_exitcode_is_not_zero=False) # works platform-indepent
700
+ if exit_code != 0:
701
+ raise ValueError(f"Fatal error occurrs while removing file '{path}'. StdErr: '{stderr}'")
702
+ if self.is_folder(path):
703
+ exit_code, _, stderr, _ = self.run_program_argsasarray("scremovefolder", ["--path", path], throw_exception_if_exitcode_is_not_zero=False) # works platform-indepent
704
+ if exit_code != 0:
705
+ raise ValueError(f"Fatal error occurrs while removing folder '{path}'. StdErr: '{stderr}'")
673
706
 
674
707
  @GeneralUtilities.check_arguments
675
708
  def __sort_fmd(self, line: str):
@@ -1302,7 +1302,9 @@ class TasksForCommonProjectStructure:
1302
1302
  # hint: arguments can be overwritten by commandline_arguments
1303
1303
  folder_of_this_file = os.path.dirname(create_release_file)
1304
1304
  verbosity = TasksForCommonProjectStructure.get_verbosity_from_commandline_arguments(commandline_arguments, verbosity)
1305
- self.__sc.run_program("python", f"CreateRelease.py --overwrite_verbosity {str(verbosity)}", folder_of_this_file, verbosity=verbosity, log_file=logfile, addLogOverhead=addLogOverhead)
1305
+ result=self.__sc.run_program("python", f"CreateRelease.py --overwrite_verbosity {str(verbosity)}", folder_of_this_file, verbosity=verbosity, log_file=logfile, addLogOverhead=addLogOverhead,print_live_output=True,throw_exception_if_exitcode_is_not_zero=False)
1306
+ if result[0]!=0:
1307
+ raise ValueError(f"CreateRelease.py resulted in exitcode {result[0]}.")
1306
1308
 
1307
1309
  @GeneralUtilities.check_arguments
1308
1310
  def __standardized_tasks_merge_to_stable_branch(self, information: MergeToStableBranchInformationForProjectInCommonProjectFormat) -> str:
@@ -2438,7 +2440,7 @@ class TasksForCommonProjectStructure:
2438
2440
  self.__sc.assert_is_git_repository(repository_folder)
2439
2441
  repository_folder = GeneralUtilities.resolve_relative_path_from_current_working_directory(repository_folder)
2440
2442
  codeunits = self.get_codeunits(repository_folder, False)
2441
- self.build_specific_codeunits(repository_folder, codeunits, verbosity, target_environmenttype, additional_arguments_file, is_pre_merge, export_target_directory, False, commandline_arguments, do_git_clean_when_no_changes)
2443
+ self.build_specific_codeunits(repository_folder, codeunits, verbosity, target_environmenttype, additional_arguments_file, is_pre_merge, export_target_directory, False, commandline_arguments, do_git_clean_when_no_changes,note)
2442
2444
 
2443
2445
  @GeneralUtilities.check_arguments
2444
2446
  def build_specific_codeunits(self, repository_folder: str, codeunits: list[str], verbosity: int = 1, target_environmenttype: str = "QualityCheck", additional_arguments_file: str = None, is_pre_merge: bool = False, export_target_directory: str = None, assume_dependent_codeunits_are_already_built: bool = True, commandline_arguments: list[str] = [], do_git_clean_when_no_changes: bool = False, note: str = None) -> None:
@@ -2463,7 +2465,9 @@ class TasksForCommonProjectStructure:
2463
2465
  prepare_build_codeunits_scripts = os.path.join(project_resources_folder, PrepareBuildCodeunits_script_name)
2464
2466
  if os.path.isfile(prepare_build_codeunits_scripts):
2465
2467
  GeneralUtilities.write_message_to_stdout(f'Run "{PrepareBuildCodeunits_script_name}"')
2466
- self.__sc.run_program("python", f"{PrepareBuildCodeunits_script_name}", project_resources_folder, print_live_output=1 < verbosity)
2468
+ result=self.__sc.run_program("python", f"{PrepareBuildCodeunits_script_name}", project_resources_folder,throw_exception_if_exitcode_is_not_zero=False, print_live_output=True)
2469
+ if result[0]!=0:
2470
+ raise ValueError(f"PrepareBuildCodeunits.py resulted in exitcode {result[0]}.")
2467
2471
 
2468
2472
  for subfolder in subfolders:
2469
2473
  codeunit_name: str = os.path.basename(subfolder)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ScriptCollection
3
- Version: 3.5.67
3
+ Version: 3.5.69
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,16 +1,16 @@
1
- ScriptCollection/Executables.py,sha256=jGJIVEjRuOEpcC6ZvCny22DgHZPtr4pmKZj6b-Zn-fA,28514
1
+ ScriptCollection/Executables.py,sha256=dyToDh4vd0k0Ox9TE4E_4-jY46XU6A6rguOL5R6Moj4,29977
2
2
  ScriptCollection/GeneralUtilities.py,sha256=WSBawT958x_0H-hnPg3S3DGzP3KOQTADtZtP145I-M4,39473
3
3
  ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
4
4
  ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
5
5
  ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
6
6
  ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
7
7
  ScriptCollection/RPStream.py,sha256=NRRHL3YSP3D9MuAV2jB_--0KUKCsvJGxeKnxgrRZ9kY,1545
8
- ScriptCollection/ScriptCollectionCore.py,sha256=Gjr-4UES3iYDUuYoBTN8XIaLbuzTq4FyMD_6cuOseAY,113595
9
- ScriptCollection/TasksForCommonProjectStructure.py,sha256=F6e045gUvSxpOcHk61OVnlod_Zn9JSNXrv6I2SzWoVc,214997
8
+ ScriptCollection/ScriptCollectionCore.py,sha256=qrFos1Od9o4paGQwKAKbeFZd72CwMbctYwVr2PI5SqU,116344
9
+ ScriptCollection/TasksForCommonProjectStructure.py,sha256=MtbaO3Sgew-cSSapf5XJ_7-ui2w3QGYwpvacX-l2K_w,215356
10
10
  ScriptCollection/UpdateCertificates.py,sha256=Eynbgu7k9jLxApP2D_8Il77B6BFjJap6K7oTeEAZYbk,7790
11
11
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- ScriptCollection-3.5.67.dist-info/METADATA,sha256=jSXXQC_Q1zoKYsvPm38722Tok5dvc3a7dtulFS9j9Uk,7664
13
- ScriptCollection-3.5.67.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
- ScriptCollection-3.5.67.dist-info/entry_points.txt,sha256=wspYVXWH8kon-wRQTAFEO11JoLJ0fEnOIG7tE7R-xtQ,3502
15
- ScriptCollection-3.5.67.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
16
- ScriptCollection-3.5.67.dist-info/RECORD,,
12
+ ScriptCollection-3.5.69.dist-info/METADATA,sha256=K88GUkBl1Hf3WB0WQ67vdgCEzR4Pn6z3wkkPd5uH0eA,7664
13
+ ScriptCollection-3.5.69.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
+ ScriptCollection-3.5.69.dist-info/entry_points.txt,sha256=psYFu5te0W8zF5k444Qi21IZN4UwwGbw-XR22nvKTYE,3545
15
+ ScriptCollection-3.5.69.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
16
+ ScriptCollection-3.5.69.dist-info/RECORD,,
@@ -6,6 +6,7 @@ scbuildcodeunitsc = ScriptCollection.Executables:BuildCodeUnitsC
6
6
  sccalculatebitcoinblockhash = ScriptCollection.Executables:CalculateBitcoinBlockHash
7
7
  scchangefileextension = ScriptCollection.Executables:ChangeFileExtensions
8
8
  scchangehashofprogram = ScriptCollection.Executables:ChangeHashOfProgram
9
+ sccopy = ScriptCollection.Executables:Copy
9
10
  sccreatechangelogentry = ScriptCollection.Executables:CreateChangelogEntry
10
11
  sccreateemptyfilewithspecificsize = ScriptCollection.Executables:CreateEmptyFileWithSpecificSize
11
12
  sccreatefile = ScriptCollection.Executables:CreateFile