scriptcollection 4.2.81__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.
Files changed (62) hide show
  1. ScriptCollection/AnionBuildPlatform.py +199 -0
  2. ScriptCollection/CertificateUpdater.py +149 -0
  3. ScriptCollection/Executables.py +921 -0
  4. ScriptCollection/GeneralUtilities.py +1589 -0
  5. ScriptCollection/HTTPMaintenanceOverheadHelper.py +36 -0
  6. ScriptCollection/OCIImages/AbstractImageHandler.py +38 -0
  7. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebian.py +20 -0
  8. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebianSlim.py +20 -0
  9. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGeneric.py +20 -0
  10. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGenericV.py +20 -0
  11. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabCE.py +20 -0
  12. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabEE.py +20 -0
  13. ScriptCollection/OCIImages/ConcreteImageHandlers/__init__.py +0 -0
  14. ScriptCollection/OCIImages/OCIImageManager.py +190 -0
  15. ScriptCollection/OCIImages/__init__.py +0 -0
  16. ScriptCollection/ProcessesRunner.py +43 -0
  17. ScriptCollection/ProgramRunnerBase.py +47 -0
  18. ScriptCollection/ProgramRunnerMock.py +2 -0
  19. ScriptCollection/ProgramRunnerPopen.py +57 -0
  20. ScriptCollection/ProgramRunnerSudo.py +108 -0
  21. ScriptCollection/Resources/CultureChooser/CultureChooser.js +29 -0
  22. ScriptCollection/Resources/CultureChooser/index.html +15 -0
  23. ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html +15 -0
  24. ScriptCollection/SCLog.py +115 -0
  25. ScriptCollection/ScriptCollectionCore.py +3485 -0
  26. ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +192 -0
  27. ScriptCollection/TFCPS/Docker/__init__.py +0 -0
  28. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py +8 -0
  29. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py +6 -0
  30. ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py +7 -0
  31. ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +547 -0
  32. ScriptCollection/TFCPS/DotNet/__init__.py +0 -0
  33. ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +137 -0
  34. ScriptCollection/TFCPS/Flutter/__init__.py +0 -0
  35. ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py +72 -0
  36. ScriptCollection/TFCPS/Go/__init__.py +0 -0
  37. ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py +42 -0
  38. ScriptCollection/TFCPS/Maven/__init__.py +0 -0
  39. ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +232 -0
  40. ScriptCollection/TFCPS/NodeJS/__init__.py +0 -0
  41. ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py +239 -0
  42. ScriptCollection/TFCPS/Python/__init__.py +0 -0
  43. ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py +42 -0
  44. ScriptCollection/TFCPS/Rust/__init__.py +0 -0
  45. ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +433 -0
  46. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py +135 -0
  47. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +301 -0
  48. ScriptCollection/TFCPS/TFCPS_CreateRelease.py +98 -0
  49. ScriptCollection/TFCPS/TFCPS_Generic.py +44 -0
  50. ScriptCollection/TFCPS/TFCPS_MergeToMain.py +128 -0
  51. ScriptCollection/TFCPS/TFCPS_MergeToStable.py +356 -0
  52. ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py +48 -0
  53. ScriptCollection/TFCPS/TFCPS_Tools_General.py +1565 -0
  54. ScriptCollection/TFCPS/__init__.py +0 -0
  55. ScriptCollection/__init__.py +0 -0
  56. ScriptCollection/__pycache__/GeneralUtilities.cpython-311.pyc +0 -0
  57. ScriptCollection/__pycache__/__init__.cpython-311.pyc +0 -0
  58. scriptcollection-4.2.81.dist-info/METADATA +169 -0
  59. scriptcollection-4.2.81.dist-info/RECORD +62 -0
  60. scriptcollection-4.2.81.dist-info/WHEEL +5 -0
  61. scriptcollection-4.2.81.dist-info/entry_points.txt +67 -0
  62. scriptcollection-4.2.81.dist-info/top_level.txt +1 -0
