ScriptCollection 3.3.23__py3-none-any.whl → 4.0.78__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.
- ScriptCollection/AnionBuildPlatform.py +206 -0
- ScriptCollection/{UpdateCertificates.py → CertificateUpdater.py} +149 -128
- ScriptCollection/Executables.py +868 -292
- ScriptCollection/GeneralUtilities.py +609 -107
- ScriptCollection/ImageUpdater.py +648 -0
- ScriptCollection/ProcessesRunner.py +41 -0
- ScriptCollection/ProgramRunnerBase.py +47 -42
- ScriptCollection/ProgramRunnerMock.py +2 -0
- ScriptCollection/ProgramRunnerPopen.py +57 -50
- ScriptCollection/ProgramRunnerSudo.py +108 -0
- ScriptCollection/SCLog.py +115 -0
- ScriptCollection/ScriptCollectionCore.py +2541 -1383
- ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +95 -0
- ScriptCollection/TFCPS/Docker/__init__.py +0 -0
- ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py +8 -0
- ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py +6 -0
- ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py +7 -0
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +485 -0
- ScriptCollection/TFCPS/DotNet/__init__.py +0 -0
- ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +130 -0
- ScriptCollection/TFCPS/Flutter/__init__.py +0 -0
- ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py +74 -0
- ScriptCollection/TFCPS/Go/__init__.py +0 -0
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +131 -0
- ScriptCollection/TFCPS/NodeJS/__init__.py +0 -0
- ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py +227 -0
- ScriptCollection/TFCPS/Python/__init__.py +0 -0
- ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +418 -0
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py +128 -0
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +136 -0
- ScriptCollection/TFCPS/TFCPS_CreateRelease.py +95 -0
- ScriptCollection/TFCPS/TFCPS_Generic.py +43 -0
- ScriptCollection/TFCPS/TFCPS_MergeToMain.py +122 -0
- ScriptCollection/TFCPS/TFCPS_MergeToStable.py +350 -0
- ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py +47 -0
- ScriptCollection/TFCPS/TFCPS_Tools_General.py +1356 -0
- ScriptCollection/TFCPS/__init__.py +0 -0
- {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/METADATA +26 -21
- scriptcollection-4.0.78.dist-info/RECORD +43 -0
- {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/WHEEL +1 -1
- scriptcollection-4.0.78.dist-info/entry_points.txt +64 -0
- ScriptCollection/Hardening.py +0 -59
- ScriptCollection/ProgramRunnerEpew.py +0 -122
- ScriptCollection/TasksForCommonProjectStructure.py +0 -1170
- ScriptCollection-3.3.23.dist-info/RECORD +0 -15
- ScriptCollection-3.3.23.dist-info/entry_points.txt +0 -24
- {ScriptCollection-3.3.23.dist-info → scriptcollection-4.0.78.dist-info}/top_level.txt +0 -0
ScriptCollection/Executables.py
CHANGED
|
@@ -1,292 +1,868 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from .
|
|
9
|
-
from .
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
parser.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
parser.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
parser =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
parser.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
parser.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
parser.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
parser =
|
|
140
|
-
|
|
141
|
-
parser.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
parser
|
|
155
|
-
parser.add_argument(
|
|
156
|
-
parser.add_argument(
|
|
157
|
-
parser.add_argument(
|
|
158
|
-
parser.add_argument('
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
parser.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
parser.
|
|
177
|
-
parser.add_argument('
|
|
178
|
-
parser.add_argument('
|
|
179
|
-
parser.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
parser
|
|
190
|
-
parser.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
parser
|
|
198
|
-
parser.add_argument('
|
|
199
|
-
parser.
|
|
200
|
-
args
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
parser
|
|
207
|
-
parser.add_argument('
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
parser.add_argument('--
|
|
246
|
-
|
|
247
|
-
parser.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
parser.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
args
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
parser
|
|
276
|
-
|
|
277
|
-
parser.add_argument('--
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
|
11
|
+
from .ImageUpdater import ImageUpdater, VersionEcholon
|
|
12
|
+
from .TFCPS.TFCPS_CodeUnit_BuildCodeUnits import TFCPS_CodeUnit_BuildCodeUnits
|
|
13
|
+
from .TFCPS.TFCPS_Tools_General import TFCPS_Tools_General
|
|
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
|
+
return 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
|
+
def PDFToImage() -> int:
|
|
205
|
+
parser = argparse.ArgumentParser(description='Converts a PDF-document to an image')
|
|
206
|
+
parser.add_argument('file', help='Input-file')
|
|
207
|
+
parser.add_argument('outputfilename_without_extension', help='File for the resulting image')
|
|
208
|
+
args = parser.parse_args()
|
|
209
|
+
ScriptCollectionCore().pdf_to_image(args.file, args.outputfilename_without_extension)
|
|
210
|
+
return 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def KeyboardDiagnosis() -> None:
|
|
214
|
+
"""Caution: This function does usually never terminate"""
|
|
215
|
+
keyboard.hook(__keyhook)
|
|
216
|
+
while True:
|
|
217
|
+
time.sleep(10)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def __keyhook(self, event) -> None:
|
|
221
|
+
GeneralUtilities.write_message_to_stdout(str(event.name)+" "+event.event_type)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def GenerateThumbnail() -> int:
|
|
225
|
+
parser = argparse.ArgumentParser(description='Generate thumpnails for video-files')
|
|
226
|
+
parser.add_argument('file', help='Input-videofile for thumbnail-generation')
|
|
227
|
+
parser.add_argument('framerate', help='', default="16")
|
|
228
|
+
args = parser.parse_args()
|
|
229
|
+
try:
|
|
230
|
+
ScriptCollectionCore().generate_thumbnail(args.file, args.framerate)
|
|
231
|
+
return 0
|
|
232
|
+
except Exception as exception:
|
|
233
|
+
GeneralUtilities.write_exception_to_stderr_with_traceback(exception, traceback)
|
|
234
|
+
return 1
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def ObfuscateFilesFolder() -> int:
|
|
238
|
+
parser = argparse.ArgumentParser(description='''Changes the hash-value of the files in the given folder and renames them to obfuscated names.
|
|
239
|
+
This script does not process subfolders transitively.
|
|
240
|
+
Caution: This script can cause harm if you pass a wrong inputfolder-argument.''')
|
|
241
|
+
|
|
242
|
+
parser.add_argument('--printtableheadline', type=GeneralUtilities.string_to_boolean, const=True, default=True, nargs='?', help='Prints column-titles in the name-mapping-csv-file')
|
|
243
|
+
parser.add_argument('--namemappingfile', default="NameMapping.csv", help='Specifies the file where the name-mapping will be written to')
|
|
244
|
+
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')
|
|
245
|
+
parser.add_argument('--inputfolder', help='Specifies the folder where the files are stored whose names should be obfuscated', required=True)
|
|
246
|
+
|
|
247
|
+
args = parser.parse_args()
|
|
248
|
+
ScriptCollectionCore().SCObfuscateFilesFolder(args.inputfolder, args.printtableheadline, args.namemappingfile, args.extensions)
|
|
249
|
+
return 0
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def HealthCheck() -> int:
|
|
253
|
+
parser = argparse.ArgumentParser()
|
|
254
|
+
parser.add_argument('--file', required=True)
|
|
255
|
+
args = parser.parse_args()
|
|
256
|
+
return ScriptCollectionCore().SCHealthcheck(args.file)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def BuildCodeUnit() -> int:
|
|
260
|
+
parser = argparse.ArgumentParser()
|
|
261
|
+
parser.add_argument('--codeunitfolder', required=False, default=".")
|
|
262
|
+
verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
|
|
263
|
+
parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
|
|
264
|
+
parser.add_argument('-e','--targetenvironment', required=False, default="QualityCheck")
|
|
265
|
+
parser.add_argument('-a','--additionalargumentsfile', required=False, default=None)
|
|
266
|
+
parser.add_argument('--assume_dependent_codeunits_are_already_built', type=GeneralUtilities.string_to_boolean, const=True, default=False, nargs='?')
|
|
267
|
+
#args = parser.parse_args()
|
|
268
|
+
#t=TasksForCommonProjectStructure(args)
|
|
269
|
+
#t.build_codeunit(args.codeunitfolder, args.targetenvironment, args.additionalargumentsfile, False, None, args.assume_dependent_codeunits_are_already_built, sys.argv)
|
|
270
|
+
#return 0
|
|
271
|
+
return 1#TODO
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def BuildCodeUnits() -> int:
|
|
275
|
+
parser = argparse.ArgumentParser()
|
|
276
|
+
|
|
277
|
+
parser.add_argument('--repositoryfolder', required=False, default=".")
|
|
278
|
+
verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
|
|
279
|
+
parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
|
|
280
|
+
parser.add_argument('-e','--targetenvironment', required=False, default="QualityCheck")
|
|
281
|
+
parser.add_argument('-a','--additionalargumentsfile', required=False, default=None)
|
|
282
|
+
parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
|
|
283
|
+
parser.add_argument('--ispremerge', required=False, default=False, action='store_true')
|
|
284
|
+
|
|
285
|
+
args = parser.parse_args()
|
|
286
|
+
|
|
287
|
+
verbosity=LogLevel(int(args.verbosity))
|
|
288
|
+
|
|
289
|
+
repo:str=args.repositoryfolder
|
|
290
|
+
if not os.path.isabs(args.repositoryfolder):
|
|
291
|
+
repo=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
|
|
292
|
+
|
|
293
|
+
t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,args.ispremerge)
|
|
294
|
+
t.build_codeunits()
|
|
295
|
+
return 0
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def BuildCodeUnitsC() -> int:
|
|
299
|
+
parser = argparse.ArgumentParser()
|
|
300
|
+
parser.add_argument('--repositoryfolder', required=False, default=".")
|
|
301
|
+
verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
|
|
302
|
+
parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
|
|
303
|
+
parser.add_argument('--targetenvironment', required=False, default="QualityCheck")
|
|
304
|
+
parser.add_argument('--additionalargumentsfile', required=False, default=None)
|
|
305
|
+
parser.add_argument('--image', required=False, default="scbuilder:latest")
|
|
306
|
+
#args = parser.parse_args()
|
|
307
|
+
GeneralUtilities.reconfigure_standrd_input_and_outputs()
|
|
308
|
+
#t=TasksForCommonProjectStructure(args)
|
|
309
|
+
#t.build_codeunitsC(args.repositoryfolder, args.image, args.targetenvironment, args.additionalargumentsfile, sys.argv)
|
|
310
|
+
#return 0
|
|
311
|
+
return 1#TODO
|
|
312
|
+
|
|
313
|
+
def UpdateDependencies() -> int:
|
|
314
|
+
parser = argparse.ArgumentParser()
|
|
315
|
+
|
|
316
|
+
parser.add_argument('--repositoryfolder', required=False, default=".")
|
|
317
|
+
verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
|
|
318
|
+
parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
|
|
319
|
+
parser.add_argument('--targetenvironment', required=False, default="QualityCheck")
|
|
320
|
+
parser.add_argument('--additionalargumentsfile', required=False, default=None)
|
|
321
|
+
parser.add_argument("-c",'--nocache', required=False, default=False, action='store_true')
|
|
322
|
+
|
|
323
|
+
args = parser.parse_args()
|
|
324
|
+
|
|
325
|
+
verbosity=LogLevel(int(args.verbosity))
|
|
326
|
+
|
|
327
|
+
repo:str=args.repositoryfolder
|
|
328
|
+
if not os.path.isabs(args.repositoryfolder):
|
|
329
|
+
repo=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
|
|
330
|
+
|
|
331
|
+
t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,False)
|
|
332
|
+
t.update_dependencies()
|
|
333
|
+
return 0
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def GenerateCertificateAuthority() -> int:
|
|
337
|
+
parser = argparse.ArgumentParser()
|
|
338
|
+
parser.add_argument('--name', required=True)
|
|
339
|
+
parser.add_argument('--subj_c', required=True)
|
|
340
|
+
parser.add_argument('--subj_st', required=True)
|
|
341
|
+
parser.add_argument('--subj_l', required=True)
|
|
342
|
+
parser.add_argument('--subj_o', required=True)
|
|
343
|
+
parser.add_argument('--subj_ou', required=True)
|
|
344
|
+
parser.add_argument('--days_until_expire', required=False, default=None, type=int)
|
|
345
|
+
parser.add_argument('--password', required=False, default=None)
|
|
346
|
+
args = parser.parse_args()
|
|
347
|
+
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)
|
|
348
|
+
return 0
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def GenerateCertificate() -> int:
|
|
352
|
+
parser = argparse.ArgumentParser()
|
|
353
|
+
parser.add_argument('--filename', required=True)
|
|
354
|
+
parser.add_argument('--domain', required=True)
|
|
355
|
+
parser.add_argument('--subj_c', required=True)
|
|
356
|
+
parser.add_argument('--subj_st', required=True)
|
|
357
|
+
parser.add_argument('--subj_l', required=True)
|
|
358
|
+
parser.add_argument('--subj_o', required=True)
|
|
359
|
+
parser.add_argument('--subj_ou', required=True)
|
|
360
|
+
parser.add_argument('--days_until_expire', required=False, default=None, type=int)
|
|
361
|
+
parser.add_argument('--password', required=False, default=None)
|
|
362
|
+
args = parser.parse_args()
|
|
363
|
+
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)
|
|
364
|
+
return 0
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def GenerateCertificateSignRequest() -> int:
|
|
368
|
+
parser = argparse.ArgumentParser()
|
|
369
|
+
parser.add_argument('--filename', required=True)
|
|
370
|
+
parser.add_argument('--domain', required=True)
|
|
371
|
+
parser.add_argument('--subj_c', required=True)
|
|
372
|
+
parser.add_argument('--subj_st', required=True)
|
|
373
|
+
parser.add_argument('--subj_l', required=True)
|
|
374
|
+
parser.add_argument('--subj_o', required=True)
|
|
375
|
+
parser.add_argument('--subj_ou', required=True)
|
|
376
|
+
args = parser.parse_args()
|
|
377
|
+
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)
|
|
378
|
+
return 0
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def SignCertificate() -> int:
|
|
382
|
+
parser = argparse.ArgumentParser()
|
|
383
|
+
parser.add_argument('--cafolder', required=True)
|
|
384
|
+
parser.add_argument('--caname', required=True)
|
|
385
|
+
parser.add_argument('--targetcertificate', required=True)
|
|
386
|
+
parser.add_argument('--filename', required=True)
|
|
387
|
+
parser.add_argument('--days_until_expire', required=False, default=None, type=int)
|
|
388
|
+
args = parser.parse_args()
|
|
389
|
+
ScriptCollectionCore().sign_certificate(os.getcwd(), args.cafolder, args.caname, args.targetcertificate, args.filename, args.args.days_until_expire)
|
|
390
|
+
return 0
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def ChangeFileExtensions() -> int:
|
|
394
|
+
parser = argparse.ArgumentParser()
|
|
395
|
+
parser.add_argument('-f', '--folder', required=True)
|
|
396
|
+
parser.add_argument('-s', '--source_extension', required=True)
|
|
397
|
+
parser.add_argument('-t', '--target_extension', required=True)
|
|
398
|
+
parser.add_argument('-r', '--recursive', required=False, default=False, type=GeneralUtilities.string_to_boolean)
|
|
399
|
+
parser.add_argument('-i', '--ignore_case', required=False, default=True, type=GeneralUtilities.string_to_boolean)
|
|
400
|
+
args = parser.parse_args()
|
|
401
|
+
ScriptCollectionCore().change_file_extensions(args.folder, args.source_extension, args.target_extension, args.recursive, args.ignore_case)
|
|
402
|
+
return 0
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def GenerateARC42ReferenceTemplate() -> int:
|
|
406
|
+
parser = argparse.ArgumentParser()
|
|
407
|
+
parser.add_argument('-f', '--folder', required=False)
|
|
408
|
+
parser.add_argument('-p', '--productname', required=False)
|
|
409
|
+
parser.add_argument('-s', '--subfolder', required=False)
|
|
410
|
+
args = parser.parse_args()
|
|
411
|
+
|
|
412
|
+
folder = args.folder
|
|
413
|
+
if folder is None:
|
|
414
|
+
folder = os.getcwd()
|
|
415
|
+
ScriptCollectionCore().generate_arc42_reference_template(folder, args.productname, args.subfolder)
|
|
416
|
+
return 0
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def CreateChangelogEntry() -> int:
|
|
420
|
+
parser = argparse.ArgumentParser()
|
|
421
|
+
parser.add_argument('-p', '--repositorypath', required=False, default=".")
|
|
422
|
+
parser.add_argument('-m', '--message', required=False, default="Updates.")
|
|
423
|
+
parser.add_argument('-c', '--commit', action='store_true', required=False, default=False)
|
|
424
|
+
parser.add_argument('-f', '--force', action='store_true', required=False, default=False)
|
|
425
|
+
args = parser.parse_args()
|
|
426
|
+
|
|
427
|
+
folder: str = None
|
|
428
|
+
if os.path.isabs(args.repositorypath):
|
|
429
|
+
folder = args.repositorypath
|
|
430
|
+
else:
|
|
431
|
+
folder = GeneralUtilities.resolve_relative_path(args.repositorypath, os.getcwd())
|
|
432
|
+
t=TFCPS_Tools_General(ScriptCollectionCore())
|
|
433
|
+
t.create_changelog_entry(folder, args.message, args.commit, args.force)
|
|
434
|
+
return 0
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def FileExists() -> int:
|
|
438
|
+
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.")
|
|
439
|
+
parser.add_argument('-p', '--path', required=True)
|
|
440
|
+
args = parser.parse_args()
|
|
441
|
+
if os.path.isfile(args.path):
|
|
442
|
+
return 0
|
|
443
|
+
else:
|
|
444
|
+
return 2
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def FolderExists() -> int:
|
|
448
|
+
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.")
|
|
449
|
+
parser.add_argument('-p', '--path', required=True)
|
|
450
|
+
args = parser.parse_args()
|
|
451
|
+
if os.path.isdir(args.path):
|
|
452
|
+
return 0
|
|
453
|
+
else:
|
|
454
|
+
return 2
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def PrintFileContent() -> int:
|
|
458
|
+
parser = argparse.ArgumentParser(description="This function prints the size of a file")
|
|
459
|
+
parser.add_argument('-p', '--path', required=True)
|
|
460
|
+
parser.add_argument('-e', '--encoding', required=False, default="utf-8")
|
|
461
|
+
args = parser.parse_args()
|
|
462
|
+
file = args.path
|
|
463
|
+
encoding = args.encoding
|
|
464
|
+
if os.path.isfile(file):
|
|
465
|
+
GeneralUtilities.write_message_to_stdout(GeneralUtilities.read_text_from_file(file, encoding))
|
|
466
|
+
return 0
|
|
467
|
+
else:
|
|
468
|
+
GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
|
|
469
|
+
return 1
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def CreateFile() -> int:
|
|
473
|
+
parser = argparse.ArgumentParser(description="This function creates an empty file.")
|
|
474
|
+
parser.add_argument('-p', '--path', required=True)
|
|
475
|
+
parser.add_argument('-e', '--errorwhenexists', action='store_true', required=False, default=False)
|
|
476
|
+
parser.add_argument('-c', '--createnecessaryfolder', action='store_true', required=False, default=False)
|
|
477
|
+
args = parser.parse_args()
|
|
478
|
+
sc = ScriptCollectionCore()
|
|
479
|
+
sc.create_file(args.path, args.errorwhenexists, args.createnecessaryfolder)
|
|
480
|
+
return 0
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def CreateFolder() -> int:
|
|
484
|
+
parser = argparse.ArgumentParser(description="This function creates an empty folder.")
|
|
485
|
+
parser.add_argument('-p', '--path', required=True)
|
|
486
|
+
parser.add_argument('-e', '--errorwhenexists', action='store_true', required=False, default=False)
|
|
487
|
+
parser.add_argument('-c', '--createnecessaryfolder', action='store_true', required=False, default=False)
|
|
488
|
+
args = parser.parse_args()
|
|
489
|
+
sc = ScriptCollectionCore()
|
|
490
|
+
sc.create_folder(args.path, args.errorwhenexists, args.createnecessaryfolder)
|
|
491
|
+
return 0
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def AppendLineToFile() -> int:
|
|
495
|
+
GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
|
|
496
|
+
# TODO implement function
|
|
497
|
+
# 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
|
|
498
|
+
# TODO add switch to enable/disable appending another new-line-character at the end of the file
|
|
499
|
+
return 1
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def RegexReplaceInFile() -> int:
|
|
503
|
+
GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
|
|
504
|
+
# TODO implement function
|
|
505
|
+
return 1
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def PrintFileSize() -> int:
|
|
509
|
+
parser = argparse.ArgumentParser(description="This function prints the size of a file")
|
|
510
|
+
parser.add_argument('-p', '--path', required=True)
|
|
511
|
+
args = parser.parse_args()
|
|
512
|
+
file = args.path
|
|
513
|
+
if os.path.isfile(file):
|
|
514
|
+
size = os.path.getsize(file)
|
|
515
|
+
GeneralUtilities.write_message_to_stdout(str(size))
|
|
516
|
+
return 0
|
|
517
|
+
else:
|
|
518
|
+
GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
|
|
519
|
+
return 1
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def FileContainsContent() -> int:
|
|
523
|
+
GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
|
|
524
|
+
# TODO implement function
|
|
525
|
+
# TODO add switch to set if the input pattern should be treated as regex
|
|
526
|
+
return 1
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def RemoveFile() -> int:
|
|
530
|
+
parser = argparse.ArgumentParser(description="This function removes a file.")
|
|
531
|
+
parser.add_argument('-p', '--path', required=True)
|
|
532
|
+
parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
|
|
533
|
+
args = parser.parse_args()
|
|
534
|
+
file = args.path
|
|
535
|
+
errorwhennotexists = args.errorwhennotexists
|
|
536
|
+
if os.path.isfile(file):
|
|
537
|
+
GeneralUtilities.ensure_file_does_not_exist(file)
|
|
538
|
+
else:
|
|
539
|
+
if errorwhennotexists:
|
|
540
|
+
GeneralUtilities.write_exception_to_stderr(f"File '{file}' does not exist.")
|
|
541
|
+
return 1
|
|
542
|
+
return 0
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def RemoveFolder() -> int:
|
|
546
|
+
parser = argparse.ArgumentParser(description="This function removes a folder.")
|
|
547
|
+
parser.add_argument('-p', '--path', required=True)
|
|
548
|
+
parser.add_argument('-e', '--errorwhennotexists', action='store_true', required=False, default=False)
|
|
549
|
+
args = parser.parse_args()
|
|
550
|
+
folder = args.path
|
|
551
|
+
errorwhennotexists = args.errorwhennotexists
|
|
552
|
+
if os.path.isdir(folder):
|
|
553
|
+
GeneralUtilities.ensure_directory_does_not_exist(folder)
|
|
554
|
+
else:
|
|
555
|
+
if errorwhennotexists:
|
|
556
|
+
GeneralUtilities.write_exception_to_stderr(f"Folder '{folder}' does not exist.")
|
|
557
|
+
return 1
|
|
558
|
+
return 0
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def Rename() -> int:
|
|
562
|
+
parser = argparse.ArgumentParser(description="This function renames a file or folder.")
|
|
563
|
+
parser.add_argument('-s', '--source', required=True)
|
|
564
|
+
parser.add_argument('-t', '--target', required=True)
|
|
565
|
+
args = parser.parse_args()
|
|
566
|
+
os.rename(args.source, args.target)
|
|
567
|
+
return 0
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def Copy() -> int:
|
|
571
|
+
parser = argparse.ArgumentParser(description="This function copies a file or folder.")
|
|
572
|
+
parser.add_argument('-s', '--source', required=True)
|
|
573
|
+
parser.add_argument('-t', '--target', required=True)
|
|
574
|
+
args = parser.parse_args()
|
|
575
|
+
|
|
576
|
+
if os.path.isfile(args.target) or os.path.isdir(args.target):
|
|
577
|
+
raise ValueError(f"Can not copy to '{args.target}' because the target already exists.")
|
|
578
|
+
|
|
579
|
+
source = args.source
|
|
580
|
+
if not os.path.isabs(source):
|
|
581
|
+
source = GeneralUtilities.resolve_relative_path(source, os.getcwd())
|
|
582
|
+
target = args.target
|
|
583
|
+
if not os.path.isabs(target):
|
|
584
|
+
target = GeneralUtilities.resolve_relative_path(target, os.getcwd())
|
|
585
|
+
|
|
586
|
+
if os.path.isfile(source):
|
|
587
|
+
shutil.copyfile(source, target)
|
|
588
|
+
elif os.path.isdir(source):
|
|
589
|
+
GeneralUtilities.ensure_directory_exists(target)
|
|
590
|
+
GeneralUtilities.copy_content_of_folder(source, target)
|
|
591
|
+
else:
|
|
592
|
+
raise ValueError(f"'{source}' can not be copied because the path does not exist.")
|
|
593
|
+
return 0
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def PrintOSName() -> int:
|
|
597
|
+
if GeneralUtilities.current_system_is_windows():
|
|
598
|
+
GeneralUtilities.write_message_to_stdout("Windows")
|
|
599
|
+
elif GeneralUtilities.current_system_is_linux():
|
|
600
|
+
GeneralUtilities.write_message_to_stdout("Linux")
|
|
601
|
+
# TODO consider Mac, Unix, etc. too
|
|
602
|
+
else:
|
|
603
|
+
GeneralUtilities.write_message_to_stderr("Unknown OS.")
|
|
604
|
+
return 1
|
|
605
|
+
return 0
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def PrintCurrecntWorkingDirectory() -> int:
|
|
609
|
+
GeneralUtilities.write_message_to_stdout(os.getcwd())
|
|
610
|
+
return 0
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def ListFolderContent() -> int:
|
|
614
|
+
parser = argparse.ArgumentParser(description="This function lists folder-content.")
|
|
615
|
+
parser.add_argument('-p', '--path', required=True)
|
|
616
|
+
parser.add_argument('-f', '--excludefiles', action='store_true', required=False, default=False)
|
|
617
|
+
parser.add_argument('-d', '--excludedirectories', action='store_true', required=False, default=False)
|
|
618
|
+
parser.add_argument('-n', '--printonlynamewithoutpath', action='store_true', required=False, default=False)
|
|
619
|
+
# TODO add option to also list transitively list subfolder
|
|
620
|
+
# TODO add option to show only content which matches a filter by extension or regex or glob-pattern
|
|
621
|
+
args = parser.parse_args()
|
|
622
|
+
folder = args.path
|
|
623
|
+
if not os.path.isabs(folder):
|
|
624
|
+
folder = GeneralUtilities.resolve_relative_path(folder, os.getcwd())
|
|
625
|
+
content = []
|
|
626
|
+
if not args.excludefiles:
|
|
627
|
+
content = content+GeneralUtilities.get_direct_files_of_folder(folder)
|
|
628
|
+
if not args.excludedirectories:
|
|
629
|
+
content = content+GeneralUtilities.get_direct_folders_of_folder(folder)
|
|
630
|
+
for contentitem in content:
|
|
631
|
+
content_to_print: str = None
|
|
632
|
+
if args.printonlynamewithoutpath:
|
|
633
|
+
content_to_print = os.path.basename(contentitem)
|
|
634
|
+
else:
|
|
635
|
+
content_to_print = contentitem
|
|
636
|
+
GeneralUtilities.write_message_to_stdout(content_to_print)
|
|
637
|
+
return 0
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
def ForEach() -> int:
|
|
641
|
+
GeneralUtilities.write_message_to_stderr("This function is not implemented yet.")
|
|
642
|
+
# TODO implement function
|
|
643
|
+
return 1
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def NpmI() -> int:
|
|
647
|
+
parser = argparse.ArgumentParser(description="Does \"npm clean install\".")
|
|
648
|
+
parser.add_argument('-d', '--directory', required=False, default=".")
|
|
649
|
+
parser.add_argument('-f', '--force', action='store_true', required=False, default=False)
|
|
650
|
+
parser.add_argument('-v', '--verbose', action='store_true', required=False, default=False)
|
|
651
|
+
parser.add_argument('-c', '--nocache', action='store_true', required=False, default=False)
|
|
652
|
+
args = parser.parse_args()
|
|
653
|
+
if os.path.isabs(args.directory):
|
|
654
|
+
folder = args.directory
|
|
655
|
+
else:
|
|
656
|
+
folder = GeneralUtilities.resolve_relative_path(args.directory, os.getcwd())
|
|
657
|
+
t = TFCPS_Tools_General(ScriptCollectionCore())
|
|
658
|
+
t.do_npm_install(folder, args.force,not args.nocache)
|
|
659
|
+
return 0
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
def CurrentUserHasElevatedPrivileges() -> int:
|
|
663
|
+
parser = argparse.ArgumentParser(description="Returns 1 if the current user has elevated privileges. Otherwise this function returns 0.")
|
|
664
|
+
parser.parse_args()
|
|
665
|
+
if GeneralUtilities.current_user_has_elevated_privileges():
|
|
666
|
+
return 1
|
|
667
|
+
else:
|
|
668
|
+
return 0
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def Espoc() -> int:
|
|
672
|
+
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.")
|
|
673
|
+
parser.add_argument('-p', '--processid', required=True)
|
|
674
|
+
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.')
|
|
675
|
+
args = parser.parse_args()
|
|
676
|
+
process_id = int(args.processid)
|
|
677
|
+
process_list_file: str = args.file
|
|
678
|
+
if not os.path.isabs(process_list_file):
|
|
679
|
+
process_list_file = GeneralUtilities.resolve_relative_path(process_list_file, os.getcwd())
|
|
680
|
+
GeneralUtilities.assert_condition(GeneralUtilities.process_is_running_by_id(process_id), f"Process with id {process_id} is not running.")
|
|
681
|
+
while GeneralUtilities.process_is_running_by_id(process_id):
|
|
682
|
+
time.sleep(1)
|
|
683
|
+
GeneralUtilities.write_message_to_stdout(f"Process with id {process_id} is not running anymore. Start terminating remaining processes.")
|
|
684
|
+
if os.path.exists(process_list_file):
|
|
685
|
+
for line in GeneralUtilities.read_lines_from_file(process_list_file):
|
|
686
|
+
if GeneralUtilities.string_has_content(line):
|
|
687
|
+
current_process_id = int(line.strip())
|
|
688
|
+
GeneralUtilities.kill_process(current_process_id, True)
|
|
689
|
+
GeneralUtilities.ensure_file_does_not_exist(process_list_file)
|
|
690
|
+
GeneralUtilities.write_message_to_stdout("All started processes terminated.")
|
|
691
|
+
else:
|
|
692
|
+
GeneralUtilities.write_message_to_stdout(f"File '{process_list_file}' does not exist. No processes to terminate.")
|
|
693
|
+
return 0
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def ConvertGitRepositoryToBareRepository() -> int:
|
|
697
|
+
parser = argparse.ArgumentParser(description="Converts a local git-repository to a bare repository.")
|
|
698
|
+
parser.add_argument('-f', '--folder', required=True, help='Git-repository-folder which should be converted.')
|
|
699
|
+
args = parser.parse_args()
|
|
700
|
+
sc = ScriptCollectionCore()
|
|
701
|
+
sc.convert_git_repository_to_bare_repository(args.folder)
|
|
702
|
+
return 0
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def OCRAnalysisOfFolder() -> int:
|
|
706
|
+
parser = argparse.ArgumentParser()
|
|
707
|
+
parser.add_argument('-s', '--serviceaddress', required=False, default=None)
|
|
708
|
+
parser.add_argument('-e', '--extensions', required=False, default=None)
|
|
709
|
+
parser.add_argument('-l', '--languages', required=False, default="en")
|
|
710
|
+
parser.add_argument('-f', '--folder', required=False, default=None)
|
|
711
|
+
args = parser.parse_args()
|
|
712
|
+
sc = ScriptCollectionCore()
|
|
713
|
+
if args.folder is None:
|
|
714
|
+
args.folder = os.getcwd()
|
|
715
|
+
extensions_value: str = None
|
|
716
|
+
if args.extensions is not None:
|
|
717
|
+
if "," in args.extensions:
|
|
718
|
+
extensions_value = args.extensions.split(",")
|
|
719
|
+
else:
|
|
720
|
+
extensions_value = [args.extensions]
|
|
721
|
+
sc.ocr_analysis_of_folder(args.folder, args.serviceaddress, extensions_value, args.languages)
|
|
722
|
+
return 0
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def OCRAnalysisOfFile() -> int:
|
|
726
|
+
parser = argparse.ArgumentParser()
|
|
727
|
+
parser.add_argument('-s', '--serviceaddress', required=False, default=None)
|
|
728
|
+
parser.add_argument('-l', '--languages', required=False, default="en")
|
|
729
|
+
parser.add_argument('-f', '--file', required=True)
|
|
730
|
+
args = parser.parse_args()
|
|
731
|
+
sc = ScriptCollectionCore()
|
|
732
|
+
sc.ocr_analysis_of_file(args.file, args.serviceaddress, args.languages)
|
|
733
|
+
return 0
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
def OCRAnalysisOfRepository() -> int:
|
|
737
|
+
parser = argparse.ArgumentParser()
|
|
738
|
+
parser.add_argument('-s', '--serviceaddress', required=False, default=None)
|
|
739
|
+
parser.add_argument('-e', '--extensions', required=False, default=None)
|
|
740
|
+
parser.add_argument('-l', '--languages', required=False, default="en")
|
|
741
|
+
parser.add_argument('-f', '--folder', required=False, default=None)
|
|
742
|
+
args = parser.parse_args()
|
|
743
|
+
sc = ScriptCollectionCore()
|
|
744
|
+
if args.folder is None:
|
|
745
|
+
args.folder = os.getcwd()
|
|
746
|
+
extensions_value: str = None
|
|
747
|
+
if args.extensions is not None:
|
|
748
|
+
if "," in args.extensions:
|
|
749
|
+
extensions_value = args.extensions.split(",")
|
|
750
|
+
else:
|
|
751
|
+
extensions_value = [args.extensions]
|
|
752
|
+
sc.ocr_analysis_of_repository(args.folder, args.serviceaddress, extensions_value, args.languages)
|
|
753
|
+
return 0
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
def UpdateImagesInDockerComposeFile() -> int:
|
|
757
|
+
iu: ImageUpdater = ImageUpdater()
|
|
758
|
+
parser = argparse.ArgumentParser()
|
|
759
|
+
parser.add_argument('-f', '--file', required=False, default=None)
|
|
760
|
+
parser.add_argument('-v', '--versionecholon', required=False, default=VersionEcholon.LatestVersion.name, dest="Possible values are: " + ", ".join([e.name for e in VersionEcholon]))
|
|
761
|
+
parser.add_argument("-s", "--servicename", required=True, default=None)
|
|
762
|
+
parser.add_argument("-u", "--updatertype", required=True, default=None)
|
|
763
|
+
args = parser.parse_args()
|
|
764
|
+
if args.file is None:
|
|
765
|
+
args.file = os.path.join(os.getcwd(), "docker-compose.yml")
|
|
766
|
+
versionecholonTyped = VersionEcholon[args.versionecholon]
|
|
767
|
+
iu.update_services_in_docker_compose_file(args.file, [args.servicename], versionecholonTyped, args.updatertype)
|
|
768
|
+
return 0
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
def SetFileContent() -> int:
|
|
772
|
+
parser = argparse.ArgumentParser(description="This function writes content into a file.")
|
|
773
|
+
parser.add_argument('-p', '--path', required=True)
|
|
774
|
+
parser.add_argument('-b', '--argumentisinbase64', action='store_true', required=False, default=False)
|
|
775
|
+
parser.add_argument('-c', '--content', required=True)
|
|
776
|
+
parser.add_argument('-e', '--encoding', required=False, default="utf-8")
|
|
777
|
+
args = parser.parse_args()
|
|
778
|
+
sc = ScriptCollectionCore()
|
|
779
|
+
content = args.content
|
|
780
|
+
if args.argumentisinbase64:
|
|
781
|
+
base64_string: str = args.content
|
|
782
|
+
base64_bytes = base64_string.encode('utf-8')
|
|
783
|
+
original_bytes = base64.b64decode(base64_bytes)
|
|
784
|
+
content = original_bytes.decode('utf-8')
|
|
785
|
+
sc.set_file_content(args.path, content, args.encoding)
|
|
786
|
+
return 0
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def GenerateTaskfileFromWorkspacefile() -> int:
|
|
790
|
+
parser = argparse.ArgumentParser(description="Generates a taskfile.yml-file from a .code-workspace-file")
|
|
791
|
+
parser.add_argument('-f', '--repositoryfolder', required=True)
|
|
792
|
+
#args = parser.parse_args()
|
|
793
|
+
#t = TasksForCommonProjectStructure()
|
|
794
|
+
#t.generate_tasksfile_from_workspace_file(args.repositoryfolder)
|
|
795
|
+
#return 0
|
|
796
|
+
return 1#TODO
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
def UpdateTimestampInFile() -> int:
|
|
800
|
+
parser = argparse.ArgumentParser(description="Update the timestamp in a comment in a file")
|
|
801
|
+
parser.add_argument('-f', '--file', required=True)
|
|
802
|
+
args = parser.parse_args()
|
|
803
|
+
sc = ScriptCollectionCore()
|
|
804
|
+
sc.update_timestamp_in_file(args.file)
|
|
805
|
+
return 0
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def LOC() -> int:
|
|
809
|
+
sc = ScriptCollectionCore()
|
|
810
|
+
default_patterns: list[str] = sc.default_excluded_patterns_for_loc
|
|
811
|
+
default_patterns_joined = ",".join(default_patterns)
|
|
812
|
+
parser = argparse.ArgumentParser(description=f"Counts the lines of code in a git-repository. Default patterns are: {default_patterns_joined}")
|
|
813
|
+
parser.add_argument('-r', '--repository', required=True)
|
|
814
|
+
parser.add_argument('-e', '--excluded_pattern', nargs='+')
|
|
815
|
+
parser.add_argument('-d', '--do_not_add_default_pattern', action='store_true', default=False)
|
|
816
|
+
parser.add_argument('-v', '--verbose', action='store_true', default=False)
|
|
817
|
+
args = parser.parse_args()
|
|
818
|
+
|
|
819
|
+
folder: str = None
|
|
820
|
+
if os.path.isabs(args.repository):
|
|
821
|
+
folder = args.repository
|
|
822
|
+
else:
|
|
823
|
+
folder = GeneralUtilities.resolve_relative_path(args.repository, os.getcwd())
|
|
824
|
+
excluded_patterns: list[str] = []
|
|
825
|
+
|
|
826
|
+
if not args.do_not_add_default_pattern:
|
|
827
|
+
excluded_patterns = excluded_patterns + sc.default_excluded_patterns_for_loc
|
|
828
|
+
if args.excluded_pattern is not None:
|
|
829
|
+
excluded_patterns = excluded_patterns + args.excluded_pattern
|
|
830
|
+
|
|
831
|
+
if args.verbose:
|
|
832
|
+
sc.log.loglevel=LogLevel.Debug
|
|
833
|
+
else:
|
|
834
|
+
sc.log.loglevel=LogLevel.Information
|
|
835
|
+
|
|
836
|
+
GeneralUtilities.write_message_to_stdout(str(sc.get_lines_of_code(folder, excluded_patterns)))
|
|
837
|
+
return 0
|
|
838
|
+
|
|
839
|
+
def CreateRelease()->int:
|
|
840
|
+
sc = ScriptCollectionCore()
|
|
841
|
+
parser = argparse.ArgumentParser(description="Creates a release in a git-repository which uses the anion-build-platform.")
|
|
842
|
+
parser.add_argument('-b', '--buildrepository', required=False, default=".")
|
|
843
|
+
verbosity_values = ", ".join(f"{lvl.value}={lvl.name}" for lvl in LogLevel)
|
|
844
|
+
parser.add_argument('-v', '--verbosity', required=False, default=3, help=f"Sets the loglevel. Possible values: {verbosity_values}")
|
|
845
|
+
parser.add_argument('-s', '--sourcebranch', required=False, default="other/next-release")
|
|
846
|
+
parser.add_argument('-u', '--updatedependencies', required=False, action='store_true', default=False)
|
|
847
|
+
args = parser.parse_args()
|
|
848
|
+
|
|
849
|
+
build_repo_folder: str = None
|
|
850
|
+
if os.path.isabs(args.buildrepository):
|
|
851
|
+
build_repo_folder = args.buildrepository
|
|
852
|
+
else:
|
|
853
|
+
build_repo_folder = GeneralUtilities.resolve_relative_path(args.buildrepository, os.getcwd())
|
|
854
|
+
|
|
855
|
+
verbosity=int(args.verbosity)
|
|
856
|
+
sc.log.loglevel=LogLevel(verbosity)
|
|
857
|
+
|
|
858
|
+
scripts_folder:str=os.path.join(build_repo_folder,"Scripts","CreateRelease")
|
|
859
|
+
arguments=f"CreateRelease.py --buildrepositoriesfolder {build_repo_folder} --verbosity {verbosity} --sourcebranch {args.sourcebranch}"
|
|
860
|
+
if args.updatedependencies:
|
|
861
|
+
arguments=arguments+" --updatedependencies"
|
|
862
|
+
sc.run_program("python", arguments, scripts_folder,print_live_output=True)
|
|
863
|
+
|
|
864
|
+
return 0
|
|
865
|
+
|
|
866
|
+
def CleanToolsCache()->int:
|
|
867
|
+
GeneralUtilities.ensure_folder_exists_and_is_empty(TFCPS_Tools_General(ScriptCollectionCore()).get_global_cache_folder())
|
|
868
|
+
return 0
|