abstract-utilities 0.2.2.540__py3-none-any.whl → 0.2.2.667__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 +13 -4
- abstract_utilities/class_utils/abstract_classes.py +104 -34
- abstract_utilities/class_utils/caller_utils.py +57 -0
- abstract_utilities/class_utils/global_utils.py +35 -20
- abstract_utilities/class_utils/imports/imports.py +1 -1
- abstract_utilities/directory_utils/src/directory_utils.py +19 -1
- abstract_utilities/file_utils/imports/classes.py +59 -55
- abstract_utilities/file_utils/imports/imports.py +0 -4
- abstract_utilities/file_utils/imports/module_imports.py +1 -1
- abstract_utilities/file_utils/src/__init__.py +2 -3
- 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_reader.py +0 -1
- abstract_utilities/file_utils/src/find_collect.py +10 -86
- abstract_utilities/file_utils/src/find_content.py +210 -0
- abstract_utilities/file_utils/src/initFunctionsGen.py +36 -23
- abstract_utilities/file_utils/src/initFunctionsGens.py +280 -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/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 +1 -1
- abstract_utilities/import_utils/imports/init_imports.py +3 -0
- abstract_utilities/import_utils/imports/module_imports.py +4 -1
- abstract_utilities/import_utils/imports/utils.py +1 -1
- abstract_utilities/import_utils/src/__init__.py +1 -0
- abstract_utilities/import_utils/src/clean_imports.py +156 -25
- abstract_utilities/import_utils/src/dot_utils.py +11 -0
- abstract_utilities/import_utils/src/extract_utils.py +4 -0
- abstract_utilities/import_utils/src/import_functions.py +66 -2
- abstract_utilities/import_utils/src/import_utils.py +39 -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 +32 -0
- abstract_utilities/import_utils/src/nullProxy.py +30 -0
- abstract_utilities/import_utils/src/pkg_utils.py +58 -4
- abstract_utilities/import_utils/src/sysroot_utils.py +56 -1
- abstract_utilities/imports.py +3 -2
- abstract_utilities/json_utils/json_utils.py +11 -3
- abstract_utilities/log_utils/log_file.py +73 -24
- 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 +32 -35
- abstract_utilities/read_write_utils/imports/imports.py +1 -1
- abstract_utilities/read_write_utils/read_write_utils.py +102 -32
- abstract_utilities/safe_utils/safe_utils.py +30 -0
- abstract_utilities/type_utils/__init__.py +5 -1
- abstract_utilities/type_utils/get_type.py +116 -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.540.dist-info → abstract_utilities-0.2.2.667.dist-info}/METADATA +1 -1
- {abstract_utilities-0.2.2.540.dist-info → abstract_utilities-0.2.2.667.dist-info}/RECORD +66 -41
- {abstract_utilities-0.2.2.540.dist-info → abstract_utilities-0.2.2.667.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.540.dist-info → abstract_utilities-0.2.2.667.dist-info}/top_level.txt +0 -0
abstract_utilities/__init__.py
CHANGED
|
@@ -34,8 +34,7 @@ from .json_utils import (unified_json_loader,
|
|
|
34
34
|
get_result_from_data,
|
|
35
35
|
flatten_json
|
|
36
36
|
)
|
|
37
|
-
|
|
38
|
-
write_to_file)
|
|
37
|
+
|
|
39
38
|
from .directory_utils import *
|
|
40
39
|
from .path_utils import *
|
|
41
40
|
from .file_utils import *
|
|
@@ -84,7 +83,8 @@ from .type_utils import (make_bool,
|
|
|
84
83
|
get_numbers_comp,
|
|
85
84
|
is_any_instance,
|
|
86
85
|
break_string,
|
|
87
|
-
MIME_TYPES
|
|
86
|
+
MIME_TYPES,
|
|
87
|
+
get_if_None
|
|
88
88
|
)
|
|
89
89
|
get_media_types = get_all_types = get_all_file_types
|
|
90
90
|
from .math_utils import (convert_to_percentage,
|
|
@@ -108,7 +108,8 @@ from .parse_utils import (num_tokens_from_string,
|
|
|
108
108
|
chunk_any_to_tokens,
|
|
109
109
|
detect_language_from_text,
|
|
110
110
|
chunk_by_language_context,
|
|
111
|
-
search_code
|
|
111
|
+
search_code,
|
|
112
|
+
get_within_quotes)
|
|
112
113
|
|
|
113
114
|
from .log_utils import get_caller_info,get_logFile,print_or_log,get_json_call_response,initialize_call_log
|
|
114
115
|
from .error_utils import try_func
|
|
@@ -119,3 +120,11 @@ from .path_utils import *
|
|
|
119
120
|
from .file_utils import *
|
|
120
121
|
from .string_utils import *
|
|
121
122
|
from .import_utils import *
|
|
123
|
+
from .read_write_utils import (read_from_file,
|
|
124
|
+
write_to_file,
|
|
125
|
+
make_dirs,
|
|
126
|
+
make_dirs,
|
|
127
|
+
copy_files,
|
|
128
|
+
make_path,
|
|
129
|
+
run_cmd
|
|
130
|
+
)
|
|
@@ -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):
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
from .imports import *
|
|
2
|
+
|
|
3
|
+
def get_initial_caller() -> str:
|
|
4
|
+
"""
|
|
5
|
+
Return the TRUE original caller: the entrypoint script that launched the program.
|
|
6
|
+
"""
|
|
7
|
+
main_mod = sys.modules.get('__main__')
|
|
8
|
+
|
|
9
|
+
# interactive environments (REPL) may have no __file__
|
|
10
|
+
if not main_mod or not hasattr(main_mod, '__file__'):
|
|
11
|
+
return None
|
|
12
|
+
|
|
13
|
+
return os.path.realpath(main_mod.__file__)
|
|
14
|
+
def get_initial_caller_dir() -> str:
|
|
15
|
+
"""
|
|
16
|
+
Return the directory of the TRUE original entrypoint script.
|
|
17
|
+
"""
|
|
18
|
+
caller = get_initial_caller()
|
|
19
|
+
return os.path.dirname(caller) if caller else None
|
|
20
|
+
|
|
2
21
|
def get_caller(i: Optional[int] = None) -> str:
|
|
3
22
|
"""
|
|
4
23
|
Return the filename of the calling frame.
|
|
@@ -33,3 +52,41 @@ def get_caller_dir(i: Optional[int] = None) -> str:
|
|
|
33
52
|
depth = 1 if i is None else int(i)
|
|
34
53
|
abspath = get_caller_path(depth + 1)
|
|
35
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,26 +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()):
|
|
52
|
-
piece = get_globes(string=string,glob=glob)
|
|
53
|
-
if piece is None:
|
|
54
|
-
piece = default
|
|
55
|
-
return change_glob(var=string,val=piece,glob=glob)
|
|
56
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
|
|
1
|
+
from ...imports import inspect,os,json,functools,inspect,glob,sys,Path
|
|
2
2
|
from typing import *
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
from pathlib import Path
|
|
2
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
|
+
|
|
3
19
|
def get_dirs(path):
|
|
4
20
|
"""
|
|
5
21
|
Get List of Immediate Subdirectories in a Path
|
|
@@ -86,7 +102,9 @@ def raw_create_dirs(*paths):
|
|
|
86
102
|
current_path = safe_join(current_path, part)
|
|
87
103
|
os.makedirs(current_path, exist_ok=True)
|
|
88
104
|
return full_path
|
|
105
|
+
|
|
89
106
|
mkdirs=raw_create_dirs
|
|
90
107
|
makedirs = mkdirs
|
|
91
108
|
make_dirs = makedirs
|
|
109
|
+
makeAllDirs = raw_create_dirs
|
|
92
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: ...
|
|
@@ -4,5 +4,5 @@ from ...ssh_utils import *
|
|
|
4
4
|
from ...env_utils import *
|
|
5
5
|
from ...read_write_utils import read_from_file,write_to_file
|
|
6
6
|
from ...log_utils import get_logFile
|
|
7
|
-
from ...class_utils import get_caller, get_caller_path, get_caller_dir,SingletonMeta,run_pruned_func
|
|
7
|
+
from ...class_utils import if_none_default,if_none_change,get_caller,get_initial_caller_dir, get_caller_path, get_caller_dir,SingletonMeta,run_pruned_func
|
|
8
8
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from .file_filters import *
|
|
2
|
-
from .filter_params import *
|
|
3
2
|
from .map_utils import *
|
|
4
|
-
from .
|
|
5
|
-
from .file_reader import *
|
|
3
|
+
from .reader_utils import *
|
|
6
4
|
from .find_collect import *
|
|
5
|
+
from .find_content import *
|
|
7
6
|
from .initFunctionsGen import call_for_all_tabs,get_for_all_tabs
|
|
8
7
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .ensure_utils import *
|