@@ -0,0 +1,921 @@
1
+ import base64
2
+ import os
3
+ import argparse
4
+ import time
5
+ import traceback
6
+ import shutil
7
+ import keyboard
8
+ from .ScriptCollectionCore import ScriptCollectionCore
9
+ from .GeneralUtilities import GeneralUtilities
10
+ from .SCLog import LogLevel, SCLog
11
+ from .TFCPS.TFCPS_CodeUnit_BuildCodeUnits import TFCPS_CodeUnit_BuildCodeUnits
12
+ from .TFCPS.TFCPS_Tools_General import TFCPS_Tools_General
13
+ from .OCIImages.OCIImageManager import OCIImageManager
14
+
15
+ def FilenameObfuscator() -> int:
16
+ parser = argparse.ArgumentParser(description=''''Obfuscates the names of all files in the given folder.
17
+ Caution: This script can cause harm if you pass a wrong inputfolder-argument.''')
18
+
19
+ parser.add_argument('--printtableheadline', type=GeneralUtilities.string_to_boolean, const=True, default=True, nargs='?', help='Prints column-titles in the name-mapping-csv-file')
20
+ parser.add_argument('--namemappingfile', default="NameMapping.csv", help='Specifies the file where the name-mapping will be written to')
21
+ parser.add_argument('--extensions', default="exe,py,sh",
22
+ help='Comma-separated list of file-extensions of files where this tool should be applied. Use "*" to obfuscate all')
23
+ parser.add_argument('--inputfolder', help='Specifies the foldere where the files are stored whose names should be obfuscated', required=True)
24
+
25
+ args = parser.parse_args()
26
+ ScriptCollectionCore().SCFilenameObfuscator(args.inputfolder, args.printtableheadline, args.namemappingfile, args.extensions)
27
+ return 0
28
+
29
+
30
+ def CreateISOFileWithObfuscatedFiles() -> int:
31
+ parser = argparse.ArgumentParser(description='''Creates an iso file with the files in the given folder and changes their names and hash-values.
32
+ This script does not process subfolders transitively.''')
33
+
34
+ parser.add_argument('--inputfolder', help='Specifies the foldere where the files are stored which should be added to the iso-file', required=True)
35
+ parser.add_argument('--outputfile', default="files.iso", help='Specifies the output-iso-file and its location')
36
+ parser.add_argument('--printtableheadline', default=False, action='store_true', help='Prints column-titles in the name-mapping-csv-file')
37
+ parser.add_argument('--createnoisofile', default=False, action='store_true', help="Create no iso file")
38
+ parser.add_argument('--extensions', default="exe,py,sh", help='Comma-separated list of file-extensions of files where this tool should be applied. Use "*" to obfuscate all')
39
+ args = parser.parse_args()
40
+
41
+ ScriptCollectionCore().SCCreateISOFileWithObfuscatedFiles(args.inputfolder, args.outputfile, args.printtableheadline, not args.createnoisofile, args.extensions)
42
+ return 0
43
+
44
+
45
+ def ChangeHashOfProgram() -> int:
46
+ parser = argparse.ArgumentParser(description='Changes the hash-value of arbitrary files by appending data at the end of the file.')
47
+ parser.add_argument('--inputfile', help='Specifies the script/executable-file whose hash-value should be changed', required=True)
48
+ args = parser.parse_args()
49
+ ScriptCollectionCore().SCChangeHashOfProgram(args.inputfile)
50
+ return 0
51
+
52
+
53
+ def CalculateBitcoinBlockHash() -> int:
54
+ parser = argparse.ArgumentParser(description='Calculates the Hash of the header of a bitcoin-block.')
55
+ parser.add_argument('--version', help='Block-version', required=True)
56
+ parser.add_argument('--previousblockhash', help='Hash-value of the previous block', required=True)
57
+ parser.add_argument('--transactionsmerkleroot', help='Hashvalue of the merkle-root of the transactions which are contained in the block', required=True)
58
+ parser.add_argument('--timestamp', help='Timestamp of the block', required=True)
59
+ parser.add_argument('--target', help='difficulty', required=True)
60
+ parser.add_argument('--nonce', help='Arbitrary 32-bit-integer-value', required=True)
61
+ args = parser.parse_args()
62
+
63
+ args = parser.parse_args()
64
+ GeneralUtilities.write_message_to_stdout(ScriptCollectionCore().SCCalculateBitcoinBlockHash(args.version, args.previousblockhash, args.transactionsmerkleroot, args.timestamp, args.target, args.nonce))
65
+ return 0
66
+
67
+
68
+ def Show2FAAsQRCode():
69
+
70
+ parser = argparse.ArgumentParser(description="""Always when you use 2-factor-authentication you have the problem:
71
+ Where to backup the secret-key so that it is easy to re-setup them when you have a new phone?
72
+ Using this script is a solution. Always when you setup a 2fa you copy and store the secret in a csv-file.
73
+ It should be obviously that this csv-file must be stored encrypted!
74
+ Now if you want to move your 2fa-codes to a new phone you simply call "SCShow2FAAsQRCode 2FA.csv"
75
+ Then the qr-codes will be displayed in the console and you can scan them on your new phone.
76
+ This script does not saving the any data anywhere.
77
+
78
+ The structure of the csv-file can be viewd here:
79
+ Displayname;Website;Email-address;Secret;Period;
80
+ Amazon;Amazon.de;myemailaddress@example.com;QWERTY;30;
81
+ Google;Google.de;myemailaddress@example.com;ASDFGH;30;
82
+
83
+ Hints:
84
+ -Since the first line of the csv-file contains headlines the first line will always be ignored
85
+ -30 is the commonly used value for the period""")
86
+ parser.add_argument('csvfile', help='File where the 2fa-codes are stored')
87
+ args = parser.parse_args()
88
+ ScriptCollectionCore().SCShow2FAAsQRCode(args.csvfile)
89
+ return 0
90
+
91
+
92
+ def SearchInFiles() -> int:
93
+ parser = argparse.ArgumentParser(description='''Searchs for the given searchstrings in the content of all files in the given folder.
94
+ This program prints all files where the given searchstring was found to the console''')
95
+
96
+ parser.add_argument('folder', help='Folder for search')
97
+ parser.add_argument('searchstring', help='string to look for')
98
+
99
+ args = parser.parse_args()
100
+ ScriptCollectionCore().SCSearchInFiles(args.folder, args.searchstring)
101
+ return 0
102
+
103
+
104
+ def ReplaceSubstringsInFilenames() -> int:
105
+ parser = argparse.ArgumentParser(description='Replaces certain substrings in filenames. This program requires "pip install Send2Trash" in certain cases.')
106
+
107
+ parser.add_argument('folder', help='Folder where the files are stored which should be renamed')
108
+ parser.add_argument('substringInFilename', help='String to be replaced')
109
+ parser.add_argument('newSubstringInFilename', help='new string value for filename')
110
+ parser.add_argument('conflictResolveMode', help='''Set a method how to handle cases where a file with the new filename already exits and
111
+ the files have not the same content. Possible values are: ignore, preservenewest, merge''')
112
+
113
+ args = parser.parse_args()
114
+
115
+ ScriptCollectionCore().SCReplaceSubstringsInFilenames(args.folder, args.substringInFilename, args.newSubstringInFilename, args.conflictResolveMode)
116
+ return 0
117
+
118
+
119
+ def GenerateSnkFiles() -> int:
120
+ parser = argparse.ArgumentParser(description='Generate multiple .snk-files')
121
+ parser.add_argument('outputfolder', help='Folder where the files are stored which should be hashed')
122
+ parser.add_argument('--keysize', default='4096')
123
+ parser.add_argument('--amountofkeys', default='10')
124
+
125
+ args = parser.parse_args()
126
+ ScriptCollectionCore().SCGenerateSnkFiles(args.outputfolder, args.keysize, args.amountofkeys)
127
+ return 0
128
+
129
+
130
+ def OrganizeLinesInFile() -> int:
131
+ parser = argparse.ArgumentParser(description='Processes the lines of a file with the given commands')
132
+
133
+ parser.add_argument('file', help='File which should be transformed')
134
+ parser.add_argument('--encoding', default="utf-8", help='Encoding for the file which should be transformed')
135
+ parser.add_argument("--sort", help="Sort lines", action='store_true')
136
+ parser.add_argument("--remove_duplicated_lines", help="Remove duplicate lines", action='store_true')
137
+ parser.add_argument("--ignore_first_line", help="Ignores the first line in the file", action='store_true')
138
+ parser.add_argument("--remove_empty_lines", help="Removes lines which are empty or contains only whitespaces", action='store_true')
139
+ parser.add_argument('--ignored_start_character', default="", help='Characters which should not be considered at the begin of a line')
140
+
141
+ args = parser.parse_args()
142
+ ScriptCollectionCore().sc_organize_lines_in_file(args.file, args.encoding, args.sort, args.remove_duplicated_lines, args.ignore_first_line, args.remove_empty_lines, list(args.ignored_start_character))
143
+
144
+
145
+ def CreateHashOfAllFiles() -> int:
146
+ parser = argparse.ArgumentParser(description='Calculates the SHA-256-value of all files in the given folder and stores the hash-value in a file next to the hashed file.')
147
+ parser.add_argument('folder', help='Folder where the files are stored which should be hashed')
148
+ args = parser.parse_args()
149
+ ScriptCollectionCore().SCCreateHashOfAllFiles(args.folder)
150
+ return 0
151
+
152
+
153
+ def CreateSimpleMergeWithoutRelease() -> int:
154
+ parser = argparse.ArgumentParser(description='TODO')
155
+ parser.add_argument('repository', help='TODO')
156
+ parser.add_argument('sourcebranch', default="stable", help='TODO')
157
+ parser.add_argument('targetbranch', default="master", help='TODO')
158
+ parser.add_argument('remotename', default=None, help='TODO')
159
+ parser.add_argument('--remove-sourcebranch', dest='removesourcebranch', action='store_true', help='TODO')
160
+ parser.add_argument('--no-remove-sourcebranch', dest='removesourcebranch', action='store_false', help='TODO')
161
+ parser.set_defaults(removesourcebranch=False)
162
+ args = parser.parse_args()
163
+ ScriptCollectionCore().SCCreateSimpleMergeWithoutRelease(args.repository, args.sourcebranch, args.targetbranch, args.remotename, args.removesourcebranch)
164
+ return 0
165
+
166
+
167
+ def CreateEmptyFileWithSpecificSize() -> int:
168
+ parser = argparse.ArgumentParser(description='Creates a file with a specific size')
169
+ parser.add_argument('name', help='Specifies the name of the created file')
170
+ parser.add_argument('size', help='Specifies the size of the created file')
171
+ args = parser.parse_args()
172
+ return ScriptCollectionCore().SCCreateEmptyFileWithSpecificSize(args.name, args.size)
173
+
174
+
175
+ def ShowMissingFiles() -> int:
176
+ parser = argparse.ArgumentParser(description='Shows all files which are in folderA but not in folder B. This program does not do any content-comparisons.')
177
+ parser.add_argument('folderA')
178
+ parser.add_argument('folderB')
179
+ args = parser.parse_args()
180
+ ScriptCollectionCore().show_missing_files(args.folderA, args.folderB)
181
+ return 0
182
+
183
+
184
+ def ExtractPDFPages() -> int:
185
+ parser = argparse.ArgumentParser(description='Extract pages from PDF-file')
186
+ parser.add_argument('file', help='Input file')
187
+ parser.add_argument('frompage', help='First page')
188
+ parser.add_argument('topage', help='Last page')
189
+ parser.add_argument('outputfile', help='File for the resulting PDF-document')
190
+ args = parser.parse_args()
191
+ ScriptCollectionCore().extract_pdf_pages(args.file, int(args.frompage), int(args.topage), args.outputfile)
192
+ return 0
193
+
194
+
195
+ def MergePDFs() -> int:
196
+ parser = argparse.ArgumentParser(description='Merges PDF-files')
197
+ parser.add_argument('files', help='Comma-separated filenames')
198
+ parser.add_argument('outputfile', help='File for the resulting PDF-document')
199
+ args = parser.parse_args()
200
+ ScriptCollectionCore().merge_pdf_files(args.files.split(','), args.outputfile)
201
+ return 0
202
+
203
+
204
+
205
+
206
+ def KeyboardDiagnosis() -> None:
207
+ """Caution: This function does usually never terminate"""
208
+ keyboard.hook(__keyhook)
209
+ while True:
210
+ time.sleep(10)
211
+
212
+
213
+ def __keyhook(self, event) -> None:
214
+ GeneralUtilities.write_message_to_stdout(str(event.name)+" "+event.event_type)
215
+
216
+
217
+ def GenerateThumbnail() -> int:
218
+ parser = argparse.ArgumentParser(description='Generate thumpnails for video-files')
219
+ parser.add_argument('file', help='Input-videofile for thumbnail-generation')
220
+ parser.add_argument('framerate', help='', default="16")
221
+ args = parser.parse_args()
222
+ try:
223
+ ScriptCollectionCore().generate_thumbnail(args.file, args.framerate)
224
+ return 0
225
+ except Exception as exception:
226
+ GeneralUtilities.write_exception_to_stderr_with_traceback(exception, traceback)
227
+ return 1
228
+
229
+
230
+ def ObfuscateFilesFolder() -> int:
231
+ parser = argparse.ArgumentParser(description='''Changes the hash-value of the files in the given folder and renames them to obfuscated names.
232
+ This script does not process subfolders transitively.
233
+ Caution: This script can cause harm if you pass a wrong inputfolder-argument.''')
234
+
235
+ parser.add_argument('--printtableheadline', type=GeneralUtilities.string_to_boolean, const=True, default=True, nargs='?', help='Prints column-titles in the name-mapping-csv-file')
236
+ parser.add_argument('--namemappingfile', default="NameMapping.csv", help='Specifies the file where the name-mapping will be written to')
237
+ parser.add_argument('--extensions', default="exe,py,sh", help='Comma-separated list of file-extensions of files where this tool should be applied. Use "*" to obfuscate all')
238
+ parser.add_argument('--inputfolder', help='Specifies the folder where the files are stored whose names should be obfuscated', required=True)
239
+
240
+ args = parser.parse_args()
241
+ ScriptCollectionCore().SCObfuscateFilesFolder(args.inputfolder, args.printtableheadline, args.namemappingfile, args.extensions)
242
+ return 0
243
+
244
+
245
+ def HealthCheck() -> int:
246
+ parser = argparse.ArgumentParser()
247
+ parser.add_argument('--file', required=True)
248
+ args = parser.parse_args()
249
+ return ScriptCollectionCore().SCHealthcheck(args.file)
250
+
251
+
252
+ def BuildCodeUnits() -> int:
253
+ parser = argparse.ArgumentParser()
254
+
255
+ parser.add_argument('--repositoryfolder', required=False, default=".")
256
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
257
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
258
+ parser.add_argument('-e','--targetenvironment', required=False, default="QualityCheck")
259
+ parser.add_argument('-a','--additionalargumentsfile', required=False, default=None)
260
+ parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
261
+ parser.add_argument('--ispremerge', required=False, default=False, action='store_true')
262
+
263
+ args = parser.parse_args()
264
+
265
+ verbosity=LogLevel(int(args.verbosity))
266
+
267
+ repo:str=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
268
+
269
+ t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,args.ispremerge)
270
+ t.build_codeunits()
271
+ return 0
272
+
273
+
274
+ def BuildCodeUnitsC() -> int:
275
+ parser = argparse.ArgumentParser()
276
+ parser.add_argument('--repositoryfolder', required=False, default=".")
277
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
278
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
279
+ parser.add_argument('--targetenvironment', required=False, default="QualityCheck")
280
+ parser.add_argument('--additionalargumentsfile', required=False, default=None)
281
+ parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
282
+ parser.add_argument('--ispremerge', required=False, default=False, action='store_true')
283
+ parser.add_argument('--image', required=False, default="scbuilder:latest")
284
+ args = parser.parse_args()
285
+ GeneralUtilities.reconfigure_standard_input_and_outputs()
286
+ repo:str=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
287
+ verbosity=LogLevel(int(args.verbosity))
288
+ t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,args.ispremerge)
289
+ t.build_codeunits_in_container()
290
+ return 1#TODO
291
+
292
+ def UpdateDependencies() -> int:
293
+ parser = argparse.ArgumentParser()
294
+ parser.add_argument('--repositoryfolder', required=False, default=".")
295
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
296
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
297
+ parser.add_argument('--targetenvironment', required=False, default="QualityCheck")
298
+ parser.add_argument('--additionalargumentsfile', required=False, default=None)
299
+ parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
300
+ args = parser.parse_args()
301
+ verbosity=LogLevel(int(args.verbosity))
302
+ repo:str=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
303
+ t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,False)
304
+ t.update_dependencies()
305
+ return 0
306
+
307
+
308
+ def GenerateCertificateAuthority() -> int:
309
+ parser = argparse.ArgumentParser()
310
+ parser.add_argument('--name', required=True)
311
+ parser.add_argument('--subj_c', required=True)
312
+ parser.add_argument('--subj_st', required=True)
313
+ parser.add_argument('--subj_l', required=True)
314
+ parser.add_argument('--subj_o', required=True)
315
+ parser.add_argument('--subj_ou', required=True)
316
+ parser.add_argument('--days_until_expire', required=False, default=None, type=int)
317
+ parser.add_argument('--password', required=False, default=None)
318
+ args = parser.parse_args()
319
+ ScriptCollectionCore().generate_certificate_authority(os.getcwd(), args.name, args.subj_c, args.subj_st, args.subj_l, args.subj_o, args.subj_ou, args.days_until_expire, args.password)
320
+ return 0
321
+
322
+
323
+ def GenerateCertificate() -> int:
324
+ parser = argparse.ArgumentParser()
325
+ parser.add_argument('--filename', required=True)
326
+ parser.add_argument('--domain', required=True)
327
+ parser.add_argument('--subj_c', required=True)
328
+ parser.add_argument('--subj_st', required=True)
329
+ parser.add_argument('--subj_l', required=True)
330
+ parser.add_argument('--subj_o', required=True)
331
+ parser.add_argument('--subj_ou', required=True)
332
+ parser.add_argument('--days_until_expire', required=False, default=None, type=int)
333
+ parser.add_argument('--password', required=False, default=None)
334
+ args = parser.parse_args()
335
+ ScriptCollectionCore().generate_certificate(os.getcwd(), args.domain, args.filename, args.subj_c, args.subj_st, args.subj_l, args.subj_o, args.subj_ou, args.days_until_expire, args.password)
336
+ return 0
337
+
338
+
339
+ def GenerateCertificateSignRequest() -> int:
340
+ parser = argparse.ArgumentParser()
341
+ parser.add_argument('--filename', required=True)
342
+ parser.add_argument('--domain', required=True)
343
+ parser.add_argument('--subj_c', required=True)
344
+ parser.add_argument('--subj_st', required=True)
345
+ parser.add_argument('--subj_l', required=True)
346
+ parser.add_argument('--subj_o', required=True)
347
+ parser.add_argument('--subj_ou', required=True)
348
+ args = parser.parse_args()
349
+ ScriptCollectionCore().generate_certificate_sign_request(os.getcwd(), args.domain, args.filename, args.subj_c, args.subj_st, args.subj_l, args.subj_o, args.sub_ou)
350
+ return 0
351
+
352
+
353
+ def SignCertificate() -> int:
354
+ parser = argparse.ArgumentParser()
355
+ parser.add_argument('--cafolder', required=True)
356
+ parser.add_argument('--caname', required=True)
357
+ parser.add_argument('--targetcertificate', required=True)
358
+ parser.add_argument('--filename', required=True)
359
+ parser.add_argument('--days_until_expire', required=False, default=None, type=int)
360
+ args = parser.parse_args()
361
+ ScriptCollectionCore().sign_certificate(os.getcwd(), args.cafolder, args.caname, args.targetcertificate, args.filename, args.args.days_until_expire)
362
+ return 0
363
+
364
+
365
+ def ChangeFileExtensions() -> int:
366
+ parser = argparse.ArgumentParser()
367
+ parser.add_argument('-f', '--folder', required=True)
368
+ parser.add_argument('-s', '--source_extension', required=True)
369
+ parser.add_argument('-t', '--target_extension', required=True)
370
+ parser.add_argument('-r', '--recursive', required=False, default=False, type=GeneralUtilities.string_to_boolean)
371
+ parser.add_argument('-i', '--ignore_case', required=False, default=True, type=GeneralUtilities.string_to_boolean)
372
+ args = parser.parse_args()
373
+ ScriptCollectionCore().change_file_extensions(args.folder, args.source_extension, args.target_extension, args.recursive, args.ignore_case)
374
+ return 0
375
+
376
+
377
+ def GenerateARC42ReferenceTemplate() -> int:
378
+ parser = argparse.ArgumentParser()
379
+ parser.add_argument('-f', '--folder', required=False)
380
+ parser.add_argument('-p', '--productname', required=False)
381
+ parser.add_argument('-s', '--subfolder', required=False)
382
+ args = parser.parse_args()
383
+
384
+ folder = args.folder
385
+ if folder is None:
386
+ folder = os.getcwd()
387
+ ScriptCollectionCore().generate_arc42_reference_template(folder, args.productname, args.subfolder)
388
+ return 0
389
+
390
+
391
+ def CreateChangelogEntry() -> int:
392
+ parser = argparse.ArgumentParser()
393
+ parser.add_argument('-p', '--repositorypath', required=False, default=".")
394
+ parser.add_argument('-m', '--message', required=False, default=None)
395
+ parser.add_argument('-c', '--commit', action='store_true', required=False, default=False)
396
+ parser.add_argument('-f', '--force', action='store_true', required=False, default=False)
397
+ args = parser.parse_args()
398
+
399
+ folder: str = None
400
+ if os.path.isabs(args.repositorypath):
401
+ folder = args.repositorypath
402
+ else:
403
+ folder = GeneralUtilities.resolve_relative_path(args.repositorypath, os.getcwd())
404
+ t=TFCPS_Tools_General(ScriptCollectionCore())
405
+ t.create_changelog_entry(folder, args.message, args.commit, args.force)
406
+ return 0
407
+
408
+
409
+ def FileExists() -> int:
410
+ parser = argparse.ArgumentParser(description="This function returns 0 if the given file exists. Otherwise this function returns 2. If an error occurrs the exitcode is 1.")
411
+ parser.add_argument('-p', '--path', required=True)
412
+ args = parser.parse_args()
413
+ if os.path.isfile(args.path):
414
+ return 0
415
+ else:
416
+ return 2
417
+
418
+
419
+ def FolderExists() -> int:
420
+ parser = argparse.ArgumentParser(description="This function returns 0 if the given folder exists. Otherwise this function returns 2. If an error occurrs the exitcode is 1.")
421
+ parser.add_argument('-p', '--path', required=True)
422
+ args = parser.parse_args()
423
+ if os.path.isdir(args.path):
424
+ return 0
425
+ else:
426
+ return 2
427
+
428
+
429
+ def PrintFileContent() -> int:
430
+ parser = argparse.ArgumentParser(description="This function prints the size of a file")
431
+ parser.add_argument('-p', '--path', required=True)
432
+ parser.add_argument('-e', '--encoding', required=False, default="utf-8")
433
+ args = parser.parse_args()
434
+ file = args.path
435
+ encoding = args.encoding
436
+ if os.path.isfile(file):
437
+ GeneralUtilities.write_message_to_stdout(GeneralUtilities.read_text_from_file(file, encoding))
438
+ return 0
439
+ else:
440
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
441
+ return 1
442
+
443
+
444
+ def CreateFile() -> int:
445
+ parser = argparse.ArgumentParser(description="This function creates an empty file.")
446
+ parser.add_argument('-p', '--path', required=True)
447
+ parser.add_argument('-e', '--errorwhenexists', action='store_true', required=False, default=False)
448
+ parser.add_argument('-c', '--createnecessaryfolder', action='store_true', required=False, default=False)
449
+ args = parser.parse_args()
450
+ sc = ScriptCollectionCore()
451
+ sc.create_file(args.path, args.errorwhenexists, args.createnecessaryfolder)
452
+ return 0
453
+
454
+
455
+ def CreateFolder() -> int:
456
+ parser = argparse.ArgumentParser(description="This function creates an empty folder.")
457
+ parser.add_argument('-p', '--path', required=True)
458
+ parser.add_argument('-e', '--errorwhenexists', action='store_true', required=False, default=False)
459
+ parser.add_argument('-c', '--createnecessaryfolder', action='store_true', required=False, default=False)
460
+ args = parser.parse_args()
461
+ sc = ScriptCollectionCore()
462
+ sc.create_folder(args.path, args.errorwhenexists, args.createnecessaryfolder)
463
+ return 0
464
+
465
+
466
+ def AppendLineToFile() -> int:
467
+ GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
468
+ # TODO implement function
469
+ # TODO add switch to set if adding new line at begin of line should be skipped if the file already ends with a new-line-character
470
+ # TODO add switch to enable/disable appending another new-line-character at the end of the file
471
+ return 1
472
+
473
+
474
+ def RegexReplaceInFile() -> int:
475
+ GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
476
+ # TODO implement function
477
+ return 1
478
+
479
+
480
+ def PrintFileSize() -> int:
481
+ parser = argparse.ArgumentParser(description="This function prints the size of a file")
482
+ parser.add_argument('-p', '--path', required=True)
483
+ args = parser.parse_args()
484
+ file = args.path
485
+ if os.path.isfile(file):
486
+ size = os.path.getsize(file)
487
+ GeneralUtilities.write_message_to_stdout(str(size))
488
+ return 0
489
+ else:
490
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
491
+ return 1
492
+
493
+
494
+ def FileContainsContent() -> int:
495
+ GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
496
+ # TODO implement function
497
+ # TODO add switch to set if the input pattern should be treated as regex
498
+ return 1
499
+
500
+
501
+ def RemoveFile() -> int:
502
+ parser = argparse.ArgumentParser(description="This function removes a file.")
503
+ parser.add_argument('-p', '--path', required=True)
504
+ parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
505
+ args = parser.parse_args()
506
+ file = args.path
507
+ errorwhennotexists = args.errorwhennotexists
508
+ if os.path.isfile(file):
509
+ GeneralUtilities.ensure_file_does_not_exist(file)
510
+ else:
511
+ if errorwhennotexists:
512
+ GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
513
+ return 1
514
+ return 0
515
+
516
+
517
+ def RemoveFolder() -> int:
518
+ parser = argparse.ArgumentParser(description="This function removes a folder.")
519
+ parser.add_argument('-p', '--path', required=True)
520
+ parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
521
+ args = parser.parse_args()
522
+ folder = args.path
523
+ errorwhennotexists = args.errorwhennotexists
524
+ if os.path.isdir(folder):
525
+ GeneralUtilities.ensure_directory_does_not_exist(folder)
526
+ else:
527
+ if errorwhennotexists:
528
+ GeneralUtilities.write_exception_to_stderr(f"Folder '{folder}' does not exist.")
529
+ return 1
530
+ return 0
531
+
532
+
533
+ def Rename() -> int:
534
+ parser = argparse.ArgumentParser(description="This function renames a file or folder.")
535
+ parser.add_argument('-s', '--source', required=True)
536
+ parser.add_argument('-t', '--target', required=True)
537
+ args = parser.parse_args()
538
+ os.rename(args.source, args.target)
539
+ return 0
540
+
541
+
542
+ def Copy() -> int:
543
+ parser = argparse.ArgumentParser(description="This function copies a file or folder.")
544
+ parser.add_argument('-s', '--source', required=True)
545
+ parser.add_argument('-t', '--target', required=True)
546
+ args = parser.parse_args()
547
+
548
+ if os.path.isfile(args.target) or os.path.isdir(args.target):
549
+ raise ValueError(f"Can not copy to '{args.target}' because the target already exists.")
550
+
551
+ source = args.source
552
+ if not os.path.isabs(source):
553
+ source = GeneralUtilities.resolve_relative_path(source, os.getcwd())
554
+ target = args.target
555
+ if not os.path.isabs(target):
556
+ target = GeneralUtilities.resolve_relative_path(target, os.getcwd())
557
+
558
+ if os.path.isfile(source):
559
+ shutil.copyfile(source, target)
560
+ elif os.path.isdir(source):
561
+ GeneralUtilities.ensure_directory_exists(target)
562
+ GeneralUtilities.copy_content_of_folder(source, target)
563
+ else:
564
+ raise ValueError(f"'{source}' can not be copied because the path does not exist.")
565
+ return 0
566
+
567
+ def GetSize() -> int:
568
+ parser = argparse.ArgumentParser(description="This function prints the size of a file.")
569
+ parser.add_argument('-p', '--path', required=True)
570
+ args = parser.parse_args()
571
+
572
+ path = GeneralUtilities.resolve_relative_path(args.path, os.getcwd())
573
+
574
+ if not os.path.isfile(path):
575
+ raise ValueError(f"File '{path}' does not exist.")
576
+
577
+ GeneralUtilities.write_message_to_stdout(str(os.path.getsize(path)))
578
+ return 0
579
+
580
+ def PrintOSName() -> int:
581
+ if GeneralUtilities.current_system_is_windows():
582
+ GeneralUtilities.write_message_to_stdout("Windows")
583
+ elif GeneralUtilities.current_system_is_linux():
584
+ GeneralUtilities.write_message_to_stdout("Linux")
585
+ # TODO consider Mac, Unix, etc. too
586
+ else:
587
+ GeneralUtilities.write_message_to_stderr("Unknown OS.")
588
+ return 1
589
+ return 0
590
+
591
+
592
+ def PrintCurrecntWorkingDirectory() -> int:
593
+ GeneralUtilities.write_message_to_stdout(os.getcwd())
594
+ return 0
595
+
596
+
597
+ def ListFolderContent() -> int:
598
+ parser = argparse.ArgumentParser(description="This function lists folder-content.")
599
+ parser.add_argument('-p', '--path', required=True)
600
+ parser.add_argument('-f', '--excludefiles', action='store_true', required=False, default=False)
601
+ parser.add_argument('-d', '--excludedirectories', action='store_true', required=False, default=False)
602
+ parser.add_argument('-n', '--printonlynamewithoutpath', action='store_true', required=False, default=False)
603
+ # TODO add option to also list transitively list subfolder
604
+ # TODO add option to show only content which matches a filter by extension or regex or glob-pattern
605
+ args = parser.parse_args()
606
+ folder = args.path
607
+ if not os.path.isabs(folder):
608
+ folder = GeneralUtilities.resolve_relative_path(folder, os.getcwd())
609
+ content = []
610
+ if not args.excludefiles:
611
+ content = content+GeneralUtilities.get_direct_files_of_folder(folder)
612
+ if not args.excludedirectories:
613
+ content = content+GeneralUtilities.get_direct_folders_of_folder(folder)
614
+ for contentitem in content:
615
+ content_to_print: str = None
616
+ if args.printonlynamewithoutpath:
617
+ content_to_print = os.path.basename(contentitem)
618
+ else:
619
+ content_to_print = contentitem
620
+ GeneralUtilities.write_message_to_stdout(content_to_print)
621
+ return 0
622
+
623
+
624
+ def ForEach() -> int:
625
+ GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
626
+ # TODO implement function
627
+ return 1
628
+
629
+
630
+ def NpmI() -> int:
631
+ parser = argparse.ArgumentParser(description="Does \"npm clean install\".")
632
+ parser.add_argument('-d', '--directory', required=False, default=".")
633
+ parser.add_argument('-f', '--force', action='store_true', required=False, default=False)
634
+ parser.add_argument('-v', '--verbose', action='store_true', required=False, default=False)
635
+ parser.add_argument('-c', '--nocache', action='store_true', required=False, default=False)
636
+ args = parser.parse_args()
637
+ if os.path.isabs(args.directory):
638
+ folder = args.directory
639
+ else:
640
+ folder = GeneralUtilities.resolve_relative_path(args.directory, os.getcwd())
641
+ t = TFCPS_Tools_General(ScriptCollectionCore())
642
+ t.do_npm_install(folder, args.force,not args.nocache)
643
+ return 0
644
+
645
+
646
+ def CurrentUserHasElevatedPrivileges() -> int:
647
+ parser = argparse.ArgumentParser(description="Returns 1 if the current user has elevated privileges. Otherwise this function returns 0.")
648
+ parser.parse_args()
649
+ if GeneralUtilities.current_user_has_elevated_privileges():
650
+ return 1
651
+ else:
652
+ return 0
653
+
654
+
655
+ def Espoc() -> int:
656
+ parser = argparse.ArgumentParser(description="Espoc (appreviation for 'exit started programs on close') is a tool to ensure the started processes of your program will also get terminated when the execution of your program is finished.")
657
+ parser.add_argument('-p', '--processid', required=True)
658
+ parser.add_argument('-f', '--file', required=True, help='Specifies the file where the process-ids of the started processes are stored (line by line). This file will be deleted when all started processes are terminated.')
659
+ parser.add_argument('-l', '--logfile', required=False,default=None)
660
+ args = parser.parse_args()
661
+ process_id = int(args.processid)
662
+ process_list_file: str = args.file
663
+ log:SCLog=None
664
+ if args.logfile is None:
665
+ log=SCLog()
666
+ else:
667
+ log=SCLog(args.logfile)
668
+ log.add_overhead_to_logfile=True
669
+ log.log(f"Start Espoc for process id {process_id} and process list file '{process_list_file}'.")
670
+ try:
671
+ if not os.path.isabs(process_list_file):
672
+ process_list_file = GeneralUtilities.resolve_relative_path(process_list_file, os.getcwd())
673
+ GeneralUtilities.assert_condition(GeneralUtilities.process_is_running_by_id(process_id), f"Process with id {process_id} is not running.")
674
+ while GeneralUtilities.process_is_running_by_id(process_id):
675
+ time.sleep(1)
676
+ log.log(f"Process with id {process_id} is not running anymore. Start terminating remaining processes.")
677
+ if os.path.exists(process_list_file):
678
+ for line in GeneralUtilities.read_nonempty_lines_from_file(process_list_file):
679
+ current_process_id = int(line.strip())
680
+ try:
681
+ log.log(f"Terminate process {current_process_id}...")
682
+ GeneralUtilities.kill_process(current_process_id, True)
683
+ except Exception as exception:
684
+ log.log_exception(f"Error while terminating process with id {current_process_id}.",exception)
685
+ log.log("All started processes terminated.")
686
+ GeneralUtilities.ensure_file_does_not_exist(process_list_file)
687
+ else:
688
+ log.log(f"File '{process_list_file}' does not exist. No processes to terminate.")
689
+ return 0
690
+ except Exception as exception:
691
+ log.log_exception("Fatal error in Espoc.", exception)
692
+ return 1
693
+
694
+
695
+ def ConvertGitRepositoryToBareRepository() -> int:
696
+ parser = argparse.ArgumentParser(description="Converts a local git-repository to a bare repository.")
697
+ parser.add_argument('-f', '--folder', required=True, help='Git-repository-folder which should be converted.')
698
+ args = parser.parse_args()
699
+ sc = ScriptCollectionCore()
700
+ sc.convert_git_repository_to_bare_repository(args.folder)
701
+ return 0
702
+
703
+
704
+ def OCRAnalysisOfFolder() -> int:
705
+ parser = argparse.ArgumentParser()
706
+ parser.add_argument('-s', '--serviceaddress', required=False, default=None)
707
+ parser.add_argument('-e', '--extensions', required=False, default="pdf,docx,jpg,png,xlsx")
708
+ parser.add_argument('-l', '--languages', required=False, default="eng")
709
+ parser.add_argument('-f', '--folder', required=False, default=None)
710
+ args = parser.parse_args()
711
+ sc = ScriptCollectionCore()
712
+ if args.folder is None:
713
+ args.folder = os.getcwd()
714
+ languages=args.languages.split(",")
715
+ extensions=args.extensions.split(",")
716
+ sc.ocr_analysis_of_folder(args.folder, args.serviceaddress, extensions, languages,args.folder,[])
717
+ return 0
718
+
719
+
720
+ def OCRAnalysisOfFile() -> int:
721
+ parser = argparse.ArgumentParser()
722
+ parser.add_argument('-s', '--serviceaddress', required=False, default=None)
723
+ parser.add_argument('-l', '--languages', required=False, default="eng")
724
+ parser.add_argument('-f', '--file', required=True)
725
+ args = parser.parse_args()
726
+ sc = ScriptCollectionCore()
727
+ languages=args.languages.split(",")
728
+ sc.ocr_analysis_of_file(args.file, args.serviceaddress, languages,".")
729
+ return 0
730
+
731
+
732
+ def OCRAnalysisOfRepository() -> int:
733
+ parser = argparse.ArgumentParser()
734
+ parser.add_argument('-s', '--serviceaddress', required=False, default=None)
735
+ parser.add_argument('-e', '--extensions', required=False, default="pdf,docx,jpg,png,xlsx")
736
+ parser.add_argument('-l', '--languages', required=False, default="eng")
737
+ parser.add_argument('-f', '--folder', required=False, default=None)
738
+ args = parser.parse_args()
739
+ sc = ScriptCollectionCore()
740
+ if args.folder is None:
741
+ args.folder = os.getcwd()
742
+ languages=args.languages.split(",")
743
+ extensions=args.extensions.split(",")
744
+ sc.ocr_analysis_of_repository(args.folder, args.serviceaddress, extensions, languages)
745
+ return 0
746
+
747
+
748
+ def UpdateImagesInDockerComposeFile() -> int:
749
+ parser = argparse.ArgumentParser(description="This function updates images in a Docker Compose file.")
750
+ parser.add_argument('-f', '--file', required=False,default="./docker-compose.yml")
751
+ #TODO add possibility to set version-echolon for each image specifically and pass this information to OCIImageManager
752
+ args = parser.parse_args()
753
+ sc = ScriptCollectionCore()
754
+ file=GeneralUtilities.resolve_relative_path(args.file, os.getcwd())
755
+ oci=OCIImageManager(sc)
756
+ oci.update_image_in_docker_compose_file(file)
757
+ return 0
758
+
759
+
760
+ def SetFileContent() -> int:
761
+ parser = argparse.ArgumentParser(description="This function writes content into a file.")
762
+ parser.add_argument('-p', '--path', required=True)
763
+ parser.add_argument('-b', '--argumentisinbase64', action='store_true', required=False, default=False)
764
+ parser.add_argument('-c', '--content', required=True)
765
+ parser.add_argument('-e', '--encoding', required=False, default="utf-8")
766
+ args = parser.parse_args()
767
+ sc = ScriptCollectionCore()
768
+ content = args.content
769
+ if args.argumentisinbase64:
770
+ base64_string: str = args.content
771
+ base64_bytes = base64_string.encode('utf-8')
772
+ original_bytes = base64.b64decode(base64_bytes)
773
+ content = original_bytes.decode('utf-8')
774
+ sc.set_file_content(args.path, content, args.encoding)
775
+ return 0
776
+
777
+
778
+ def GenerateTaskfileFromWorkspacefile() -> int:
779
+ parser = argparse.ArgumentParser(description="Generates a taskfile.yml-file from a .code-workspace-file")
780
+ parser.add_argument('-f', '--repositoryfolder', required=True)
781
+ #args = parser.parse_args()
782
+ #t = TasksForCommonProjectStructure()
783
+ #t.generate_tasksfile_from_workspace_file(args.repositoryfolder)
784
+ #return 0
785
+ return 1#TODO
786
+
787
+
788
+ def UpdateTimestampInFile() -> int:
789
+ parser = argparse.ArgumentParser(description="Update the timestamp in a comment in a file")
790
+ parser.add_argument('-f', '--file', required=True)
791
+ args = parser.parse_args()
792
+ sc = ScriptCollectionCore()
793
+ sc.update_timestamp_in_file(args.file)
794
+ return 0
795
+
796
+
797
+ def LOC() -> int:
798
+ sc = ScriptCollectionCore()
799
+ default_patterns: list[str] = sc.default_excluded_patterns_for_loc
800
+ default_patterns_joined = ",".join(default_patterns)
801
+ parser = argparse.ArgumentParser(description=f"Counts the lines of code in a git-repository. Default patterns are: {default_patterns_joined}")
802
+ parser.add_argument('-r', '--repository', required=True)
803
+ parser.add_argument('-e', '--excluded_pattern', nargs='+')
804
+ parser.add_argument('-d', '--do_not_add_default_pattern', action='store_true', default=False)
805
+ parser.add_argument('-v', '--verbose', action='store_true', default=False)
806
+ args = parser.parse_args()
807
+
808
+ folder: str = None
809
+ if os.path.isabs(args.repository):
810
+ folder = args.repository
811
+ else:
812
+ folder = GeneralUtilities.resolve_relative_path(args.repository, os.getcwd())
813
+ excluded_patterns: list[str] = []
814
+
815
+ if not args.do_not_add_default_pattern:
816
+ excluded_patterns = excluded_patterns + sc.default_excluded_patterns_for_loc
817
+ if args.excluded_pattern is not None:
818
+ excluded_patterns = excluded_patterns + args.excluded_pattern
819
+
820
+ if args.verbose:
821
+ sc.log.loglevel=LogLevel.Debug
822
+ else:
823
+ sc.log.loglevel=LogLevel.Information
824
+
825
+ GeneralUtilities.write_message_to_stdout(str(sc.get_lines_of_code(folder, excluded_patterns)))
826
+ return 0
827
+
828
+ def CreateRelease()->int:
829
+ sc = ScriptCollectionCore()
830
+ parser = argparse.ArgumentParser(description="Creates a release in a git-repository which uses the anion-build-platform.")
831
+ parser.add_argument('-b', '--buildrepository', required=False, default=".")
832
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
833
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
834
+ parser.add_argument('-s', '--sourcebranch', required=False, default="other/next-release")
835
+ parser.add_argument('-u', '--updatedependencies', required=False, action='store_true', default=False)
836
+ parser.add_argument('-l', '--lazymode', required=False, action='store_true', default=False)
837
+ args = parser.parse_args()
838
+
839
+ build_repo_folder: str = None
840
+ if os.path.isabs(args.buildrepository):
841
+ build_repo_folder = args.buildrepository
842
+ else:
843
+ build_repo_folder = GeneralUtilities.resolve_relative_path(args.buildrepository, os.getcwd())
844
+
845
+ verbosity=int(args.verbosity)
846
+ sc.log.loglevel=LogLevel(verbosity)
847
+
848
+ scripts_folder:str=os.path.join(build_repo_folder,"Scripts","CreateRelease")
849
+ arguments=f"CreateRelease.py --buildrepositoriesfolder {build_repo_folder} --verbosity {verbosity} --sourcebranch {args.sourcebranch}"
850
+ if args.updatedependencies:
851
+ arguments=arguments+" --updatedependencies"
852
+ if args.lazymode:
853
+ arguments=arguments+" --lazymode"
854
+ sc.run_program(GeneralUtilities.get_python_executable(), arguments, scripts_folder,print_live_output=True)
855
+
856
+ return 0
857
+
858
+ def CleanToolsCache()->int:
859
+ sc=ScriptCollectionCore()
860
+ GeneralUtilities.ensure_folder_exists_and_is_empty(sc.get_global_cache_folder())
861
+ return 0
862
+
863
+
864
+ def EnsureDockerNetworkIsAvailable()->int:
865
+ sc = ScriptCollectionCore()
866
+ parser = argparse.ArgumentParser()
867
+ parser.add_argument('-n', '--networkname', required=True)
868
+ args = parser.parse_args()
869
+
870
+ sc:ScriptCollectionCore=ScriptCollectionCore()
871
+ sc.ensure_docker_network_is_available(args.networkname)
872
+ return 0
873
+
874
+
875
+ def ReclaimSpaceFromDocker()->int:
876
+ sc = ScriptCollectionCore()
877
+ parser = argparse.ArgumentParser()
878
+ parser.add_argument('-c', '--removecontainers', action='store_true', default=False)
879
+ parser.add_argument('-v', '--removevolumes', action='store_true', default=False)
880
+ parser.add_argument('-i', '--removeimages', action='store_true', default=False)
881
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
882
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
883
+ args = parser.parse_args()
884
+ sc:ScriptCollectionCore=ScriptCollectionCore()
885
+ verbosity=int(args.verbosity)
886
+ sc.log.loglevel=LogLevel(verbosity)
887
+ sc.reclaim_space_from_docker(args.removecontainers,args.removevolumes,args.removeimages)
888
+ return 0
889
+
890
+
891
+ def AddImageToCustomRegistry()->int:
892
+ sc = ScriptCollectionCore()
893
+ parser = argparse.ArgumentParser()
894
+ parser.add_argument('-r', '--remotehub', required=True)
895
+ parser.add_argument('-i', '--imagenameonremotehub', required=True)
896
+ parser.add_argument('-o', '--ownregistryaddress', required=True)
897
+ parser.add_argument('-l', '--imagenameonownregistry', required=True)
898
+ parser.add_argument('-t', '--tag', required=False,default="latest")
899
+ parser.add_argument('-u', '--username', required=False,default=None)
900
+ parser.add_argument('-p', '--password', required=False,default=None)
901
+ verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
902
+ parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
903
+ parser.add_argument('-r', '--removeimagelocally', action='store_true', default=False)
904
+ args = parser.parse_args()
905
+ sc:ScriptCollectionCore=ScriptCollectionCore()
906
+ verbosity=int(args.verbosity)
907
+ sc.log.loglevel=LogLevel(verbosity)
908
+ sc.add_image_to_custom_docker_image_registry(args.remotehub,args.imagenameonremotehub,args.ownregistryaddress,args.imagenameonownregistry,args.tag,args.username,args.password)
909
+ return 0
910
+
911
+ def SyncXlfFiles()->int:
912
+ parser = argparse.ArgumentParser(description="This function syncs the content of xlf-files in a folder. This is useful to keep the content of xlf-files in sync which are used for translations in software projects.")
913
+ parser.add_argument('-p', '--prefix', required=True, help="File prefix. Example: 'message' when the files are named 'message.xlf', 'message.fr.xlf', etc.")
914
+ parser.add_argument('-l', '--languages', required=True, help="Comma-separated list of languages. Example: 'en,fr,de'")
915
+ parser.add_argument('-f', '--folder', required=False)
916
+ args = parser.parse_args()
917
+ sc:ScriptCollectionCore=ScriptCollectionCore()
918
+ languages=str(args.languages).split(",")
919
+ folder=GeneralUtilities.resolve_relative_path(args.folder, os.getcwd())
920
+ sc.sync_xlf2_files(args.prefix, languages, folder)
921
+ return 0