ScriptCollection 3.5.60__py3-none-any.whl → 3.5.62__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.
@@ -416,9 +416,18 @@ def SetContentOfFile() -> int:
416
416
 
417
417
 
418
418
  def PrintFileContent() -> int:
419
- GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
420
- # TODO implement function
421
- return 1
419
+ parser = argparse.ArgumentParser(description="This function prints the size of a file")
420
+ parser.add_argument('-p', '--path', required=True)
421
+ parser.add_argument('-e', '--encoding', required=False, default="utf-8")
422
+ args = parser.parse_args()
423
+ file = args.path
424
+ encoding = args.encoding
425
+ if os.path.isfile(file):
426
+ GeneralUtilities.write_message_to_stdout(GeneralUtilities.read_text_from_file(file, encoding))
427
+ return 0
428
+ else:
429
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
430
+ return 1
422
431
 
423
432
 
424
433
  def CreateFile() -> int:
@@ -458,9 +467,17 @@ def RegexReplaceInFile() -> int:
458
467
 
459
468
 
460
469
  def PrintFileSize() -> int:
461
- GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
462
- # TODO implement function
463
- return 1
470
+ parser = argparse.ArgumentParser(description="This function prints the size of a file")
471
+ parser.add_argument('-p', '--path', required=True)
472
+ args = parser.parse_args()
473
+ file = args.path
474
+ if os.path.isfile(file):
475
+ size = os.path.getsize(file)
476
+ GeneralUtilities.write_message_to_stdout(str(size))
477
+ return 0
478
+ else:
479
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
480
+ return 1
464
481
 
465
482
 
466
483
  def FileContainsContent() -> int:
@@ -471,15 +488,35 @@ def FileContainsContent() -> int:
471
488
 
472
489
 
473
490
  def RemoveFile() -> int:
474
- GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
475
- # TODO implement function
476
- return 1
491
+ parser = argparse.ArgumentParser(description="This function removes a file.")
492
+ parser.add_argument('-p', '--path', required=True)
493
+ parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
494
+ args = parser.parse_args()
495
+ file = args.path
496
+ errorwhennotexists = args.errorwhennotexists
497
+ if os.path.isfile(file):
498
+ GeneralUtilities.ensure_file_does_not_exist(file)
499
+ else:
500
+ if errorwhennotexists:
501
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
502
+ return 1
503
+ return 0
477
504
 
478
505
 
479
506
  def RemoveFolder() -> int:
480
- GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
481
- # TODO implement function
482
- return 1
507
+ parser = argparse.ArgumentParser(description="This function removes a folder.")
508
+ parser.add_argument('-p', '--path', required=True)
509
+ parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
510
+ args = parser.parse_args()
511
+ folder = args.path
512
+ errorwhennotexists = args.errorwhennotexists
513
+ if os.path.isdir(folder):
514
+ GeneralUtilities.ensure_directory_does_not_exist(folder)
515
+ else:
516
+ if errorwhennotexists:
517
+ GeneralUtilities.write_exception_to_stderr(f"Folder '{folder}' does not exist.")
518
+ return 1
519
+ return 0
483
520
 
484
521
 
485
522
  def Rename() -> int:
@@ -489,3 +526,52 @@ def Rename() -> int:
489
526
  args = parser.parse_args()
490
527
  os.rename(args.source, args.target)
491
528
  return 0
529
+
530
+
531
+ def PrintOSName() -> int:
532
+ GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
533
+ if GeneralUtilities.current_system_is_windows():
534
+ GeneralUtilities.write_message_to_stdout("Windows")
535
+ elif GeneralUtilities.current_system_is_linux():
536
+ GeneralUtilities.write_message_to_stdout("Linux")
537
+ # TODO also consider Mac, Unix, etc.
538
+ else:
539
+ GeneralUtilities.write_message_to_stderr("Unknown OS.")
540
+ return 1
541
+ return 0
542
+
543
+
544
+ def PrintCurrecntWorkingDirectory() -> int:
545
+ GeneralUtilities.write_message_to_stdout(os.getcwd())
546
+ return 0
547
+
548
+
549
+ def ListFolderContent() -> int:
550
+ 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
+ return 1
557
+
558
+
559
+ def ForEach() -> int:
560
+ GeneralUtilities.write_exception_to_stderr("This function is not implemented yet.")
561
+ # TODO implement function
562
+ return 1
563
+
564
+
565
+ def NpmI() -> int:
566
+ parser = argparse.ArgumentParser(description="Does \"npm clean install\".")
567
+ parser.add_argument('-d', '--directory', required=False, default=".")
568
+ parser.add_argument('-f', '--force', action='store_true', required=False, default=False)
569
+ parser.add_argument('-v', '--verbose', action='store_true', required=False, default=False)
570
+ args = parser.parse_args()
571
+ if os.path.isabs(args.directory):
572
+ folder = args.directory
573
+ else:
574
+ folder = GeneralUtilities.resolve_relative_path(args.directory, os.getcwd())
575
+ t = TasksForCommonProjectStructure()
576
+ t.do_npm_install(folder, args.force, 3 if args.verbose else 0)
577
+ return 0
@@ -937,3 +937,16 @@ class GeneralUtilities:
937
937
  GeneralUtilities.assert_condition(not (amount_of_attempts < amount_of_fails))
