abstract-utilities 0.2.2.442__py3-none-any.whl → 0.2.2.688__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.

Potentially problematic release.


This version of abstract-utilities might be problematic. Click here for more details.

Files changed (236) hide show
  1. abstract_utilities/__init__.py +25 -16
  2. abstract_utilities/circular_import_finder.py +222 -0
  3. abstract_utilities/circular_import_finder2.py +118 -0
  4. abstract_utilities/class_utils/__init__.py +7 -0
  5. abstract_utilities/class_utils/abstract_classes.py +144 -0
  6. abstract_utilities/class_utils/caller_utils.py +92 -0
  7. abstract_utilities/class_utils/class_utils.py +109 -0
  8. abstract_utilities/class_utils/function_utils.py +153 -0
  9. abstract_utilities/class_utils/global_utils.py +71 -0
  10. abstract_utilities/class_utils/imports/__init__.py +2 -0
  11. abstract_utilities/class_utils/imports/imports.py +2 -0
  12. abstract_utilities/class_utils/imports/utils.py +40 -0
  13. abstract_utilities/class_utils/module_utils.py +63 -0
  14. abstract_utilities/class_utils.py +0 -1
  15. abstract_utilities/directory_utils/__init__.py +2 -0
  16. abstract_utilities/directory_utils/directory_utils.py +94 -0
  17. abstract_utilities/directory_utils/imports/__init__.py +2 -0
  18. abstract_utilities/directory_utils/imports/imports.py +1 -0
  19. abstract_utilities/directory_utils/imports/module_imports.py +2 -0
  20. abstract_utilities/directory_utils/name_utils.py +43 -0
  21. abstract_utilities/directory_utils/size_utils.py +57 -0
  22. abstract_utilities/directory_utils/src/__init__.py +4 -0
  23. abstract_utilities/directory_utils/src/directory_utils.py +110 -0
  24. abstract_utilities/directory_utils/src/name_utils.py +43 -0
  25. abstract_utilities/directory_utils/src/size_utils.py +57 -0
  26. abstract_utilities/directory_utils/src/utils.py +116 -0
  27. abstract_utilities/directory_utils/utils.py +116 -0
  28. abstract_utilities/dynimport.py +1 -1
  29. abstract_utilities/env_utils/imports/imports.py +5 -3
  30. abstract_utilities/error_utils/__init__.py +2 -0
  31. abstract_utilities/error_utils/error_utils.py +25 -0
  32. abstract_utilities/error_utils/imports/__init__.py +2 -0
  33. abstract_utilities/error_utils/imports/imports.py +1 -0
  34. abstract_utilities/error_utils/imports/module_imports.py +1 -0
  35. abstract_utilities/file_utils/__init__.py +1 -2
  36. abstract_utilities/file_utils/file_utils/__init__.py +2 -0
  37. abstract_utilities/file_utils/file_utils/file_utils.py +3 -3
  38. abstract_utilities/file_utils/file_utils/find_collect.py +154 -0
  39. abstract_utilities/file_utils/file_utils/imports/__init__.py +3 -0
  40. abstract_utilities/file_utils/file_utils/imports/constants.py +39 -0
  41. abstract_utilities/file_utils/file_utils/imports/file_functions.py +10 -0
  42. abstract_utilities/file_utils/file_utils/imports/imports.py +39 -0
  43. abstract_utilities/file_utils/file_utils/imports/module_imports.py +14 -0
  44. abstract_utilities/file_utils/file_utils/imports.py +9 -0
  45. abstract_utilities/file_utils/file_utils/type_checks.py +92 -0
  46. abstract_utilities/file_utils/imports/__init__.py +1 -2
  47. abstract_utilities/file_utils/imports/classes.py +59 -55
  48. abstract_utilities/file_utils/imports/clean_imps.py +158 -0
  49. abstract_utilities/file_utils/imports/constants.py +84 -4
  50. abstract_utilities/file_utils/imports/file_functions.py +1 -1
  51. abstract_utilities/file_utils/imports/imports.py +40 -8
  52. abstract_utilities/file_utils/imports/module_imports.py +4 -5
  53. abstract_utilities/file_utils/module_imports.py +12 -0
  54. abstract_utilities/file_utils/src/__init__.py +7 -0
  55. abstract_utilities/file_utils/src/file_filters/__init__.py +1 -0
  56. abstract_utilities/file_utils/src/file_filters/ensure_utils.py +490 -0
  57. abstract_utilities/file_utils/src/file_filters/filter_params.py +150 -0
  58. abstract_utilities/file_utils/src/file_filters/filter_utils.py +78 -0
  59. abstract_utilities/file_utils/src/file_filters/predicate_utils.py +44 -0
  60. abstract_utilities/file_utils/src/file_filters.py +177 -0
  61. abstract_utilities/file_utils/src/file_reader.py +543 -0
  62. abstract_utilities/file_utils/src/file_utils.py +156 -0
  63. abstract_utilities/file_utils/src/filter_params.py +197 -0
  64. abstract_utilities/file_utils/src/find_collect.py +200 -0
  65. abstract_utilities/file_utils/src/find_content.py +210 -0
  66. abstract_utilities/file_utils/src/initFunctionsGen.py +293 -0
  67. abstract_utilities/file_utils/src/initFunctionsGens.py +280 -0
  68. abstract_utilities/file_utils/src/map_utils.py +29 -0
  69. abstract_utilities/file_utils/src/pdf_utils.py +300 -0
  70. abstract_utilities/file_utils/src/reader_utils/__init__.py +4 -0
  71. abstract_utilities/file_utils/src/reader_utils/directory_reader.py +53 -0
  72. abstract_utilities/file_utils/src/reader_utils/file_reader.py +543 -0
  73. abstract_utilities/file_utils/src/reader_utils/file_readers.py +376 -0
  74. abstract_utilities/file_utils/src/reader_utils/imports.py +18 -0
  75. abstract_utilities/file_utils/src/reader_utils/pdf_utils.py +300 -0
  76. abstract_utilities/file_utils/src/type_checks.py +91 -0
  77. abstract_utilities/file_utils (2)/__init__.py +2 -0
  78. abstract_utilities/file_utils (2)/imports/__init__.py +2 -0
  79. abstract_utilities/file_utils (2)/imports/constants.py +118 -0
  80. abstract_utilities/file_utils (2)/imports/imports/__init__.py +3 -0
  81. abstract_utilities/file_utils (2)/imports/imports/constants.py +119 -0
  82. abstract_utilities/file_utils (2)/imports/imports/imports.py +46 -0
  83. abstract_utilities/file_utils (2)/imports/imports/module_imports.py +8 -0
  84. abstract_utilities/file_utils (2)/imports/utils/__init__.py +3 -0
  85. abstract_utilities/file_utils (2)/imports/utils/classes.py +379 -0
  86. abstract_utilities/file_utils (2)/imports/utils/clean_imps.py +155 -0
  87. abstract_utilities/file_utils (2)/imports/utils/filter_utils.py +341 -0
  88. abstract_utilities/file_utils (2)/src/__init__.py +8 -0
  89. abstract_utilities/file_utils (2)/src/file_filters.py +155 -0
  90. abstract_utilities/file_utils (2)/src/file_reader.py +604 -0
  91. abstract_utilities/file_utils (2)/src/find_collect.py +258 -0
  92. abstract_utilities/file_utils (2)/src/initFunctionsGen.py +286 -0
  93. abstract_utilities/file_utils (2)/src/map_utils.py +28 -0
  94. abstract_utilities/file_utils (2)/src/pdf_utils.py +300 -0
  95. abstract_utilities/hash_utils/__init__.py +2 -0
  96. abstract_utilities/hash_utils/hash_utils.py +5 -0
  97. abstract_utilities/hash_utils/imports/__init__.py +2 -0
  98. abstract_utilities/hash_utils/imports/imports.py +1 -0
  99. abstract_utilities/hash_utils/imports/module_imports.py +0 -0
  100. abstract_utilities/history_utils/__init__.py +2 -0
  101. abstract_utilities/history_utils/history_utils.py +37 -0
  102. abstract_utilities/history_utils/imports/__init__.py +2 -0
  103. abstract_utilities/history_utils/imports/imports.py +1 -0
  104. abstract_utilities/history_utils/imports/module_imports.py +0 -0
  105. abstract_utilities/import_utils/__init__.py +2 -0
  106. abstract_utilities/import_utils/circular_import_finder.py +222 -0
  107. abstract_utilities/import_utils/circular_import_finder2.py +118 -0
  108. abstract_utilities/import_utils/imports/__init__.py +4 -0
  109. abstract_utilities/import_utils/imports/constants.py +2 -0
  110. abstract_utilities/import_utils/imports/imports.py +4 -0
  111. abstract_utilities/import_utils/imports/init_imports.py +3 -0
  112. abstract_utilities/import_utils/imports/module_imports.py +9 -0
  113. abstract_utilities/import_utils/imports/utils.py +30 -0
  114. abstract_utilities/import_utils/src/__init__.py +8 -0
  115. abstract_utilities/import_utils/src/clean_imports.py +278 -0
  116. abstract_utilities/import_utils/src/dot_utils.py +80 -0
  117. abstract_utilities/import_utils/src/extract_utils.py +46 -0
  118. abstract_utilities/import_utils/src/import_functions.py +110 -0
  119. abstract_utilities/import_utils/src/import_utils.py +349 -0
  120. abstract_utilities/import_utils/src/layze_import_utils/__init__.py +2 -0
  121. abstract_utilities/import_utils/src/layze_import_utils/lazy_utils.py +41 -0
  122. abstract_utilities/import_utils/src/layze_import_utils/nullProxy.py +37 -0
  123. abstract_utilities/import_utils/src/nullProxy.py +30 -0
  124. abstract_utilities/import_utils/src/package_utils/__init__.py +139 -0
  125. abstract_utilities/import_utils/src/package_utils/context_utils.py +27 -0
  126. abstract_utilities/import_utils/src/package_utils/import_collectors.py +53 -0
  127. abstract_utilities/import_utils/src/package_utils/path_utils.py +28 -0
  128. abstract_utilities/import_utils/src/package_utils/safe_import.py +27 -0
  129. abstract_utilities/import_utils/src/package_utils.py +140 -0
  130. abstract_utilities/import_utils/src/package_utilss/__init__.py +139 -0
  131. abstract_utilities/import_utils/src/package_utilss/context_utils.py +27 -0
  132. abstract_utilities/import_utils/src/package_utilss/import_collectors.py +53 -0
  133. abstract_utilities/import_utils/src/package_utilss/path_utils.py +28 -0
  134. abstract_utilities/import_utils/src/package_utilss/safe_import.py +27 -0
  135. abstract_utilities/import_utils/src/pkg_utils.py +194 -0
  136. abstract_utilities/import_utils/src/sysroot_utils.py +112 -0
  137. abstract_utilities/imports.py +21 -0
  138. abstract_utilities/json_utils/__init__.py +2 -0
  139. abstract_utilities/json_utils/imports/__init__.py +2 -0
  140. abstract_utilities/json_utils/imports/imports.py +2 -0
  141. abstract_utilities/json_utils/imports/module_imports.py +5 -0
  142. abstract_utilities/json_utils/json_utils.py +777 -0
  143. abstract_utilities/list_utils/__init__.py +2 -0
  144. abstract_utilities/list_utils/imports/__init__.py +2 -0
  145. abstract_utilities/list_utils/imports/imports.py +1 -0
  146. abstract_utilities/list_utils/imports/module_imports.py +0 -0
  147. abstract_utilities/list_utils/list_utils.py +202 -0
  148. abstract_utilities/log_utils/__init__.py +5 -0
  149. abstract_utilities/log_utils/abstractLogManager.py +64 -0
  150. abstract_utilities/log_utils/call_response.py +68 -0
  151. abstract_utilities/log_utils/imports/__init__.py +2 -0
  152. abstract_utilities/log_utils/imports/imports.py +7 -0
  153. abstract_utilities/log_utils/imports/module_imports.py +2 -0
  154. abstract_utilities/log_utils/log_file.py +162 -0
  155. abstract_utilities/log_utils/logger_callable.py +49 -0
  156. abstract_utilities/math_utils/__init__.py +2 -0
  157. abstract_utilities/math_utils/imports/__init__.py +2 -0
  158. abstract_utilities/math_utils/imports/imports.py +2 -0
  159. abstract_utilities/math_utils/imports/module_imports.py +1 -0
  160. abstract_utilities/math_utils/math_utils.py +208 -0
  161. abstract_utilities/parse_utils/__init__.py +2 -0
  162. abstract_utilities/parse_utils/imports/__init__.py +3 -0
  163. abstract_utilities/parse_utils/imports/constants.py +10 -0
  164. abstract_utilities/parse_utils/imports/imports.py +2 -0
  165. abstract_utilities/parse_utils/imports/module_imports.py +4 -0
  166. abstract_utilities/parse_utils/parse_utils.py +539 -0
  167. abstract_utilities/path_utils/__init__.py +2 -0
  168. abstract_utilities/path_utils/imports/__init__.py +3 -0
  169. abstract_utilities/path_utils/imports/imports.py +1 -0
  170. abstract_utilities/path_utils/imports/module_imports.py +8 -0
  171. abstract_utilities/path_utils/path_utils.py +248 -0
  172. abstract_utilities/path_utils.py +95 -14
  173. abstract_utilities/read_write_utils/__init__.py +1 -0
  174. abstract_utilities/read_write_utils/imports/__init__.py +2 -0
  175. abstract_utilities/read_write_utils/imports/imports.py +2 -0
  176. abstract_utilities/read_write_utils/imports/module_imports.py +5 -0
  177. abstract_utilities/read_write_utils/read_write_utils.py +439 -0
  178. abstract_utilities/read_write_utils.py +218 -10
  179. abstract_utilities/robust_reader/imports/imports.py +0 -9
  180. abstract_utilities/robust_readers/import_utils/__init__.py +1 -0
  181. abstract_utilities/robust_readers/import_utils/clean_imports.py +175 -0
  182. abstract_utilities/robust_readers/initFuncGen.py +10 -2
  183. abstract_utilities/safe_utils/__init__.py +2 -0
  184. abstract_utilities/safe_utils/imports/__init__.py +3 -0
  185. abstract_utilities/safe_utils/imports/imports.py +2 -0
  186. abstract_utilities/safe_utils/imports/module_imports.py +2 -0
  187. abstract_utilities/safe_utils/safe_utils.py +166 -0
  188. abstract_utilities/ssh_utils/__init__.py +3 -1
  189. abstract_utilities/ssh_utils/classes.py +0 -1
  190. abstract_utilities/ssh_utils/cmd_utils.py +207 -0
  191. abstract_utilities/ssh_utils/imports/__init__.py +3 -0
  192. abstract_utilities/ssh_utils/imports/imports.py +5 -0
  193. abstract_utilities/ssh_utils/imports/module_imports.py +6 -0
  194. abstract_utilities/ssh_utils/imports/utils.py +189 -0
  195. abstract_utilities/ssh_utils/imports.py +1 -2
  196. abstract_utilities/ssh_utils/pexpect_utils.py +11 -18
  197. abstract_utilities/ssh_utils/type_checks.py +92 -0
  198. abstract_utilities/string_clean.py +40 -1
  199. abstract_utilities/string_utils/__init__.py +4 -0
  200. abstract_utilities/string_utils/clean_utils.py +28 -0
  201. abstract_utilities/string_utils/eat_utils.py +103 -0
  202. abstract_utilities/string_utils/imports/__init__.py +3 -0
  203. abstract_utilities/string_utils/imports/imports.py +2 -0
  204. abstract_utilities/string_utils/imports/module_imports.py +2 -0
  205. abstract_utilities/string_utils/imports/utils.py +81 -0
  206. abstract_utilities/string_utils/replace_utils.py +27 -0
  207. abstract_utilities/string_utils.py +51 -0
  208. abstract_utilities/thread_utils/__init__.py +2 -0
  209. abstract_utilities/thread_utils/imports/__init__.py +2 -0
  210. abstract_utilities/thread_utils/imports/imports.py +2 -0
  211. abstract_utilities/thread_utils/imports/module_imports.py +2 -0
  212. abstract_utilities/thread_utils/thread_utils.py +140 -0
  213. abstract_utilities/time_utils/__init__.py +2 -0
  214. abstract_utilities/time_utils/imports/__init__.py +2 -0
  215. abstract_utilities/time_utils/imports/imports.py +3 -0
  216. abstract_utilities/time_utils/imports/module_imports.py +1 -0
  217. abstract_utilities/time_utils/time_utils.py +392 -0
  218. abstract_utilities/type_utils/__init__.py +7 -0
  219. abstract_utilities/type_utils/alpha_utils.py +59 -0
  220. abstract_utilities/type_utils/get_type.py +120 -0
  221. abstract_utilities/type_utils/imports/__init__.py +3 -0
  222. abstract_utilities/type_utils/imports/constants.py +134 -0
  223. abstract_utilities/type_utils/imports/imports.py +4 -0
  224. abstract_utilities/type_utils/imports/module_imports.py +25 -0
  225. abstract_utilities/type_utils/is_type.py +455 -0
  226. abstract_utilities/type_utils/make_type.py +126 -0
  227. abstract_utilities/type_utils/mime_types.py +68 -0
  228. abstract_utilities/type_utils/num_utils.py +19 -0
  229. abstract_utilities/type_utils/type_utils.py +104 -0
  230. abstract_utilities/type_utils.py +25 -1
  231. {abstract_utilities-0.2.2.442.dist-info → abstract_utilities-0.2.2.688.dist-info}/METADATA +1 -1
  232. abstract_utilities-0.2.2.688.dist-info/RECORD +288 -0
  233. imports/__init__.py +36 -0
  234. abstract_utilities-0.2.2.442.dist-info/RECORD +0 -82
  235. {abstract_utilities-0.2.2.442.dist-info → abstract_utilities-0.2.2.688.dist-info}/WHEEL +0 -0
  236. {abstract_utilities-0.2.2.442.dist-info → abstract_utilities-0.2.2.688.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,110 @@
1
+ from pathlib import Path
2
+ from .utils import *
3
+
4
+ def get_shortest_path(*args):
5
+ shortest = None
6
+ args = {arg:str(arg).split('/') for arg in args if arg}
7
+ for path,spl in args.items():
8
+ if shortest is None or (len(spl)<len(shortest[-1])):
9
+ shortest=[path,spl]
10
+ return shortest[0]
11
+ def get_common_root(paths):
12
+ """
13
+ Compute the deepest common parent directory of all sysroots.
14
+ """
15
+ paths = [Path(p).resolve() for p in paths]
16
+ common = os.path.commonpath(paths)
17
+ return common
18
+
19
+ def get_dirs(path):
20
+ """
21
+ Get List of Immediate Subdirectories in a Path
22
+
23
+ This function uses the os.walk method to traverse through a directory tree and returns a list of immediate subdirectories
24
+ within the specified path.
25
+
26
+ Parameters:
27
+ - path (str): The path for which subdirectories need to be retrieved.
28
+
29
+ Returns:
30
+ - subdirectories (list): A list of immediate subdirectories within the specified path.
31
+
32
+ Example:
33
+ subdirs = get_dirs("/path/to/directory")
34
+ print("Immediate Subdirectories:", subdirs)
35
+ """
36
+ from os import walk
37
+ for (dirpath, dirnames, filenames) in walk(path):
38
+ return dirnames
39
+ def get_directory(file_path: str) -> str:
40
+ """
41
+ Extracts and returns the directory path from a given file path.
42
+
43
+ Args:
44
+ file_path (str): A string representing the file path.
45
+
46
+ Returns:
47
+ str: The directory path extracted from the file path.
48
+ """
49
+ return os.path.dirname(file_path)
50
+ def if_not_last_child_join(path:str,child:str):
51
+ """
52
+ Adds a child path to the given path if it's not already present at the end.
53
+
54
+ Args:
55
+ path (str): The parent path.
56
+ child (str): The child path to add.
57
+
58
+ Returns:
59
+ str: The updated path.
60
+ """
61
+ if path.endswith(child):
62
+ return path
63
+ return simple_path_join(path, child)
64
+ def createFolds(ls: list) -> None:
65
+ """
66
+ Creates multiple directories.
67
+
68
+ Args:
69
+ ls (list): The list of directory paths to create.
70
+ """
71
+ for k in range(len(ls)):
72
+ mkdirs(ls[k])
73
+ def list_directory_contents(path: str) -> list:
74
+ """Returns a list of directory contents or a list with a single file, if the path is a file.
75
+
76
+ Args:
77
+ path (str): The path of the directory or file.
78
+
79
+ Returns:
80
+ list: A list of directory contents or a list with a single file path.
81
+ """
82
+ if is_file(path):
83
+ return [path]
84
+ elif is_valid_path(path):
85
+ return os.listdir(path)
86
+ return [path]
87
+ def is_string_in_dir(path,strings,**kwargs):
88
+ dirname = path
89
+ if is_file(path,**kwargs):
90
+ dirname = os.path.dirname(path)
91
+ pieces = [pa for pa in dirname.split('/') if pa and pa in strings]
92
+ if pieces:
93
+ return True
94
+ return False
95
+ def raw_create_dirs(*paths):
96
+ """Recursively create all directories along the given path."""
97
+ full_path = os.path.abspath(safe_join(*paths))
98
+ sub_parts = [p for p in full_path.split(os.sep) if p]
99
+
100
+ current_path = "/" if full_path.startswith(os.sep) else ""
101
+ for part in sub_parts:
102
+ current_path = safe_join(current_path, part)
103
+ os.makedirs(current_path, exist_ok=True)
104
+ return full_path
105
+
106
+ mkdirs=raw_create_dirs
107
+ makedirs = mkdirs
108
+ make_dirs = makedirs
109
+ makeAllDirs = raw_create_dirs
110
+
@@ -0,0 +1,43 @@
1
+ from ..imports import *
2
+ from .directory_utils import *
3
+ def get_file_name(file_path: str) -> str:
4
+ """
5
+ Retrieves and returns the base name of a file from a given file path.
6
+
7
+ Args:
8
+ file_path (str): A string representing the file path.
9
+
10
+ Returns:
11
+ str: The base name of the file (without extension).
12
+ """
13
+ return split_text(get_base_name(file_path))[0]
14
+ def get_abs_name_of_this():
15
+ """
16
+ Returns the absolute name of the current module.
17
+
18
+ Returns:
19
+ Path: The absolute name of the current module.
20
+ """
21
+ return os.path.abspath(__name__)
22
+ def sanitize_filename(name: str):
23
+ """
24
+ Sanitize a filename by removing invalid characters.
25
+
26
+ Args:
27
+ name (str): Filename to sanitize.
28
+
29
+ Returns:
30
+ str: Sanitized filename.
31
+ """
32
+ return re.sub(r'[\\/*?:"<>|]', "", name)
33
+ def get_base_name(file_path: str) -> str:
34
+ """
35
+ Extracts and returns the base name of a file from a given file path.
36
+
37
+ Args:
38
+ file_path (str): A string representing the file path.
39
+
40
+ Returns:
41
+ str: The base name of the file.
42
+ """
43
+ return os.path.basename(file_path)
@@ -0,0 +1,57 @@
1
+ from ..imports import *
2
+ from .name_utils import *
3
+ def get_os_info():
4
+ """
5
+ Get Operating System Information
6
+
7
+ This function retrieves information about the current operating system, including its name and bit size.
8
+
9
+ Returns:
10
+ - os_info (dict): A dictionary containing the operating system information.
11
+ Keys:
12
+ - "operating_system" (str): The name of the operating system (e.g., "Windows", "Linux", "Darwin").
13
+ - "bit_size" (str): The bit size of the operating system (e.g., "32bit", "64bit").
14
+
15
+ Example:
16
+ os_info = get_os_info()
17
+ print("Operating System:", os_info["operating_system"])
18
+ print("Bit Size:", os_info["bit_size"])
19
+ """
20
+ os_name = platform.system()
21
+ bit_size = platform.architecture()[0]
22
+ return {"operating_system": os_name, "bit_size": bit_size}
23
+ def mkGb(k) -> float:
24
+ """
25
+ Converts a value to Gigabytes (GB).
26
+
27
+ Args:
28
+ k (float): The value to convert to GB.
29
+
30
+ Returns:
31
+ float: The value converted to GB.
32
+ """
33
+ return float(float(k)*(10**9))
34
+
35
+ def mkGbTrunk(k) -> float:
36
+ """
37
+ Converts a value to Gigabytes (GB) and truncates the result to five decimal places.
38
+
39
+ Args:
40
+ k (float): The value to convert to GB.
41
+
42
+ Returns:
43
+ float: The value converted to GB and truncated to five decimal places.
44
+ """
45
+ return trunc(mkGb(k), 5)
46
+
47
+ def mkGbTrunFroPathTot(k) -> float:
48
+ """
49
+ Fetches the file size from a path, converts it to Gigabytes (GB) and truncates the result to five decimal places.
50
+
51
+ Args:
52
+ k (str): The file path.
53
+
54
+ Returns:
55
+ float: The file size converted to GB and truncated to five decimal places.
56
+ """
57
+ return trunc(mkGb(s.path.getsize(k)), 5)
@@ -0,0 +1,116 @@
1
+ from ..imports import *
2
+ def split_text(string: str) -> tuple:
3
+ """
4
+ Splits a string into its base name and extension and returns them as a tuple.
5
+
6
+ Args:
7
+ string (str): A string to be split, typically representing a file name.
8
+
9
+ Returns:
10
+ tuple: A tuple containing the base name and extension of the input string.
11
+ """
12
+ return os.path.splitext(string)
13
+ def get_ext(file_path: str) -> str:
14
+ """
15
+ Retrieves and returns the extension of a file from a given file path.
16
+
17
+ Args:
18
+ file_path (str): A string representing the file path.
19
+
20
+ Returns:
21
+ str: The extension of the file (including the dot).
22
+ """
23
+ return split_text(get_base_name(file_path))[1]
24
+
25
+ def get_slash():
26
+ """
27
+ Returns the appropriate file path separator depending on the current operating system.
28
+ """
29
+ slash = '/' # Assume a Unix-like system by default
30
+ if slash not in get_current_path():
31
+ slash = '\\' # Use backslash for Windows systems
32
+ return slash
33
+ def get_current_path():
34
+ """
35
+ Returns the current working directory.
36
+
37
+ Returns:
38
+ str: The current working directory.
39
+ """
40
+ return os.getcwd()
41
+
42
+ def get_home_folder():
43
+ """
44
+ Returns the path to the home directory of the current user.
45
+
46
+ Returns:
47
+ str: The path to the home directory.
48
+ """
49
+ return os.path.expanduser("~")
50
+ def simple_path_join(path_A:str, path_B:str):
51
+ """
52
+ Join two paths using the appropriate file path separator.
53
+
54
+ Args:
55
+ path_A (str): The first path to join.
56
+ path_B (str): The second path to join.
57
+
58
+ Returns:
59
+ str: The joined path.
60
+ """
61
+ return os.path.join(str(path_A), str(path_B))
62
+
63
+ def path_join(path_A, path_B=None):
64
+ """
65
+ Joins two paths or a list of paths using the appropriate file path separator.
66
+
67
+ Args:
68
+ path_A (str or list): The first path or list of paths to join.
69
+ path_B (str, optional): The second path to join. Defaults to None.
70
+
71
+ Returns:
72
+ str: The joined path.
73
+ """
74
+ if path_B is not None: # If path_B is provided, join path_A and path_B
75
+ return simple_path_join(path_A, path_B)
76
+ if isinstance(path_A, list): # If path_A is a list, join all paths in the list
77
+ path = path_A[0]
78
+ for k in range(1, len(path_A)):
79
+ path = simple_path_join(path, path_A[k])
80
+ return path
81
+ def update_global_variable(name: str, value) -> None:
82
+ """Updates the global variable with the provided name and value.
83
+
84
+ Args:
85
+ name (str): The name of the global variable.
86
+ value: The value to assign to the global variable.
87
+
88
+ Returns:
89
+ None
90
+ """
91
+ globals()[name] = value
92
+
93
+
94
+ def trunc(a: float, x: int) -> float:
95
+ """
96
+ Truncates a float number to a specific number of decimal places.
97
+
98
+ Args:
99
+ a (float): The number to truncate.
100
+ x (int): The number of decimal places to retain.
101
+
102
+ Returns:
103
+ float: The truncated float number.
104
+ """
105
+ temp = str(a)
106
+ for i in range(len(temp)):
107
+ if temp[i] == '.':
108
+ try:
109
+ return float(temp[:i+x+1])
110
+ except:
111
+ return float(temp)
112
+ return float(temp)
113
+
114
+
115
+
116
+
@@ -0,0 +1,116 @@
1
+ from ..imports import *
2
+ def split_text(string: str) -> tuple:
3
+ """
4
+ Splits a string into its base name and extension and returns them as a tuple.
5
+
6
+ Args:
7
+ string (str): A string to be split, typically representing a file name.
8
+
9
+ Returns:
10
+ tuple: A tuple containing the base name and extension of the input string.
11
+ """
12
+ return os.path.splitext(string)
13
+ def get_ext(file_path: str) -> str:
14
+ """
15
+ Retrieves and returns the extension of a file from a given file path.
16
+
17
+ Args:
18
+ file_path (str): A string representing the file path.
19
+
20
+ Returns:
21
+ str: The extension of the file (including the dot).
22
+ """
23
+ return split_text(get_base_name(file_path))[1]
24
+
25
+ def get_slash():
26
+ """
27
+ Returns the appropriate file path separator depending on the current operating system.
28
+ """
29
+ slash = '/' # Assume a Unix-like system by default
30
+ if slash not in get_current_path():
31
+ slash = '\\' # Use backslash for Windows systems
32
+ return slash
33
+ def get_current_path():
34
+ """
35
+ Returns the current working directory.
36
+
37
+ Returns:
38
+ str: The current working directory.
39
+ """
40
+ return os.getcwd()
41
+
42
+ def get_home_folder():
43
+ """
44
+ Returns the path to the home directory of the current user.
45
+
46
+ Returns:
47
+ str: The path to the home directory.
48
+ """
49
+ return os.path.expanduser("~")
50
+ def simple_path_join(path_A:str, path_B:str):
51
+ """
52
+ Join two paths using the appropriate file path separator.
53
+
54
+ Args:
55
+ path_A (str): The first path to join.
56
+ path_B (str): The second path to join.
57
+
58
+ Returns:
59
+ str: The joined path.
60
+ """
61
+ return os.path.join(str(path_A), str(path_B))
62
+
63
+ def path_join(path_A, path_B=None):
64
+ """
65
+ Joins two paths or a list of paths using the appropriate file path separator.
66
+
67
+ Args:
68
+ path_A (str or list): The first path or list of paths to join.
69
+ path_B (str, optional): The second path to join. Defaults to None.
70
+
71
+ Returns:
72
+ str: The joined path.
73
+ """
74
+ if path_B is not None: # If path_B is provided, join path_A and path_B
75
+ return simple_path_join(path_A, path_B)
76
+ if isinstance(path_A, list): # If path_A is a list, join all paths in the list
77
+ path = path_A[0]
78
+ for k in range(1, len(path_A)):
79
+ path = simple_path_join(path, path_A[k])
80
+ return path
81
+ def update_global_variable(name: str, value) -> None:
82
+ """Updates the global variable with the provided name and value.
83
+
84
+ Args:
85
+ name (str): The name of the global variable.
86
+ value: The value to assign to the global variable.
87
+
88
+ Returns:
89
+ None
90
+ """
91
+ globals()[name] = value
92
+
93
+
94
+ def trunc(a: float, x: int) -> float:
95
+ """
96
+ Truncates a float number to a specific number of decimal places.
97
+
98
+ Args:
99
+ a (float): The number to truncate.
100
+ x (int): The number of decimal places to retain.
101
+
102
+ Returns:
103
+ float: The truncated float number.
104
+ """
105
+ temp = str(a)
106
+ for i in range(len(temp)):
107
+ if temp[i] == '.':
108
+ try:
109
+ return float(temp[:i+x+1])
110
+ except:
111
+ return float(temp)
112
+ return float(temp)
113
+
114
+
115
+
116
+
@@ -2,7 +2,7 @@
2
2
  from __future__ import annotations
3
3
  from functools import lru_cache
4
4
  from typing import *
5
- import importlib, sys, os, sys
5
+ import importlib, sys, os, sys,inspect
6
6
  from typing import Optional
7
7
  from importlib import import_module
8
8
  from .type_utils import make_list
@@ -1,8 +1,10 @@
1
- import os
1
+ from ...imports import os
2
2
  from dotenv import load_dotenv
3
- from ...string_clean import eatAll,eatInner,eatOuter,safe_split
3
+ from ...ssh_utils import is_file
4
+ from ...string_utils import eatAll,eatInner,eatOuter
5
+ from ...safe_utils import safe_split
4
6
  from ...compare_utils import line_contains
5
7
  from ...type_utils import is_list,is_bool
6
- from ...path_utils import get_slash,path_join,if_not_last_child_join,get_home_folder,simple_path_join,is_file
8
+ from ...directory_utils import get_slash,path_join,if_not_last_child_join,get_home_folder,simple_path_join
7
9
  DEFAULT_FILE_NAME = '.env'
8
10
  DEFAULT_KEY = 'MY_PASSWORD'
@@ -0,0 +1,2 @@
1
+ from .imports import *
2
+ from .error_utils import *
@@ -0,0 +1,25 @@
1
+ from .imports import *
2
+ def try_func(func, *args, logger=None, level='error', **kwargs):
3
+ """
4
+ Execute a function with try-except and log exceptions.
5
+
6
+ Args:
7
+ func: Function to execute.
8
+ *args: Positional arguments for the function.
9
+ logger: Logger object, logger method (e.g., logger.error), or None.
10
+ level (str): Logging level for exceptions (e.g., 'error').
11
+ **kwargs: Keyword arguments for the function.
12
+
13
+ Returns:
14
+ Result of the function if successful.
15
+
16
+ Raises:
17
+ Exception: If the function fails and logger is used to log the error.
18
+ """
19
+ log_callable = get_logger_callable(logger=logger, level=level)
20
+ try:
21
+ return func(*args, **kwargs)
22
+ except Exception as e:
23
+ if log_callable:
24
+ log_callable(f"Exception in {func.__name__}: {str(e)}")
25
+ raise
@@ -0,0 +1,2 @@
1
+ from .imports import *
2
+ from .module_imports import *
@@ -0,0 +1 @@
1
+ from ...log_utils import get_logger_callable
@@ -1,3 +1,2 @@
1
1
  from .imports import *
2
- from .file_utils import *
3
- from .req import call_for_all_tabs,get_for_all_tabs
2
+ from .src import *
@@ -4,3 +4,5 @@ from .filter_params import *
4
4
  from .map_utils import *
5
5
  from .pdf_utils import *
6
6
  from .file_reader import *
7
+ from .find_collect import *
8
+ from .type_checks import *
@@ -1,7 +1,7 @@
1
- from pathlib import Path
2
- from typing import *
3
- import fnmatch, os, glob
1
+
4
2
  from .filter_params import *
3
+ from .imports import *
4
+
5
5
  ##from abstract_utilities import make_list,get_media_exts, is_media_type
6
6
  def get_allowed_predicate(allowed=None):
7
7
  if allowed != False:
@@ -0,0 +1,154 @@
1
+ from .imports import *
2
+ from .filter_params import *
3
+ from .file_filters import enumerate_source_files
4
+
5
+
6
+ def check_path_type(
7
+ path: str,
8
+ user: Optional[str] = None,
9
+ host: Optional[str] = None,
10
+ user_as_host: Optional[str] = None,
11
+ use_shell: bool = False
12
+ ) -> Literal["file", "directory", "missing", "unknown"]:
13
+ """
14
+ Determine whether a given path is a file, directory, or missing.
15
+ Works locally or remotely (via SSH).
16
+
17
+ Args:
18
+ path: The path to check.
19
+ user, host, user_as_host: SSH parameters if remote.
20
+ use_shell: Force shell test instead of Python os.path.
21
+ Returns:
22
+ One of: 'file', 'directory', 'missing', or 'unknown'
23
+ """
24
+
25
+ # --- remote check if user/host is given ---
26
+ if user_as_host or (user and host):
27
+ remote_target = user_as_host or f"{user}@{host}"
28
+ cmd = f"if [ -f '{path}' ]; then echo file; elif [ -d '{path}' ]; then echo directory; else echo missing; fi"
29
+ try:
30
+ result = subprocess.check_output(
31
+ ["ssh", remote_target, cmd],
32
+ stderr=subprocess.DEVNULL,
33
+ text=True,
34
+ timeout=5
35
+ ).strip()
36
+ return result if result in ("file", "directory", "missing") else "unknown"
37
+ except Exception:
38
+ return "unknown"
39
+
40
+ # --- local check ---
41
+ if not use_shell:
42
+ if os.path.isfile(path):
43
+ return "file"
44
+ elif os.path.isdir(path):
45
+ return "directory"
46
+ elif not os.path.exists(path):
47
+ return "missing"
48
+ return "unknown"
49
+ else:
50
+ # fallback using shell tests (useful for sandboxed contexts)
51
+ cmd = f"if [ -f '{path}' ]; then echo file; elif [ -d '{path}' ]; then echo directory; else echo missing; fi"
52
+ try:
53
+ output = subprocess.check_output(
54
+ cmd, shell=True, stderr=subprocess.DEVNULL, text=True
55
+ ).strip()
56
+ return output if output in ("file", "directory", "missing") else "unknown"
57
+ except Exception:
58
+ return "unknown"
59
+
60
+
61
+
62
+
63
+ def get_find_cmd(
64
+ directory: str,
65
+ *,
66
+ mindepth: Optional[int] = None,
67
+ maxdepth: Optional[int] = None,
68
+ depth: Optional[int] = None,
69
+ file_type: Optional[str] = None, # 'f' or 'd'
70
+ name: Optional[str] = None,
71
+ size: Optional[str] = None,
72
+ mtime: Optional[str] = None,
73
+ perm: Optional[str] = None,
74
+ user: Optional[str] = None,
75
+ **kwargs
76
+ ) -> str:
77
+ """Constructs a Unix `find` command string from keyword args."""
78
+ cmd = [f"find {directory}"]
79
+
80
+ if depth is not None:
81
+ cmd += [f"-mindepth {depth}", f"-maxdepth {depth}"]
82
+ else:
83
+ if mindepth is not None:
84
+ cmd.append(f"-mindepth {mindepth}")
85
+ if maxdepth is not None:
86
+ cmd.append(f"-maxdepth {maxdepth}")
87
+
88
+ if file_type in ("f", "d"):
89
+ cmd.append(f"-type {file_type}")
90
+ if name:
91
+ cmd.append(f"-name '{name}'")
92
+ if size:
93
+ cmd.append(f"-size {size}")
94
+ if mtime:
95
+ cmd.append(f"-mtime {mtime}")
96
+ if perm:
97
+ cmd.append(f"-perm {perm}")
98
+ if user:
99
+ cmd.append(f"-user {user}")
100
+
101
+ return " ".join(cmd)
102
+
103
+
104
+ def collect_globs(
105
+ directory: str,
106
+ cfg: Optional["ScanConfig"] = None,
107
+ *,
108
+ exts: Optional[Set[str]] = None,
109
+ patterns: Optional[List[str]] = None,
110
+ mindepth: Optional[int] = None,
111
+ maxdepth: Optional[int] = None,
112
+ depth: Optional[int] = None,
113
+ file_type: Optional[str] = None,
114
+ user_at_host: Optional[str] = None,
115
+ add: bool = False,
116
+ **kwargs
117
+ ) -> List[str]:
118
+ """
119
+ Collect file or directory paths using either:
120
+ - local recursive logic (rglob)
121
+ - or remote shell call (find via run_cmd)
122
+ """
123
+ cfg = cfg or define_defaults(add=add)
124
+ directory = str(directory)
125
+ exts = ensure_exts(exts)
126
+ patterns = ensure_patterns(patterns)
127
+
128
+ # Remote path via SSH
129
+ if user_at_host:
130
+ find_cmd = get_find_cmd(
131
+ directory,
132
+ mindepth=mindepth,
133
+ maxdepth=maxdepth,
134
+ depth=depth,
135
+ file_type=file_type,
136
+ **{k: v for k, v in kwargs.items() if v},
137
+ )
138
+ return run_cmd(find_cmd, user_at_host=user_at_host)
139
+
140
+ # Local path (Python-native walk)
141
+ root = Path(directory)
142
+ results = []
143
+ for p in root.rglob("*"):
144
+ if file_type == "f" and not p.is_file():
145
+ continue
146
+ if file_type == "d" and not p.is_dir():
147
+ continue
148
+ if exts and p.suffix.lower() not in exts:
149
+ continue
150
+ if patterns and not any(p.match(pat) for pat in patterns):
151
+ continue
152
+ results.append(str(p.resolve()))
153
+
154
+ return sorted(results)
@@ -0,0 +1,3 @@
1
+ from .constants import *
2
+ from .imports import *
3
+ from ..imports import *