osbot-utils 1.26.0__py3-none-any.whl → 1.27.0__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.
@@ -4,7 +4,7 @@ from osbot_utils.utils.Misc import random_string
4
4
 
5
5
  from osbot_utils.utils.Files import path_combine, temp_folder_current, safe_file_name, folder_exists, folder_create, \
6
6
  folder_delete_recursively, files_list, file_create, folder_files, folders_recursive, files_find, files_recursive, \
7
- temp_file_in_folder, create_folder, filter_parent_folder
7
+ temp_file_in_folder, create_folder, filter_parent_folder, file_contents
8
8
  from osbot_utils.utils.Zip import zip_folder
9
9
 
10
10
 
@@ -92,6 +92,10 @@ class Temp_Folder:
92
92
  def path(self):
93
93
  return self.full_path
94
94
 
95
+ def file_contents(self, target_file):
96
+ file_path = path_combine(self.full_path, target_file)
97
+ return file_contents(file_path)
98
+
95
99
  def files(self, show_parent_folder=False, include_folders=False):
96
100
  all_files = files_recursive(self.path(), include_folders=include_folders)
97
101
  if show_parent_folder:
@@ -1,5 +1,6 @@
1
1
  from osbot_utils.testing.Temp_Folder import Temp_Folder
2
- from osbot_utils.utils.Files import Files, is_folder, file_exists, file_name
2
+ from osbot_utils.utils.Files import Files, is_folder, file_exists, file_name, file_move_to_folder, file_move, \
3
+ file_move_to
3
4
  from osbot_utils.utils.Zip import zip_folder, zip_file_list
4
5
 
5
6
 
@@ -42,4 +43,7 @@ class Temp_Zip():
42
43
  return self
43
44
 
44
45
  def zip_file_exists(self):
45
- return file_exists(self.zip_file)
46
+ return file_exists(self.zip_file)
47
+
48
+ def move_to(self, target_file):
49
+ file_move_to(self.zip_file, target_file)
@@ -8,6 +8,8 @@ import shutil
8
8
  import tempfile
9
9
  from os.path import abspath, join
10
10
  from pathlib import Path, PosixPath
11
+ from typing import Union
12
+
11
13
  from osbot_utils.utils.Misc import bytes_to_base64, base64_to_bytes, random_string
12
14
 
13
15
 
@@ -306,13 +308,24 @@ class Files:
306
308
  return Files.open(path, mode='rb')
307
309
 
308
310
  @staticmethod
309
- def path_combine(path1, path2):
310
- if type(path1) in [str, Path] and type(path2) in [str, Path]:
311
- parent_path = str(path1)
312
- sub_path = str(path2)
313
- if sub_path.startswith('/'):
314
- sub_path = sub_path[1:]
315
- return abspath(join(parent_path,sub_path))
311
+ # def path_combine(path1, path2):
312
+ # if type(path1) in [str, Path] and type(path2) in [str, Path]:
313
+ # parent_path = str(path1)
314
+ # sub_path = str(path2)
315
+ # if sub_path.startswith('/'):
316
+ # sub_path = sub_path[1:]
317
+ # return abspath(join(parent_path,sub_path))
318
+
319
+ def path_combine(path1: Union[str, os.PathLike], path2: Union[str, os.PathLike]) -> str:
320
+ if path1 is None or path2 is None:
321
+ raise ValueError("Both paths must be provided")
322
+
323
+ parent_path = str(path1)
324
+ sub_path = str(path2)
325
+
326
+ sub_path = sub_path.lstrip('/') # Remove leading slashes from sub_path
327
+
328
+ return abspath(join(parent_path, sub_path))
316
329
 
317
330
  @staticmethod
318
331
  def parent_folder(path, use_full_path=False):
@@ -451,8 +464,8 @@ def all_parent_folders(path=None, include_path=False):
451
464
  if path and path not in parent_directories: # to handle the root path case
452
465
  parent_directories.append(path)
453
466
  break
454
-
455
467
  return parent_directories
468
+
456
469
  def file_move(source_file, target_file):
457
470
  if file_exists(source_file):
458
471
  file_copy(source_file, target_file)
@@ -461,6 +474,14 @@ def file_move(source_file, target_file):
461
474
  return True
462
475
  return False
463
476
 
477
+ def file_move_to_folder(source_file, target_folder):
478
+ if file_exists(source_file):
479
+ if folder_exists(target_folder):
480
+ target_file = path_combine(target_folder, file_name(source_file))
481
+ if file_move(source_file, target_file):
482
+ return target_file
483
+
484
+
464
485
  def folders_names_in_folder(target):
465
486
  folders = folders_in_folder(target)
466
487
  return folders_names(folders)
@@ -506,6 +527,7 @@ file_full_path = absolute_path
506
527
  file_lines = Files.lines
507
528
  file_lines_gz = Files.lines_gz
508
529
  file_md5 = Files.contents_md5
530
+ file_move_to = file_move
509
531
  file_name = Files.file_name
510
532
  file_name_without_extension = Files.file_name_without_extension
511
533
  file_not_exists = Files.not_exists
osbot_utils/utils/Zip.py CHANGED
@@ -136,5 +136,6 @@ def zip_files(base_folder, file_pattern="*.*", target_file=None):
136
136
 
137
137
 