938
938
  if amount_of_fails == amount_of_attempts:
939
939
  raise
940
+
941
+ @staticmethod
942
+ @check_arguments
943
+ def int_to_string(number: int, leading_zeroplaces: int, trailing_zeroplaces: int) -> str:
944
+ return GeneralUtilities.float_to_string(float(number), leading_zeroplaces, trailing_zeroplaces)
945
+
946
+ @staticmethod
947
+ @check_arguments
948
+ def float_to_string(number: float, leading_zeroplaces: int, trailing_zeroplaces: int) -> str:
949
+ plain_str = str(number)
950
+ GeneralUtilities.assert_condition("." in plain_str)
951
+ splitted: list[str] = plain_str.split(".")
952
+ return splitted[0].zfill(leading_zeroplaces)+"."+splitted[1].ljust(trailing_zeroplaces, '0')
@@ -31,7 +31,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
31
31
  from .ProgramRunnerPopen import ProgramRunnerPopen
32
32
  from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument
33
33
 
34
- version = "3.5.60"
34
+ version = "3.5.62"
35
35
  __version__ = version
36
36
 
37
37
 
@@ -1291,7 +1291,7 @@ class ScriptCollectionCore:
1291
1291
  return False
1292
1292
 
1293
1293
  @staticmethod
1294
- def __read_popen_pipes(p: Popen):
1294
+ def __read_popen_pipes(p: Popen) -> tuple[list[str], list[str]]:
1295
1295
  p_id = p.pid
1296
1296
  with ThreadPoolExecutor(2) as pool:
1297
1297
  q_stdout = Queue()
@@ -1301,28 +1301,33 @@ class ScriptCollectionCore:
1301
1301
  pool.submit(ScriptCollectionCore.__enqueue_output, p.stderr, q_stderr)
1302
1302
  reading_stdout_last_time_resulted_in_exception: bool = False
1303
1303
  reading_stderr_last_time_resulted_in_exception: bool = False
1304
+
1305
+ stdout_result: list[str] = []
1306
+ stderr_result: list[str] = []
1307
+
1304
1308
  while (ScriptCollectionCore.__continue_process_reading(p_id, p, q_stdout, q_stderr, reading_stdout_last_time_resulted_in_exception, reading_stderr_last_time_resulted_in_exception)):
1305
- out_line = None
1306
- err_line = None
1309
+
1307
1310
  try:
1308
- out_line = q_stdout.get_nowait() # TODO read all avaliable lines
1309
- reading_stdout_last_time_resulted_in_exception = False
1311
+ while not q_stdout.empty():
1312
+ stdout_result.append(q_stdout.get_nowait())
1313
+ reading_stdout_last_time_resulted_in_exception = False
1310
1314
  except Empty:
1311
1315
  reading_stdout_last_time_resulted_in_exception = True
1312
1316
 
1313
1317
  try:
1314
- err_line = q_stderr.get_nowait() # TODO read all avaliable lines
1315
- reading_stderr_last_time_resulted_in_exception = False
1318
+ while not q_stderr.empty():
1319
+ stderr_result.append(q_stderr.get_nowait())
1320
+ reading_stderr_last_time_resulted_in_exception = False
1316
1321
  except Empty:
1317
1322
  reading_stderr_last_time_resulted_in_exception = True
1318
1323
 
1319
1324
  time.sleep(0.01) # this is required to not finish too early
1320
1325
 
1321
- yield (out_line, err_line)
1326
+ return (stdout_result, stderr_result)
1322
1327
 
1323
- # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
1324
1328
  @GeneralUtilities.check_arguments
1325
1329
  def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, verbosity: int = 1, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
1330
+ # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
1326
1331
  # verbosity 1: No output will be logged.
1327
1332
  # verbosity 2: If the exitcode of the executed program is not 0 then the StdErr will be logged. This is supposed to be the default verbosity-level.
1328
1333
  # verbosity 3: Logs and prints StdOut and StdErr of the executed program in realtime.
@@ -1363,8 +1368,10 @@ class ScriptCollectionCore:
1363
1368
  if log_file is not None:
1364
1369
  GeneralUtilities.ensure_file_exists(log_file)
1365
1370
  pid = process.pid
