ScriptCollection 4.2.56__py3-none-any.whl → 4.2.58__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ import json
3
3
  import binascii
4
4
  import filecmp
5
5
  import hashlib
6
- import logging
7
6
  import multiprocessing
8
7
  import time
9
8
  from io import BytesIO
@@ -37,7 +36,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
37
36
  from .ProgramRunnerPopen import ProgramRunnerPopen
38
37
  from .SCLog import SCLog, LogLevel
39
38
 
40
- version = "4.2.56"
39
+ version = "4.2.58"
41
40
  __version__ = version
42
41
 
43
42
  class VSCodeWorkspaceShellTask:
@@ -2880,7 +2879,7 @@ OCR-content:
2880
2879
  lines=program_result[1].split("\n")[1:]
2881
2880
  for line in lines:
2882
2881
  splitted=[item for item in line.split(' ') if GeneralUtilities.string_has_content(item)]
2883
- result.append(splitted[1])
2882
+ result.append(splitted[1].replace("\n","").replace("\r","").strip())
2884
2883
  return result
2885
2884
 
2886
2885
  @GeneralUtilities.check_arguments
@@ -3124,6 +3123,7 @@ OCR-content:
3124
3123
  #sync existing files
3125
3124
  self.__sync_xlf2_files(base_file_xml, language_files_with_content)
3126
3125
 
3126
+
3127
3127
  @GeneralUtilities.check_arguments
3128
3128
  def translate_xlf_files_in_folder(self, folder: str, base_language: str, libre_translate_api_server: str):
3129
3129
  """Translates all .xlf files directly in the given folder (non-recursive)."""
@@ -3185,7 +3185,7 @@ OCR-content:
3185
3185
  "target": target_language,
3186
3186
  "format": "text"
3187
3187
  }
3188
- response = requests.post(url, json=payload)
3188
+ response = requests.post(url, json=payload, timeout=30)
3189
3189
  response.raise_for_status()
3190
3190
  return response.json()["translatedText"]
3191
3191
 
@@ -3194,9 +3194,28 @@ OCR-content:
3194
3194
  """Detects the language of the given text using the LibreTranslate API."""
3195
3195
  url = f"{libre_translate_api_server.rstrip('/')}/detect"
3196
3196
  payload = {"q": content}
3197
- response = requests.post(url, json=payload)
3197
+ response = requests.post(url, json=payload, timeout=30)
3198
3198
  response.raise_for_status()
3199
3199
  results = response.json()
3200
3200
  if not results:
3201
3201
  raise ValueError("Language detection returned no results.")
3202
3202
  return results[0]["language"]
3203
+
3204
+ @GeneralUtilities.check_arguments
3205
+ def get_all_files_in_git_repository(self,repository_folder:str,include_submodules: bool = True) -> list[str]:
3206
+ """returns all files in a git-repository except ignored files"""
3207
+ cmd = ["ls-files", "--cached", "--exclude-standard"]
3208
+ if include_submodules:
3209
+ cmd.append("--recurse-submodules")
3210
+ output=self.run_program_argsasarray("git", cmd,repository_folder)
3211
+ files = [ GeneralUtilities.normalize_path("./" + line) for line in output[1].splitlines()if line.strip() ]
3212
+ return files
3213
+
3214
+ @GeneralUtilities.check_arguments
3215
+ def write_file_list_for_repository(self,repository_folder:str,target_file:str="./FileList.txt") -> None:
3216
+ if os.path.isabs(target_file):
3217
+ target_file=GeneralUtilities.resolve_relative_path(target_file,repository_folder)
3218
+ target_file=GeneralUtilities.normalize_path(target_file)
3219
+ files=self.get_all_files_in_git_repository(repository_folder)
3220
+ GeneralUtilities.ensure_file_exists(target_file)
3221
+ GeneralUtilities.write_lines_to_file(target_file, files)
@@ -157,7 +157,7 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
157
157
  @GeneralUtilities.check_arguments
158
158
  def get_available_cultures_for_angular_app(self)->None:
159
159
  return self._protected_sc.get_available_cultures_for_angular_app(self.get_codeunit_folder()+"/angular.json")
160
-
160
+
161
161
  @GeneralUtilities.check_arguments
162
162
  def __ensure_translations_exist(self,languages:list[str])->None:
