abstract-utilities 0.2.2.593__py3-none-any.whl → 0.2.2.679__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 +18 -6
- abstract_utilities/class_utils/abstract_classes.py +104 -34
- abstract_utilities/class_utils/caller_utils.py +39 -0
- abstract_utilities/class_utils/global_utils.py +35 -21
- abstract_utilities/class_utils/imports/imports.py +1 -1
- abstract_utilities/directory_utils/src/directory_utils.py +2 -0
- abstract_utilities/file_utils/imports/classes.py +59 -55
- abstract_utilities/file_utils/imports/module_imports.py +1 -1
- abstract_utilities/file_utils/src/file_filters/__init__.py +0 -3
- abstract_utilities/file_utils/src/file_filters/ensure_utils.py +382 -10
- abstract_utilities/file_utils/src/file_filters/filter_params.py +64 -0
- abstract_utilities/file_utils/src/file_filters/predicate_utils.py +21 -91
- abstract_utilities/file_utils/src/find_collect.py +10 -0
- abstract_utilities/file_utils/src/initFunctionsGen.py +36 -23
- abstract_utilities/file_utils/src/initFunctionsGens.py +280 -0
- abstract_utilities/import_utils/imports/__init__.py +1 -1
- abstract_utilities/import_utils/imports/init_imports.py +3 -0
- abstract_utilities/import_utils/imports/module_imports.py +2 -1
- abstract_utilities/import_utils/imports/utils.py +1 -1
- abstract_utilities/import_utils/src/__init__.py +1 -0
- abstract_utilities/import_utils/src/extract_utils.py +2 -2
- abstract_utilities/import_utils/src/import_functions.py +30 -10
- abstract_utilities/import_utils/src/import_utils.py +41 -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/sysroot_utils.py +1 -1
- abstract_utilities/imports.py +5 -2
- abstract_utilities/json_utils/imports/imports.py +1 -1
- abstract_utilities/json_utils/json_utils.py +37 -3
- abstract_utilities/list_utils/list_utils.py +3 -0
- abstract_utilities/log_utils/log_file.py +137 -34
- abstract_utilities/parse_utils/parse_utils.py +23 -0
- abstract_utilities/path_utils/imports/module_imports.py +1 -1
- abstract_utilities/path_utils/path_utils.py +7 -12
- abstract_utilities/read_write_utils/imports/imports.py +1 -1
- abstract_utilities/read_write_utils/read_write_utils.py +137 -36
- abstract_utilities/type_utils/__init__.py +5 -1
- abstract_utilities/type_utils/get_type.py +120 -0
- abstract_utilities/type_utils/imports/__init__.py +1 -0
- abstract_utilities/type_utils/imports/constants.py +134 -0
- abstract_utilities/type_utils/imports/module_imports.py +25 -1
- 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/type_utils.py +0 -877
- {abstract_utilities-0.2.2.593.dist-info → abstract_utilities-0.2.2.679.dist-info}/METADATA +1 -1
- {abstract_utilities-0.2.2.593.dist-info → abstract_utilities-0.2.2.679.dist-info}/RECORD +51 -40
- {abstract_utilities-0.2.2.593.dist-info → abstract_utilities-0.2.2.679.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.593.dist-info → abstract_utilities-0.2.2.679.dist-info}/top_level.txt +0 -0
abstract_utilities/__init__.py
CHANGED
|
@@ -32,10 +32,10 @@ from .json_utils import (unified_json_loader,
|
|
|
32
32
|
safe_write_to_file,
|
|
33
33
|
safe_save_updated_json_data,
|
|
34
34
|
get_result_from_data,
|
|
35
|
-
flatten_json
|
|
35
|
+
flatten_json,
|
|
36
|
+
to_json_safe
|
|
36
37
|
)
|
|
37
|
-
|
|
38
|
-
write_to_file)
|
|
38
|
+
|
|
39
39
|
from .directory_utils import *
|
|
40
40
|
from .path_utils import *
|
|
41
41
|
from .file_utils import *
|
|
@@ -46,7 +46,9 @@ from .list_utils import (get_highest_value_obj,
|
|
|
46
46
|
compare_lists,
|
|
47
47
|
get_symetric_difference,
|
|
48
48
|
list_set,
|
|
49
|
-
make_list_it
|
|
49
|
+
make_list_it,
|
|
50
|
+
get_single_from_list
|
|
51
|
+
)
|
|
50
52
|
from .time_utils import (get_time_stamp,
|
|
51
53
|
get_sleep,
|
|
52
54
|
sleep_count_down,
|
|
@@ -84,7 +86,8 @@ from .type_utils import (make_bool,
|
|
|
84
86
|
get_numbers_comp,
|
|
85
87
|
is_any_instance,
|
|
86
88
|
break_string,
|
|
87
|
-
MIME_TYPES
|
|
89
|
+
MIME_TYPES,
|
|
90
|
+
get_if_None
|
|
88
91
|
)
|
|
89
92
|
get_media_types = get_all_types = get_all_file_types
|
|
90
93
|
from .math_utils import (convert_to_percentage,
|
|
@@ -108,7 +111,8 @@ from .parse_utils import (num_tokens_from_string,
|
|
|
108
111
|
chunk_any_to_tokens,
|
|
109
112
|
detect_language_from_text,
|
|
110
113
|
chunk_by_language_context,
|
|
111
|
-
search_code
|
|
114
|
+
search_code,
|
|
115
|
+
get_within_quotes)
|
|
112
116
|
|
|
113
117
|
from .log_utils import get_caller_info,get_logFile,print_or_log,get_json_call_response,initialize_call_log
|
|
114
118
|
from .error_utils import try_func
|
|
@@ -119,3 +123,11 @@ from .path_utils import *
|
|
|
119
123
|
from .file_utils import *
|
|
120
124
|
from .string_utils import *
|
|
121
125
|
from .import_utils import *
|
|
126
|
+
from .read_write_utils import (read_from_file,
|
|
127
|
+
write_to_file,
|
|
128
|
+
make_dirs,
|
|
129
|
+
make_dirs,
|
|
130
|
+
copy_files,
|
|
131
|
+
make_path,
|
|
132
|
+
run_cmd
|
|
133
|
+
)
|
|
@@ -26,47 +26,117 @@ def get_inputs(cls, *args, **kwargs):
|
|
|
26
26
|
return cls(**values)
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
from abstract_utilities import *
|
|
30
|
+
class SingletonMeta(type):
|
|
31
|
+
_instances = {}
|
|
32
|
+
def __call__(cls, *args, **kwargs):
|
|
33
|
+
if cls not in cls._instances:
|
|
34
|
+
cls._instances[cls] = super(SingletonMeta, cls).__call__(*args, **kwargs)
|
|
35
|
+
return cls._instances[cls]
|
|
36
|
+
|
|
37
|
+
def get_inputs(cls, *args, **kwargs):
|
|
38
|
+
"""
|
|
39
|
+
Dynamically construct a dataclass instance from args and kwargs,
|
|
40
|
+
filling missing values from defaults in the dataclass.
|
|
41
|
+
"""
|
|
42
|
+
fields = list(cls.__annotations__.keys())
|
|
43
|
+
values = {}
|
|
44
|
+
|
|
45
|
+
args = list(args)
|
|
46
|
+
for field in fields:
|
|
47
|
+
if field in kwargs:
|
|
48
|
+
values[field] = kwargs[field]
|
|
49
|
+
elif args:
|
|
50
|
+
values[field] = args.pop(0)
|
|
51
|
+
else:
|
|
52
|
+
values[field] = getattr(cls(), field) # default from dataclass
|
|
53
|
+
|
|
54
|
+
return cls(*args,**values)
|
|
55
|
+
def get_input_params(func):
|
|
56
|
+
sig = inspect.signature(func)
|
|
57
|
+
return sig.parameters
|
|
58
|
+
def get_args(func, *args,**kwargs):
|
|
59
|
+
parameters = get_input_params(func)
|
|
60
|
+
parameters = dict(parameters)
|
|
61
|
+
for key,value in parameters.items():
|
|
62
|
+
value = str(value)
|
|
63
|
+
if value.startswith('**'):
|
|
64
|
+
kwargs_key = key
|
|
65
|
+
elif value.startswith('*'):
|
|
66
|
+
args_key = key
|
|
67
|
+
kwargs_copy = kwargs.copy()
|
|
68
|
+
for k_key,k_value in kwargs.items():
|
|
69
|
+
if args_key == k_key and isinstance(k_value,list or tuple or set):
|
|
70
|
+
args = args | tuple(k_value)
|
|
71
|
+
del kwargs[k_key]
|
|
72
|
+
return args,kwargs
|
|
73
|
+
|
|
29
74
|
def prune_inputs(func, *args, **kwargs):
|
|
30
75
|
"""
|
|
31
|
-
|
|
32
|
-
|
|
76
|
+
Smart argument adapter:
|
|
77
|
+
- Detects if func accepts *args or **kwargs
|
|
78
|
+
- Builds new positional arguments from kwargs when appropriate
|
|
79
|
+
- Handles explicit {"args": [...]} convention
|
|
33
80
|
"""
|
|
81
|
+
|
|
34
82
|
sig = inspect.signature(func)
|
|
35
83
|
params = sig.parameters
|
|
36
84
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
new_args.extend(
|
|
50
|
-
break
|
|
85
|
+
has_varargs = any(p.kind == inspect.Parameter.VAR_POSITIONAL for p in params.values())
|
|
86
|
+
has_varkw = any(p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values())
|
|
87
|
+
|
|
88
|
+
new_args = list(args)
|
|
89
|
+
new_kwargs = dict(kwargs)
|
|
90
|
+
|
|
91
|
+
# -----------------------------------------------------------
|
|
92
|
+
# 1. If user provided explicit args: {"args": [...]}
|
|
93
|
+
# -----------------------------------------------------------
|
|
94
|
+
if "args" in new_kwargs:
|
|
95
|
+
explicit_args = new_kwargs.pop("args")
|
|
96
|
+
if isinstance(explicit_args, (list, tuple)):
|
|
97
|
+
new_args.extend(explicit_args)
|
|
51
98
|
else:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
new_args.append(explicit_args)
|
|
100
|
+
|
|
101
|
+
# -----------------------------------------------------------
|
|
102
|
+
# 2. If function has *args, infer which kwargs belong there
|
|
103
|
+
# -----------------------------------------------------------
|
|
104
|
+
if has_varargs:
|
|
105
|
+
|
|
106
|
+
# Heuristic rules for upgrading kwargs to args:
|
|
107
|
+
# - if the function has NO named params, treat all scalar kwargs as positional
|
|
108
|
+
# - common param names like "file_path" also qualify
|
|
109
|
+
preferred_as_args = {"path", "file", "file_path", "filename", "value"}
|
|
110
|
+
|
|
111
|
+
positional_candidates = []
|
|
112
|
+
|
|
113
|
+
for k in list(new_kwargs.keys()):
|
|
114
|
+
v = new_kwargs[k]
|
|
115
|
+
|
|
116
|
+
# candidate rules:
|
|
117
|
+
if k in preferred_as_args:
|
|
118
|
+
positional_candidates.append(v)
|
|
119
|
+
del new_kwargs[k]
|
|
120
|
+
|
|
121
|
+
# scalars but not mappings/lists (optional)
|
|
122
|
+
elif isinstance(v, (str, int, float)) and len(positional_candidates) == 0:
|
|
123
|
+
positional_candidates.append(v)
|
|
124
|
+
del new_kwargs[k]
|
|
125
|
+
|
|
126
|
+
new_args.extend(positional_candidates)
|
|
127
|
+
|
|
128
|
+
# -----------------------------------------------------------
|
|
129
|
+
# 3. If function does NOT accept **kwargs → strip extras
|
|
130
|
+
# -----------------------------------------------------------
|
|
131
|
+
if not has_varkw:
|
|
132
|
+
allowed = {
|
|
133
|
+
name for name, p in params.items()
|
|
134
|
+
if p.kind in (
|
|
135
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
136
|
+
inspect.Parameter.KEYWORD_ONLY
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
new_kwargs = {k: v for k, v in new_kwargs.items() if k in allowed}
|
|
70
140
|
|
|
71
141
|
return tuple(new_args), new_kwargs
|
|
72
142
|
def run_pruned_func(func, *args, **kwargs):
|
|
@@ -17,6 +17,7 @@ def get_initial_caller_dir() -> str:
|
|
|
17
17
|
"""
|
|
18
18
|
caller = get_initial_caller()
|
|
19
19
|
return os.path.dirname(caller) if caller else None
|
|
20
|
+
|
|
20
21
|
def get_caller(i: Optional[int] = None) -> str:
|
|
21
22
|
"""
|
|
22
23
|
Return the filename of the calling frame.
|
|
@@ -51,3 +52,41 @@ def get_caller_dir(i: Optional[int] = None) -> str:
|
|
|
51
52
|
depth = 1 if i is None else int(i)
|
|
52
53
|
abspath = get_caller_path(depth + 1)
|
|
53
54
|
return os.path.dirname(abspath)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_original_caller_dir(levels_up: int = None) -> Path:
|
|
58
|
+
"""
|
|
59
|
+
Return the directory of the *original* caller in the call stack.
|
|
60
|
+
|
|
61
|
+
levels_up:
|
|
62
|
+
- None → automatically goes to the bottom-most user-level caller.
|
|
63
|
+
- N → manually walk up N frames for custom behavior.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Path object pointing to caller's directory.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
stack = inspect.stack()
|
|
70
|
+
|
|
71
|
+
# If the user specifies an exact depth
|
|
72
|
+
if levels_up is not None:
|
|
73
|
+
target = min(levels_up + 1, len(stack) - 1)
|
|
74
|
+
frame = stack[target]
|
|
75
|
+
return Path(frame.filename).resolve().parent
|
|
76
|
+
|
|
77
|
+
# Otherwise, auto-detect the FIRST file that isn't inside site-packages or abstract_* utilities
|
|
78
|
+
for frameinfo in reversed(stack):
|
|
79
|
+
file_path = Path(frameinfo.filename).resolve()
|
|
80
|
+
|
|
81
|
+
# Skip internal interpreter/frame files
|
|
82
|
+
if "site-packages" in str(file_path):
|
|
83
|
+
continue
|
|
84
|
+
if "abstract_" in file_path.name:
|
|
85
|
+
continue
|
|
86
|
+
if file_path.name.startswith("<"):
|
|
87
|
+
continue
|
|
88
|
+
|
|
89
|
+
return file_path.parent
|
|
90
|
+
|
|
91
|
+
# Fallback: last entry in the stack
|
|
92
|
+
return Path(stack[-1].filename).resolve().parent
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import importlib, sys,os
|
|
2
|
+
from .caller_utils import get_initial_caller
|
|
3
|
+
def file_to_module_name(path):
|
|
4
|
+
path = os.path.realpath(path)
|
|
5
|
+
# Find a path that exists in sys.path
|
|
6
|
+
for base in sys.path:
|
|
7
|
+
base = os.path.realpath(base)
|
|
8
|
+
if path.startswith(base):
|
|
9
|
+
rel = os.path.relpath(path, base)
|
|
10
|
+
mod = os.path.splitext(rel)[0]
|
|
11
|
+
return mod.replace(os.sep, ".")
|
|
12
|
+
# fallback (never should be used)
|
|
13
|
+
return os.path.splitext(os.path.basename(path))[0]
|
|
14
|
+
def get_globals_from_path(module_path: str=None):
|
|
15
|
+
module_path = module_path or get_initial_caller()
|
|
16
|
+
module_name = file_to_module_name(module_path)
|
|
17
|
+
if module_name not in sys.modules:
|
|
18
|
+
importlib.import_module(module_name)
|
|
19
|
+
return sys.modules[module_name].__dict__
|
|
1
20
|
def global_registry(name:str,glob:dict):
|
|
2
21
|
global_ledger = if_none_default(string='global_ledger',glob=globals(),default={"registry_names":[],"registry_index":[]})
|
|
3
22
|
if name not in global_ledger['registry_names']:
|
|
@@ -31,27 +50,22 @@ def return_globals() -> dict:
|
|
|
31
50
|
dict: The global variables dictionary.
|
|
32
51
|
"""
|
|
33
52
|
return globals()
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var (str): The name of the global variable.
|
|
40
|
-
val (any): The new value.
|
|
41
|
-
glob (dict, optional): The dictionary of global variables. Defaults to the current globals.
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
any: The new value of the variable.
|
|
45
|
-
"""
|
|
53
|
+
def get_true_globals():
|
|
54
|
+
return sys.modules['__main__'].__dict__
|
|
55
|
+
def change_glob(var: str, val: any, glob: dict = None) -> any:
|
|
56
|
+
if glob is None:
|
|
57
|
+
glob = get_true_globals()
|
|
46
58
|
glob[var] = val
|
|
47
59
|
return val
|
|
48
|
-
def get_globes(string:str='',glob:dict=return_globals()):
|
|
49
|
-
if string in glob:
|
|
50
|
-
return glob[string]
|
|
51
|
-
def if_none_default(string:str, default:any,glob:dict=return_globals(),typ=None):
|
|
52
|
-
|
|
53
|
-
piece = get_globes(string=string,glob=glob)
|
|
54
|
-
if piece is None or (typ and not isinstance(piece,typ)):
|
|
55
|
-
piece = default
|
|
56
|
-
return change_glob(var=string,val=piece,glob=glob)
|
|
57
60
|
|
|
61
|
+
def get_globes(string: str='', glob: dict=None):
|
|
62
|
+
if glob is None:
|
|
63
|
+
glob = get_true_globals()
|
|
64
|
+
return glob.get(string)
|
|
65
|
+
def if_none_default(string: str, default: any, glob: dict=None, typ=None):
|
|
66
|
+
if glob is None:
|
|
67
|
+
glob = get_true_globals()
|
|
68
|
+
piece = get_globes(string=string, glob=glob)
|
|
69
|
+
if piece is None or (typ and not isinstance(piece, typ)):
|
|
70
|
+
piece = default
|
|
71
|
+
return change_glob(var=string, val=piece, glob=glob)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from ...imports import inspect,os,json,functools,inspect,glob,sys
|
|
1
|
+
from ...imports import inspect,os,json,functools,inspect,glob,sys,Path
|
|
2
2
|
from typing import *
|
|
@@ -102,7 +102,9 @@ def raw_create_dirs(*paths):
|
|
|
102
102
|
current_path = safe_join(current_path, part)
|
|
103
103
|
os.makedirs(current_path, exist_ok=True)
|
|
104
104
|
return full_path
|
|
105
|
+
|
|
105
106
|
mkdirs=raw_create_dirs
|
|
106
107
|
makedirs = mkdirs
|
|
107
108
|
make_dirs = makedirs
|
|
109
|
+
makeAllDirs = raw_create_dirs
|
|
108
110
|
|
|
@@ -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: ...
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from ...list_utils import make_list
|
|
2
|
-
from ...type_utils import get_media_exts, is_media_type, MIME_TYPES, is_str
|
|
2
|
+
from ...type_utils import get_media_exts, is_media_type, MIME_TYPES, is_str,if_not_bool_default
|
|
3
3
|
from ...ssh_utils import *
|
|
4
4
|
from ...env_utils import *
|
|
5
5
|
from ...read_write_utils import read_from_file,write_to_file
|