1366
- for out_line_plain, err_line_plain in ScriptCollectionCore.__read_popen_pipes(process): # see https://stackoverflow.com/a/57084403/3905529
1367
1371
 
1372
+ outputs: tuple[list[str], list[str]] = ScriptCollectionCore.__read_popen_pipes(process)
1373
+
1374
+ for out_line_plain in outputs[0]:
1368
1375
  if out_line_plain is not None:
1369
1376
  out_line: str = None
1370
1377
  if isinstance(out_line_plain, str):
@@ -1385,6 +1392,7 @@ class ScriptCollectionCore:
1385
1392
  if log_file is not None:
1386
1393
  GeneralUtilities.append_line_to_file(log_file, out_line)
1387
1394
 
1395
+ for err_line_plain in outputs[1]:
1388
1396
  if err_line_plain is not None:
1389
1397
  err_line: str = None
1390
1398
  if isinstance(err_line_plain, str):
@@ -1811,11 +1811,16 @@ class TasksForCommonProjectStructure:
1811
1811
  argument1 = f"{argument1} --force"
1812
1812
  self.run_with_epew("npm", argument1, package_json_folder, verbosity=verbosity)
1813
1813
 
1814
- argument2 = "clean-install"
1814
+ argument2 = "install --package-lock-only"
1815
1815
  if force:
1816
1816
  argument2 = f"{argument2} --force"
1817
1817
  self.run_with_epew("npm", argument2, package_json_folder, verbosity=verbosity)
1818
1818
 
1819
+ argument3 = "clean-install"
1820
+ if force:
1821
+ argument3 = f"{argument3} --force"
1822
+ self.run_with_epew("npm", argument3, package_json_folder, verbosity=verbosity)
1823
+
1819
1824
  @GeneralUtilities.check_arguments