163
163
  base_file=os.path.join(self.get_codeunit_folder(),"Other","Resources","Translations",f"messages.xlf")
@@ -166,7 +166,6 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
166
166
  if not os.path.isfile(target_file):
167
167
  GeneralUtilities.ensure_file_exists(target_file)
168
168
  GeneralUtilities.write_text_to_file(target_file, GeneralUtilities.read_text_from_file(base_file))
169
-
170
169
  #set new attribute
171
170
  tree = ET.parse(target_file)
172
171
  root = tree.getroot()
@@ -192,17 +191,27 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
192
191
 
193
192
  @GeneralUtilities.check_arguments
194
193
  def organize_translations(self,languages:list[str])->None:
195
- self.__ensure_translations_exist(languages)
196
194
  self._protected_sc.run_with_epew("npm","run extract-translations",self.get_codeunit_folder())
195
+ self.__ensure_translations_exist(languages)
197
196
  self._protected_sc.sync_xlf2_files("messages",languages,os.path.join(self.get_codeunit_folder(),"Other","Resources","Translations"))
198
197
 
199
198
  @GeneralUtilities.check_arguments
200
- def translate_safe(self)->None:
201
- pass#TODO if ~/.ScriptCollection/TranslationService.txt exists: use this and call translate(...)
202
-
199
+ def translate_safe(self,base_language:str="en")->None:
200
+ """Translates XLF files if a translation service is configured. The translation service can be configured by creating a file at ~/.ScriptCollection/TranslationServiceProperties.txt with the content 'LibreTranslateAPI=your_api_server_url'."""
201
+ translationservice_file:str=self._protected_sc.get_global_cache_folder()+"/TranslationServiceProperties.txt"
202
+ api_server:str=None
203
+ if os.path.isfile(translationservice_file):
204
+ lines=GeneralUtilities.read_nonempty_lines_from_file(translationservice_file)
205
+ for line in lines:
206
+ if line.startswith("LibreTranslateAPI="):
207
+ api_server=line.replace("LibreTranslateAPI=","").strip()
208
+ GeneralUtilities.assert_not_null(api_server,"No translation service configured. Please create a file at ~/.ScriptCollection/TranslationServiceProperties.txt with the content 'LibreTranslateAPI=your_api_server_url' to enable automatic translation of XLF files.")
209
+ self.translate(api_server,base_language)
210
+
203
211
  @GeneralUtilities.check_arguments
204
- def translate(self,api_server:str)->None:
205
- pass#TODO if Other/Resources/Translations exists: call sc.translate_messages_in_folder(...)
212
+ def translate(self,api_server:str,base_language:str="en")->None:
213
+ folder:str=os.path.join(self.get_codeunit_folder(),"Other","Resources","Translations")
214
+ self._protected_sc.translate_xlf_files_in_folder(folder, base_language, api_server)
206
215
 
207
216
  class TFCPS_CodeUnitSpecific_NodeJS_CLI:
208
217
 
@@ -726,7 +726,7 @@ class TFCPS_Tools_General:
726
726
  if generate_certificate:
727
727
  self.__sc.generate_certificate_authority(ca_folder, ca_name, "DE", "SubjST", "SubjL", "SubjO", "SubjOU")
728
728
  # TODO add switch to auto-install the script if desired
729
- # for windows: powershell Import-Certificate -FilePath ConSurvCA_20241121000236.crt -CertStoreLocation 'Cert:\CurrentUser\Root'
729
+ # for windows: powershell Import-Certificate -FilePath MyProjectCA_20241121000236.crt -CertStoreLocation 'Cert:\CurrentUser\Root'
730
730
  # for linux: (TODO)
731
731
 
732
732
  @GeneralUtilities.check_arguments
@@ -1433,7 +1433,7 @@ class TFCPS_Tools_General:
1433
1433
  def download_file(self,source:str,target:str):
1434
1434
  GeneralUtilities.ensure_directory_exists(os.path.dirname(target))
1435
1435
  GeneralUtilities.ensure_file_exists(target)
1436
- response = requests.get(source)
1436
+ response = requests.get(source, timeout=30)
1437
1437
  response.raise_for_status()
1438
1438
  with open(target, "wb") as f:
1439
1439
  f.write(response.content)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ScriptCollection
3
- Version: 4.2.56
3
+ Version: 4.2.58
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Home-page: https://github.com/anionDev/ScriptCollection
6
6
  Author: Marius Göcke
