abstract-utilities 0.2.2.480__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.
- abstract_utilities/__init__.py +24 -16
- abstract_utilities/circular_import_finder.py +222 -0
- abstract_utilities/circular_import_finder2.py +118 -0
- abstract_utilities/class_utils/__init__.py +7 -0
- abstract_utilities/class_utils/abstract_classes.py +144 -0
- abstract_utilities/class_utils/caller_utils.py +92 -0
- abstract_utilities/class_utils/class_utils.py +109 -0
- abstract_utilities/class_utils/function_utils.py +153 -0
- abstract_utilities/class_utils/global_utils.py +71 -0
- abstract_utilities/class_utils/imports/__init__.py +2 -0
- abstract_utilities/class_utils/imports/imports.py +2 -0
- abstract_utilities/class_utils/imports/utils.py +40 -0
- abstract_utilities/class_utils/module_utils.py +63 -0
- abstract_utilities/directory_utils/__init__.py +2 -0
- abstract_utilities/directory_utils/directory_utils.py +94 -0
- abstract_utilities/directory_utils/imports/__init__.py +2 -0
- abstract_utilities/directory_utils/imports/imports.py +1 -0
- abstract_utilities/directory_utils/imports/module_imports.py +2 -0
- abstract_utilities/directory_utils/name_utils.py +43 -0
- abstract_utilities/directory_utils/size_utils.py +57 -0
- abstract_utilities/directory_utils/src/__init__.py +4 -0
- abstract_utilities/directory_utils/src/directory_utils.py +110 -0
- abstract_utilities/directory_utils/src/name_utils.py +43 -0
- abstract_utilities/directory_utils/src/size_utils.py +57 -0
- abstract_utilities/directory_utils/src/utils.py +116 -0
- abstract_utilities/directory_utils/utils.py +116 -0
- abstract_utilities/env_utils/imports/imports.py +5 -3
- abstract_utilities/error_utils/__init__.py +2 -0
- abstract_utilities/error_utils/error_utils.py +25 -0
- abstract_utilities/error_utils/imports/__init__.py +2 -0
- abstract_utilities/error_utils/imports/imports.py +1 -0
- abstract_utilities/error_utils/imports/module_imports.py +1 -0
- abstract_utilities/file_utils/__init__.py +1 -2
- abstract_utilities/file_utils/file_utils/type_checks.py +2 -1
- abstract_utilities/file_utils/imports/classes.py +59 -55
- abstract_utilities/file_utils/imports/constants.py +84 -4
- abstract_utilities/file_utils/imports/imports.py +2 -21
- abstract_utilities/file_utils/imports/module_imports.py +3 -8
- abstract_utilities/file_utils/module_imports.py +12 -0
- abstract_utilities/file_utils/src/__init__.py +7 -0
- abstract_utilities/file_utils/src/file_filters/__init__.py +1 -0
- abstract_utilities/file_utils/src/file_filters/ensure_utils.py +490 -0
- abstract_utilities/file_utils/src/file_filters/filter_params.py +150 -0
- abstract_utilities/file_utils/src/file_filters/filter_utils.py +78 -0
- abstract_utilities/file_utils/src/file_filters/predicate_utils.py +44 -0
- abstract_utilities/file_utils/src/file_filters.py +177 -0
- abstract_utilities/file_utils/src/file_reader.py +543 -0
- abstract_utilities/file_utils/src/file_utils.py +156 -0
- abstract_utilities/file_utils/src/filter_params.py +197 -0
- abstract_utilities/file_utils/src/find_collect.py +200 -0
- abstract_utilities/file_utils/src/find_content.py +210 -0
- abstract_utilities/file_utils/src/initFunctionsGen.py +293 -0
- abstract_utilities/file_utils/src/initFunctionsGens.py +280 -0
- abstract_utilities/file_utils/src/map_utils.py +29 -0
- abstract_utilities/file_utils/src/pdf_utils.py +300 -0
- abstract_utilities/file_utils/src/reader_utils/__init__.py +4 -0
- abstract_utilities/file_utils/src/reader_utils/directory_reader.py +53 -0
- abstract_utilities/file_utils/src/reader_utils/file_reader.py +543 -0
- abstract_utilities/file_utils/src/reader_utils/file_readers.py +376 -0
- abstract_utilities/file_utils/src/reader_utils/imports.py +18 -0
- abstract_utilities/file_utils/src/reader_utils/pdf_utils.py +300 -0
- abstract_utilities/file_utils/src/type_checks.py +91 -0
- abstract_utilities/file_utils (2)/__init__.py +2 -0
- abstract_utilities/file_utils (2)/imports/__init__.py +2 -0
- abstract_utilities/file_utils (2)/imports/constants.py +118 -0
- abstract_utilities/file_utils (2)/imports/imports/__init__.py +3 -0
- abstract_utilities/file_utils (2)/imports/imports/constants.py +119 -0
- abstract_utilities/file_utils (2)/imports/imports/imports.py +46 -0
- abstract_utilities/file_utils (2)/imports/imports/module_imports.py +8 -0
- abstract_utilities/file_utils (2)/imports/utils/__init__.py +3 -0
- abstract_utilities/file_utils (2)/imports/utils/classes.py +379 -0
- abstract_utilities/file_utils (2)/imports/utils/clean_imps.py +155 -0
- abstract_utilities/file_utils (2)/imports/utils/filter_utils.py +341 -0
- abstract_utilities/file_utils (2)/src/__init__.py +8 -0
- abstract_utilities/file_utils (2)/src/file_filters.py +155 -0
- abstract_utilities/file_utils (2)/src/file_reader.py +604 -0
- abstract_utilities/file_utils (2)/src/find_collect.py +258 -0
- abstract_utilities/file_utils (2)/src/initFunctionsGen.py +286 -0
- abstract_utilities/file_utils (2)/src/map_utils.py +28 -0
- abstract_utilities/file_utils (2)/src/pdf_utils.py +300 -0
- abstract_utilities/hash_utils/__init__.py +2 -0
- abstract_utilities/hash_utils/hash_utils.py +5 -0
- abstract_utilities/hash_utils/imports/__init__.py +2 -0
- abstract_utilities/hash_utils/imports/imports.py +1 -0
- abstract_utilities/hash_utils/imports/module_imports.py +0 -0
- abstract_utilities/history_utils/__init__.py +2 -0
- abstract_utilities/history_utils/history_utils.py +37 -0
- abstract_utilities/history_utils/imports/__init__.py +2 -0
- abstract_utilities/history_utils/imports/imports.py +1 -0
- abstract_utilities/history_utils/imports/module_imports.py +0 -0
- abstract_utilities/import_utils/__init__.py +2 -0
- abstract_utilities/import_utils/circular_import_finder.py +222 -0
- abstract_utilities/import_utils/circular_import_finder2.py +118 -0
- abstract_utilities/import_utils/imports/__init__.py +4 -0
- abstract_utilities/import_utils/imports/constants.py +2 -0
- abstract_utilities/import_utils/imports/imports.py +4 -0
- abstract_utilities/import_utils/imports/init_imports.py +3 -0
- abstract_utilities/import_utils/imports/module_imports.py +9 -0
- abstract_utilities/import_utils/imports/utils.py +30 -0
- abstract_utilities/import_utils/src/__init__.py +8 -0
- abstract_utilities/import_utils/src/clean_imports.py +278 -0
- abstract_utilities/import_utils/src/dot_utils.py +80 -0
- abstract_utilities/import_utils/src/extract_utils.py +46 -0
- abstract_utilities/import_utils/src/import_functions.py +110 -0
- abstract_utilities/import_utils/src/import_utils.py +349 -0
- abstract_utilities/import_utils/src/layze_import_utils/__init__.py +2 -0
- abstract_utilities/import_utils/src/layze_import_utils/lazy_utils.py +41 -0
- abstract_utilities/import_utils/src/layze_import_utils/nullProxy.py +37 -0
- abstract_utilities/import_utils/src/nullProxy.py +30 -0
- abstract_utilities/import_utils/src/package_utils/__init__.py +139 -0
- abstract_utilities/import_utils/src/package_utils/context_utils.py +27 -0
- abstract_utilities/import_utils/src/package_utils/import_collectors.py +53 -0
- abstract_utilities/import_utils/src/package_utils/path_utils.py +28 -0
- abstract_utilities/import_utils/src/package_utils/safe_import.py +27 -0
- abstract_utilities/import_utils/src/package_utils.py +140 -0
- abstract_utilities/import_utils/src/package_utilss/__init__.py +139 -0
- abstract_utilities/import_utils/src/package_utilss/context_utils.py +27 -0
- abstract_utilities/import_utils/src/package_utilss/import_collectors.py +53 -0
- abstract_utilities/import_utils/src/package_utilss/path_utils.py +28 -0
- abstract_utilities/import_utils/src/package_utilss/safe_import.py +27 -0
- abstract_utilities/import_utils/src/pkg_utils.py +194 -0
- abstract_utilities/import_utils/src/sysroot_utils.py +112 -0
- abstract_utilities/imports.py +21 -0
- abstract_utilities/json_utils/__init__.py +2 -0
- abstract_utilities/json_utils/imports/__init__.py +2 -0
- abstract_utilities/json_utils/imports/imports.py +2 -0
- abstract_utilities/json_utils/imports/module_imports.py +5 -0
- abstract_utilities/json_utils/json_utils.py +777 -0
- abstract_utilities/list_utils/__init__.py +2 -0
- abstract_utilities/list_utils/imports/__init__.py +2 -0
- abstract_utilities/list_utils/imports/imports.py +1 -0
- abstract_utilities/list_utils/imports/module_imports.py +0 -0
- abstract_utilities/list_utils/list_utils.py +202 -0
- abstract_utilities/log_utils/__init__.py +5 -0
- abstract_utilities/log_utils/abstractLogManager.py +64 -0
- abstract_utilities/log_utils/call_response.py +68 -0
- abstract_utilities/log_utils/imports/__init__.py +2 -0
- abstract_utilities/log_utils/imports/imports.py +7 -0
- abstract_utilities/log_utils/imports/module_imports.py +2 -0
- abstract_utilities/log_utils/log_file.py +162 -0
- abstract_utilities/log_utils/logger_callable.py +49 -0
- abstract_utilities/math_utils/__init__.py +2 -0
- abstract_utilities/math_utils/imports/__init__.py +2 -0
- abstract_utilities/math_utils/imports/imports.py +2 -0
- abstract_utilities/math_utils/imports/module_imports.py +1 -0
- abstract_utilities/math_utils/math_utils.py +208 -0
- abstract_utilities/parse_utils/__init__.py +2 -0
- abstract_utilities/parse_utils/imports/__init__.py +3 -0
- abstract_utilities/parse_utils/imports/constants.py +10 -0
- abstract_utilities/parse_utils/imports/imports.py +2 -0
- abstract_utilities/parse_utils/imports/module_imports.py +4 -0
- abstract_utilities/parse_utils/parse_utils.py +539 -0
- abstract_utilities/path_utils/__init__.py +2 -0
- abstract_utilities/path_utils/imports/__init__.py +3 -0
- abstract_utilities/path_utils/imports/imports.py +1 -0
- abstract_utilities/path_utils/imports/module_imports.py +8 -0
- abstract_utilities/path_utils/path_utils.py +248 -0
- abstract_utilities/path_utils.py +95 -14
- abstract_utilities/read_write_utils/__init__.py +1 -0
- abstract_utilities/read_write_utils/imports/__init__.py +2 -0
- abstract_utilities/read_write_utils/imports/imports.py +2 -0
- abstract_utilities/read_write_utils/imports/module_imports.py +5 -0
- abstract_utilities/read_write_utils/read_write_utils.py +439 -0
- abstract_utilities/read_write_utils.py +113 -62
- abstract_utilities/safe_utils/__init__.py +2 -0
- abstract_utilities/safe_utils/imports/__init__.py +3 -0
- abstract_utilities/safe_utils/imports/imports.py +2 -0
- abstract_utilities/safe_utils/imports/module_imports.py +2 -0
- abstract_utilities/safe_utils/safe_utils.py +166 -0
- abstract_utilities/ssh_utils/__init__.py +3 -1
- abstract_utilities/ssh_utils/classes.py +0 -1
- abstract_utilities/ssh_utils/cmd_utils.py +207 -0
- abstract_utilities/ssh_utils/imports/__init__.py +3 -0
- abstract_utilities/ssh_utils/imports/imports.py +5 -0
- abstract_utilities/ssh_utils/imports/module_imports.py +6 -0
- abstract_utilities/ssh_utils/imports/utils.py +189 -0
- abstract_utilities/ssh_utils/pexpect_utils.py +11 -18
- abstract_utilities/ssh_utils/type_checks.py +92 -0
- abstract_utilities/string_utils/__init__.py +4 -0
- abstract_utilities/string_utils/clean_utils.py +28 -0
- abstract_utilities/string_utils/eat_utils.py +103 -0
- abstract_utilities/string_utils/imports/__init__.py +3 -0
- abstract_utilities/string_utils/imports/imports.py +2 -0
- abstract_utilities/string_utils/imports/module_imports.py +2 -0
- abstract_utilities/string_utils/imports/utils.py +81 -0
- abstract_utilities/string_utils/replace_utils.py +27 -0
- abstract_utilities/string_utils.py +1 -1
- abstract_utilities/thread_utils/__init__.py +2 -0
- abstract_utilities/thread_utils/imports/__init__.py +2 -0
- abstract_utilities/thread_utils/imports/imports.py +2 -0
- abstract_utilities/thread_utils/imports/module_imports.py +2 -0
- abstract_utilities/thread_utils/thread_utils.py +140 -0
- abstract_utilities/time_utils/__init__.py +2 -0
- abstract_utilities/time_utils/imports/__init__.py +2 -0
- abstract_utilities/time_utils/imports/imports.py +3 -0
- abstract_utilities/time_utils/imports/module_imports.py +1 -0
- abstract_utilities/time_utils/time_utils.py +392 -0
- abstract_utilities/type_utils/__init__.py +7 -0
- abstract_utilities/type_utils/alpha_utils.py +59 -0
- abstract_utilities/type_utils/get_type.py +120 -0
- abstract_utilities/type_utils/imports/__init__.py +3 -0
- abstract_utilities/type_utils/imports/constants.py +134 -0
- abstract_utilities/type_utils/imports/imports.py +4 -0
- abstract_utilities/type_utils/imports/module_imports.py +25 -0
- abstract_utilities/type_utils/is_type.py +455 -0
- abstract_utilities/type_utils/make_type.py +126 -0
- abstract_utilities/type_utils/mime_types.py +68 -0
- abstract_utilities/type_utils/num_utils.py +19 -0
- abstract_utilities/type_utils/type_utils.py +104 -0
- {abstract_utilities-0.2.2.480.dist-info → abstract_utilities-0.2.2.688.dist-info}/METADATA +1 -1
- abstract_utilities-0.2.2.688.dist-info/RECORD +288 -0
- imports/__init__.py +36 -0
- abstract_utilities-0.2.2.480.dist-info/RECORD +0 -92
- {abstract_utilities-0.2.2.480.dist-info → abstract_utilities-0.2.2.688.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.480.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
|
+
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import os
|
|
1
|
+
from ...imports import os
|
|
2
2
|
from dotenv import load_dotenv
|
|
3
|
-
from ...
|
|
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 ...
|
|
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,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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ...log_utils import get_logger_callable
|
|
@@ -2,7 +2,8 @@ from .imports import *
|
|
|
2
2
|
|
|
3
3
|
def get_user_pass_host_key(**kwargs):
|
|
4
4
|
args = ['password','user_at_host','host','key','user']
|
|
5
|
-
|
|
5
|
+
kwargs['del_kwarg']=kwargs.get('del_kwarg',False)
|
|
6
|
+
values,kwargs = get_from_kwargs(*args,**kwargs)
|
|
6
7
|
return values
|
|
7
8
|
|
|
8
9
|
# --- Base remote checker -----------------------------------------------------
|
|
@@ -50,19 +50,20 @@ def is_file(
|
|
|
50
50
|
env_path=None,
|
|
51
51
|
**kwargs
|
|
52
52
|
):
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
if path:
|
|
54
|
+
contingencies = list(set([user_at_host,password,key,env_path]))
|
|
55
|
+
len_contingencies = len(contingencies)
|
|
56
|
+
is_potential = (len_contingencies >1 or (None not in contingencies))
|
|
57
|
+
if not is_potential:
|
|
58
|
+
return os.path.isfile(path)
|
|
59
|
+
cmd = get_item_check_cmd(path,file=True)
|
|
60
|
+
return run_cmd(cmd=cmd,
|
|
61
|
+
user_at_host=user_at_host,
|
|
62
|
+
password=password,
|
|
63
|
+
key=key,
|
|
64
|
+
env_path=env_path,
|
|
65
|
+
**kwargs
|
|
66
|
+
)
|
|
66
67
|
def is_dir(
|
|
67
68
|
path,
|
|
68
69
|
user_at_host=None,
|
|
@@ -71,34 +72,13 @@ def is_dir(
|
|
|
71
72
|
env_path=None,
|
|
72
73
|
**kwargs
|
|
73
74
|
):
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
user_at_host=user_at_host,
|
|
82
|
-
password=password,
|
|
83
|
-
key=key,
|
|
84
|
-
env_path=env_path,
|
|
85
|
-
**kwargs
|
|
86
|
-
)
|
|
87
|
-
def is_exists(
|
|
88
|
-
path,
|
|
89
|
-
user_at_host=None,
|
|
90
|
-
password=None,
|
|
91
|
-
key=None,
|
|
92
|
-
env_path=None,
|
|
93
|
-
**kwargs
|
|
94
|
-
):
|
|
95
|
-
contingencies = list(set([user_at_host,password,key,env_path]))
|
|
96
|
-
len_contingencies = len(contingencies)
|
|
97
|
-
is_potential = (len_contingencies >1 or (None not in contingencies))
|
|
98
|
-
if not is_potential:
|
|
99
|
-
return os.path.exists(path)
|
|
100
|
-
if is_potential == True:
|
|
101
|
-
cmd = get_item_check_cmd(path,exists=True)
|
|
75
|
+
if path:
|
|
76
|
+
contingencies = list(set([user_at_host,password,key,env_path]))
|
|
77
|
+
len_contingencies = len(contingencies)
|
|
78
|
+
is_potential = (len_contingencies >1 or (None not in contingencies))
|
|
79
|
+
if not is_potential:
|
|
80
|
+
return os.path.isdir(path)
|
|
81
|
+
cmd = get_item_check_cmd(path,file=False,directory=True)
|
|
102
82
|
return run_cmd(cmd=cmd,
|
|
103
83
|
user_at_host=user_at_host,
|
|
104
84
|
password=password,
|
|
@@ -106,7 +86,7 @@ def is_exists(
|
|
|
106
86
|
env_path=env_path,
|
|
107
87
|
**kwargs
|
|
108
88
|
)
|
|
109
|
-
def
|
|
89
|
+
def is_exists(
|
|
110
90
|
path,
|
|
111
91
|
user_at_host=None,
|
|
112
92
|
password=None,
|
|
@@ -114,25 +94,49 @@ def is_any(
|
|
|
114
94
|
env_path=None,
|
|
115
95
|
**kwargs
|
|
116
96
|
):
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
97
|
+
if path:
|
|
98
|
+
contingencies = list(set([user_at_host,password,key,env_path]))
|
|
99
|
+
len_contingencies = len(contingencies)
|
|
100
|
+
is_potential = (len_contingencies >1 or (None not in contingencies))
|
|
101
|
+
if not is_potential:
|
|
102
|
+
return os.path.exists(path)
|
|
103
|
+
if is_potential == True:
|
|
104
|
+
cmd = get_item_check_cmd(path,exists=True)
|
|
105
|
+
return run_cmd(cmd=cmd,
|
|
126
106
|
user_at_host=user_at_host,
|
|
127
107
|
password=password,
|
|
128
108
|
key=key,
|
|
129
109
|
env_path=env_path,
|
|
130
110
|
**kwargs
|
|
131
111
|
)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
112
|
+
def is_any(
|
|
113
|
+
path,
|
|
114
|
+
user_at_host=None,
|
|
115
|
+
password=None,
|
|
116
|
+
key=None,
|
|
117
|
+
env_path=None,
|
|
118
|
+
**kwargs
|
|
119
|
+
):
|
|
120
|
+
if path:
|
|
121
|
+
contingencies = list(set([user_at_host,password,key,env_path]))
|
|
122
|
+
len_contingencies = len(contingencies)
|
|
123
|
+
is_potential = (len_contingencies >1 or (None not in contingencies))
|
|
124
|
+
if not is_potential:
|
|
125
|
+
return os.path.exists(path)
|
|
126
|
+
if is_potential == True:
|
|
127
|
+
out_js = get_all_item_check_cmd(path,file=True,directory=True,exists=True)
|
|
128
|
+
for typ,cmd in out_js.items():
|
|
129
|
+
response = run_cmd(cmd=cmd,
|
|
130
|
+
user_at_host=user_at_host,
|
|
131
|
+
password=password,
|
|
132
|
+
key=key,
|
|
133
|
+
env_path=env_path,
|
|
134
|
+
**kwargs
|
|
135
|
+
)
|
|
136
|
+
result = "__OK__" in (response or "")
|
|
137
|
+
if result:
|
|
138
|
+
return typ
|
|
139
|
+
|
|
136
140
|
class PathBackend(Protocol):
|
|
137
141
|
def join(self, *parts: str) -> str: ...
|
|
138
142
|
def isfile(self, path: str) -> bool: ...
|