138
138
  # extra function's mappings
139
- file_unzip = unzip_file
140
- folder_zip = zip_folder
139
+ file_unzip = unzip_file
140
+ folder_zip = zip_folder
141
+ zip_bytes_unzip_to_folder = zip_bytes_extract_to_folder
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.26.0
1
+ v1.27.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.26.0
3
+ Version: 1.27.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  Home-page: https://github.com/owasp-sbot/OSBot-Utils
6
6
  License: MIT
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  Powerful Python util methods and classes that simplify common apis and tasks.
24
24
 
25
- ![Current Release](https://img.shields.io/badge/release-v1.26.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.27.0-blue)
26
26
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
27
27
 
28
28
 
@@ -251,10 +251,10 @@ osbot_utils/testing/Stderr.py,sha256=wi1gfjpsxnBK3aOl2jzCTWI-0En1HtPgEin97148_MQ
251
251
  osbot_utils/testing/Stdout.py,sha256=XQ9OlOW1aHXY1TiNu8O5b75RoDnoaX5RyMHml3OjlKw,459
252
252
  osbot_utils/testing/Temp_Env_Vars.py,sha256=oFuaegBlaV0aySkPe1Nzf-mdIKN03oTUKNfKijGz__M,751
253
253
  osbot_utils/testing/Temp_File.py,sha256=yZBL9MmcNU4PCQ4xlF4rSss4GylKoX3T_AJF-BlQhdI,1693
254
- osbot_utils/testing/Temp_Folder.py,sha256=wZQhCi5Cy0dQQAXuu3_jArDz5T94Q_JX68GENU6nTMo,4793
254
+ osbot_utils/testing/Temp_Folder.py,sha256=gewV0L3B4ScKyorkVOQaQ-vz4DbeVRnqxCMS9A0eVLo,4953
255
255
  osbot_utils/testing/Temp_Sys_Path.py,sha256=gOMD-7dQYQlejoDYUqsrmuZQ9DLC07ymPZB3zYuNmG4,256
256
256
  osbot_utils/testing/Temp_Web_Server.py,sha256=0A-gZsd0_3wRj2YuBEOWyV2rhT6dcS2BlArngPXGTtk,3186
257
- osbot_utils/testing/Temp_Zip.py,sha256=yGEqba2uHerDG5JuAtEgXgG6ZT6joztTxWadRcdFubM,1349
257
+ osbot_utils/testing/Temp_Zip.py,sha256=Qaxu7J4zpdYn3bXgYOLT5BYRWu8-QgkUBA-LtqpNoS0,1487
258
258
  osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=LhZZR3jQtRywdQNC71hvFk1I3Yek4eMPXpNTT8S6zHo,3278
259
259
  osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
260
260
  osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
@@ -265,7 +265,7 @@ osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
265
265
  osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
266
266
  osbot_utils/utils/Env.py,sha256=uYLhqVXqqgfh03Zmf9Vdy9zFdFf0rasW6lteh_VM1xQ,5078
267
267
  osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
268
- osbot_utils/utils/Files.py,sha256=q4_JeNWZygM8T0_frpTGvZjtISC1ZyJTOr3bD9pCKUE,19599
268
+ osbot_utils/utils/Files.py,sha256=fWASqyfhUttKw4g3AfbhzplUPZL228nBzBSVqgLylvQ,20374
269
269
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
270
270
  osbot_utils/utils/Http.py,sha256=Z8V149M2HDrKBoXkDD5EXgqTGx6vQoUqXugXK__wcuw,4572
271
271
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
@@ -281,10 +281,10 @@ osbot_utils/utils/Status.py,sha256=Yq4s0TelXgn0i2QjCP9V8mP30GabXp_UL-jjM6Iwiw4,4
281
281
  osbot_utils/utils/Str.py,sha256=kxdY8ROX4FdJtCaMTfOc8fK_xcDICprNkefHu2MMNU4,2585
282
282
  osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,1402
283
283
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
284
- osbot_utils/utils/Zip.py,sha256=YFahdBguVK71mLdYy4m7mqVAQ5al-60QnTmYK-txCfY,6784
284
+ osbot_utils/utils/Zip.py,sha256=yGTRuE1gaUMZ8T_lnM0PAU31Kwd-TrzEuuWysJVgHGA,6868
285
285
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
286
- osbot_utils/version,sha256=U6XfqJy3uErITQwIljLFrmcd6bNbxgAaOZBn2N10FzA,8
287
- osbot_utils-1.26.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
288
- osbot_utils-1.26.0.dist-info/METADATA,sha256=v-yB6jau74HW-32x-u-GKJrage3pT0FS-URSEdPR0_U,1266
289
- osbot_utils-1.26.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
290
- osbot_utils-1.26.0.dist-info/RECORD,,
286
+ osbot_utils/version,sha256=geP7KEJu4xooR8XnusEbz-qnkD4i7bGqu2XFp8jXSIo,8
287
+ osbot_utils-1.27.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
288
+ osbot_utils-1.27.0.dist-info/METADATA,sha256=DGQYf9EpRkKvgPfZZ2Z2xQVy8sLD6ODZwAUZfvr68nU,1266
289
+ osbot_utils-1.27.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
290
+ osbot_utils-1.27.0.dist-info/RECORD,,