@@ -33,7 +33,7 @@ Requires-Dist: ntplib>=0.4.0
33
33
  Requires-Dist: Pillow>=11.3.0
34
34
  Requires-Dist: psutil>=7.2.2
35
35
  Requires-Dist: pycdlib>=1.14.0
36
- Requires-Dist: Pygments>=2.19.2
36
+ Requires-Dist: Pygments>=2.20.0
37
37
  Requires-Dist: pylint>=4.0.5
38
38
  Requires-Dist: pyOpenSSL>=25.3.0
39
39
  Requires-Dist: PyPDF>=6.9.2
@@ -9,7 +9,7 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
9
9
  ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=_khC3xuTdrPoLluBJZWfldltmmuKltABJPcbjZSFW-4,4835
11
11
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
12
- ScriptCollection/ScriptCollectionCore.py,sha256=YE4yV9Vxy3RrC_Fpr0QC3tyI_OYiBAOxwZqsmGXMxU8,173731
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=c-wSuEa8_T_-GC-iE3fNO7Yr7gB92b4R1zAwQN2-QSM,174896
13
13
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=83qDMILwxhH9DbC0sb358Vu8PXEysmJJyap_6gECZqs,1627
15
15
  ScriptCollection/OCIImages/OCIImageManager.py,sha256=aBogkSXNDyi8NO11N-s03nuFJEv7PyJ-wjHuYYeZfvs,6662
@@ -30,7 +30,7 @@ ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=O-0guM_LJCcZmPZJhMgTvXD2RXUJEBWWv
30
30
  ScriptCollection/TFCPS/TFCPS_MergeToMain.py,sha256=-Ev9D3bZDlUk2WFQhcmvzQ3FCS97OdsVUd0koAdmpZc,7474
31
31
  ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=Ajfy2pLajTuU6UpwItHt4C2a-gLF3gPc4z6BktL3Cio,22163
32
32
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=f0Uq1cA_4LvmL72cal0crrbKF6PcxL13D9wBKuQ1YBw,2328
33
- ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=s4DPntMzNe-hEEYeR_PAtzxb2eJM0Fp4LhK5rV_NVuE,93928
33
+ ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=WV67pHLrhD_qEjUqM-8tUpEdhQ4brwVentfIf7AMOP4,93942
34
34
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=BPJkoy2KVgB_38cAk5qjM4s4FpJvOkTp467nrvANIIU,10606
36
36
  ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -43,12 +43,12 @@ ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=U8oBAOLR
43
43
  ScriptCollection/TFCPS/Flutter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
44
  ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py,sha256=kyx26AnT1-LySFA46wfJ9yZUKYdMWTD0U2XZfSQbuB0,3497
45
45
  ScriptCollection/TFCPS/Go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=BBWrFaAUVdmjl8qPq231aYlAENnjF1BOWXQQmOrQdxE,11816
46
+ ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=kL37qJNwH6E-CAJqcHbdnc0K0uGjHQ8XD1RXZOdcw1M,12850
47
47
  ScriptCollection/TFCPS/NodeJS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=nLw_eSUd_56jjgfcAvtUyzecSZ14mYmNJl0iu-1YNVk,13496
49
49
  ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
- scriptcollection-4.2.56.dist-info/METADATA,sha256=Zmiu4fHdrglsMZrShG8yxyKzwqsi5RqKsW4EXESthCw,7690
51
- scriptcollection-4.2.56.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
52
- scriptcollection-4.2.56.dist-info/entry_points.txt,sha256=27XwAJEcaMEc1be0Ec1vKHCbiU4Ziu8jKL-SqsrYOIQ,4680
53
- scriptcollection-4.2.56.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
54
- scriptcollection-4.2.56.dist-info/RECORD,,
50
+ scriptcollection-4.2.58.dist-info/METADATA,sha256=Lm4CyXwLiuq4Qr6srolxs5gr6CRuojWuzOeD9x0qonY,7690
51
+ scriptcollection-4.2.58.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
52
+ scriptcollection-4.2.58.dist-info/entry_points.txt,sha256=27XwAJEcaMEc1be0Ec1vKHCbiU4Ziu8jKL-SqsrYOIQ,4680
53
+ scriptcollection-4.2.58.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
54
+ scriptcollection-4.2.58.dist-info/RECORD,,