1820
1825
  def run_with_epew(self, program: str, argument: str = "", working_directory: str = None, verbosity: int = 1, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
1821
1826
  sc: ScriptCollectionCore = ScriptCollectionCore()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ScriptCollection
3
- Version: 3.5.60
3
+ Version: 3.5.62
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
@@ -28,14 +28,14 @@ Requires-Dist: cyclonedx-bom>=5.1.2
28
28
  Requires-Dist: defusedxml>=0.7.1
29
29
  Requires-Dist: keyboard>=0.13.5
30
30
  Requires-Dist: lcov-cobertura>=2.0.2
31
- Requires-Dist: lxml>=5.3.0
31
+ Requires-Dist: lxml>=5.3.1
32
32
  Requires-Dist: ntplib>=0.4.0
33
33
  Requires-Dist: Pillow>=11.1.0
34
34
  Requires-Dist: pycdlib>=1.14.0
35
35
  Requires-Dist: Pygments>=2.19.1
36
36
  Requires-Dist: pylint>=3.3.4
37
37
  Requires-Dist: pyOpenSSL>=25.0.0
38
- Requires-Dist: PyPDF>=5.2.0
38
+ Requires-Dist: PyPDF>=5.3.0
39
39
  Requires-Dist: pytest>=8.3.4
40
40
  Requires-Dist: PyYAML>=6.0.2
41
41
  Requires-Dist: qrcode>=8.0
@@ -0,0 +1,16 @@
1
+ ScriptCollection/Executables.py,sha256=kON_jatJe84iCJj60uUjA-Aj0ytERRe0FUDWbOWUe6s,28089
2
+ ScriptCollection/GeneralUtilities.py,sha256=Ah-quoBRLNO3iTCfZaAlN0fhOC42b-UEGYRMW_XxgO0,39438
3
+ ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
4
+ ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
5
+ ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
6
+ ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
7
+ ScriptCollection/RPStream.py,sha256=NRRHL3YSP3D9MuAV2jB_--0KUKCsvJGxeKnxgrRZ9kY,1545
8
+ ScriptCollection/ScriptCollectionCore.py,sha256=TN3Crb86-lU9YrHV9XFDUUNtX3KhT0Gq9WHyjt2XeKI,111409
9
+ ScriptCollection/TasksForCommonProjectStructure.py,sha256=B3-KSAZOR_UKSeLsdAxyZu2ylsRSjDvlj0272TXSEfA,213090
10
+ ScriptCollection/UpdateCertificates.py,sha256=Eynbgu7k9jLxApP2D_8Il77B6BFjJap6K7oTeEAZYbk,7790
11
+ ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ ScriptCollection-3.5.62.dist-info/METADATA,sha256=zPOBDBekOQ2rDLHvgehw8cB3gWbJUeSWIZbCdZehZJE,7664
13
+ ScriptCollection-3.5.62.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
+ ScriptCollection-3.5.62.dist-info/entry_points.txt,sha256=wspYVXWH8kon-wRQTAFEO11JoLJ0fEnOIG7tE7R-xtQ,3502
15
+ ScriptCollection-3.5.62.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
16
+ ScriptCollection-3.5.62.dist-info/RECORD,,
@@ -18,6 +18,7 @@ scfilecontainscontent = ScriptCollection.Executables:FileContainsContent
18
18
  scfileexists = ScriptCollection.Executables:FileExists
19
19
  scfilenameobfuscator = ScriptCollection.Executables:FilenameObfuscator
20
20
  scfolderexists = ScriptCollection.Executables:FolderExists
21
+ scforeach = ScriptCollection.Executables:ForEach
21
22
  scgeneratearc42referencetemplate = ScriptCollection.Executables:GenerateARC42ReferenceTemplate
22
23
  scgeneratecertificate = ScriptCollection.Executables:GenerateCertificate
23
24
  scgeneratecertificateauthority = ScriptCollection.Executables:GenerateCertificateAuthority
@@ -26,12 +27,16 @@ scgeneratesnkfiles = ScriptCollection.Executables:GenerateSnkFiles
26
27
  scgeneratethumbnail = ScriptCollection.Executables:GenerateThumbnail
27
28
  schealthcheck = ScriptCollection.Executables:Healthcheck
28
29
  sckeyboarddiagnosis = ScriptCollection.Executables:KeyboardDiagnosis
30
+ sclistfoldercontent = ScriptCollection.Executables:ListFolderContent
29
31
  scmergepdfs = ScriptCollection.Executables:MergePDFs
32
+ scnpmi = ScriptCollection.Executables:NpmI
30
33
  scobfuscatefilesfolder = ScriptCollection.Executables:ObfuscateFilesFolder
31
34
  scorganizelinesinfile = ScriptCollection.Executables:OrganizeLinesInFile
32
35
  scpdftoimage = ScriptCollection.Executables:PDFToImage
36
+ scprintcurrentworkingdirectory = ScriptCollection.Executables:PrintCurrecntWorkingDirectory
33
37
  scprintfilecontent = ScriptCollection.Executables:PrintFileContent
34
38
  scprintfilesize = ScriptCollection.Executables:PrintFileSize
39
+ scprintosname = ScriptCollection.Executables:PrintOSName
35
40
  scregexreplaceinfile = ScriptCollection.Executables:RegexReplaceInFile
36
41
  scremoveFolder = ScriptCollection.Executables:RemoveFolder
37
42
  scremovefile = ScriptCollection.Executables:RemoveFile
@@ -1,16 +0,0 @@
1
- ScriptCollection/Executables.py,sha256=j79qOgjHKgha2EW1uMfKf1Woa6rsChL0yqJgIA-YkYU,24586
2
- ScriptCollection/GeneralUtilities.py,sha256=nlSZSsQVHWxf0Yzz4PjgZm39rgvIltVof8gL2YPgR7s,38805
3
- ScriptCollection/ProcessesRunner.py,sha256=3mu4ZxzZleQo0Op6o9EYTCFiJfb6kx5ov2YfZfT89mU,1395
4
- ScriptCollection/ProgramRunnerBase.py,sha256=2kMIAqdc65UjBAddOZkzy_aFx9h5roZ5a4bQNM6RV6Y,2480
5
- ScriptCollection/ProgramRunnerEpew.py,sha256=4pjEd0r9Fcz3TTDv0MdTSd5KkigYXcWUVI1X43regfU,6477
6
- ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
7
- ScriptCollection/RPStream.py,sha256=NRRHL3YSP3D9MuAV2jB_--0KUKCsvJGxeKnxgrRZ9kY,1545
8
- ScriptCollection/ScriptCollectionCore.py,sha256=th3pd2sKt6kBJQ1-7WrjnYOVmbWPfDrYzRkVzmmu6C4,111227
9
- ScriptCollection/TasksForCommonProjectStructure.py,sha256=IOrvyAgnA2PmXbotfxdXhwIwdciFiXvtPm2URcpDSVc,212887
10
- ScriptCollection/UpdateCertificates.py,sha256=Eynbgu7k9jLxApP2D_8Il77B6BFjJap6K7oTeEAZYbk,7790
11
- ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- ScriptCollection-3.5.60.dist-info/METADATA,sha256=SwD2qxvbM1YxPLHJGuKrRLXgCDhJ3pcgJDcih0bPGTc,7664
13
- ScriptCollection-3.5.60.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
- ScriptCollection-3.5.60.dist-info/entry_points.txt,sha256=AQz2mMJ787Aw5Q_ItC6Q-Mo_DGYlM_OPEkovrgsrRF0,3192
15
- ScriptCollection-3.5.60.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
16
- ScriptCollection-3.5.60.dist-info/RECORD,,