abstract-utilities 0.2.2.448__tar.gz → 0.2.2.450__tar.gz
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-0.2.2.448 → abstract_utilities-0.2.2.450}/PKG-INFO +3 -5
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/pyproject.toml +1 -1
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/setup.cfg +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/setup.py +3 -3
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/__init__.py +43 -17
- abstract_utilities-0.2.2.450/src/abstract_utilities/abstract_classes.py +24 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/class_utils.py +3 -39
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/cmd_utils/user_utils.py +1 -1
- {abstract_utilities-0.2.2.448/src/abstract_utilities/compare_utils → abstract_utilities-0.2.2.450/src/abstract_utilities}/compare_utils.py +1 -1
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/dynimport.py +15 -7
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/json_utils.py +0 -35
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/log_utils.py +3 -14
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/path_utils.py +6 -90
- abstract_utilities-0.2.2.450/src/abstract_utilities/read_write_utils.py +199 -0
- abstract_utilities-0.2.2.450/src/abstract_utilities/robust_reader/__init__.py +2 -0
- {abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils → abstract_utilities-0.2.2.450/src/abstract_utilities/robust_reader}/file_reader.py +19 -5
- {abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils → abstract_utilities-0.2.2.450/src/abstract_utilities/robust_reader}/pdf_utils.py +9 -1
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/__init__.py +1 -0
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils/file_utils.py → abstract_utilities-0.2.2.450/src/abstract_utilities/robust_readers/file_filters.py +1 -2
- {abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils → abstract_utilities-0.2.2.450/src/abstract_utilities/robust_readers}/filter_params.py +38 -1
- abstract_utilities-0.2.2.450/src/abstract_utilities/robust_readers/initFuncGen.py +135 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/type_utils.py +1 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities.egg-info/PKG-INFO +3 -5
- abstract_utilities-0.2.2.450/src/abstract_utilities.egg-info/SOURCES.txt +54 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities.egg-info/requires.txt +1 -3
- abstract_utilities-0.2.2.448/src/abstract_utilities/abstract_classes.py +0 -73
- abstract_utilities-0.2.2.448/src/abstract_utilities/cmd_utils/imports/__init__.py +0 -1
- abstract_utilities-0.2.2.448/src/abstract_utilities/cmd_utils/imports/imports.py +0 -10
- abstract_utilities-0.2.2.448/src/abstract_utilities/cmd_utils/pexpect_utils.py +0 -310
- abstract_utilities-0.2.2.448/src/abstract_utilities/compare_utils/__init__.py +0 -3
- abstract_utilities-0.2.2.448/src/abstract_utilities/compare_utils/best_match.py +0 -150
- abstract_utilities-0.2.2.448/src/abstract_utilities/compare_utils/find_value.py +0 -105
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/__init__.py +0 -3
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/abstractEnv.py +0 -129
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/envy_it.py +0 -33
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/imports/__init__.py +0 -2
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/imports/imports.py +0 -8
- abstract_utilities-0.2.2.448/src/abstract_utilities/env_utils/imports/utils.py +0 -122
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/__init__.py +0 -3
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils/__init__.py +0 -6
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils/file_filters.py +0 -104
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils/imports.py +0 -1
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/file_utils/map_utils.py +0 -29
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/__init__.py +0 -5
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/classes.py +0 -381
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/constants.py +0 -39
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/file_functions.py +0 -10
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/imports.py +0 -14
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/imports/module_imports.py +0 -9
- abstract_utilities-0.2.2.448/src/abstract_utilities/file_utils/req.py +0 -329
- abstract_utilities-0.2.2.448/src/abstract_utilities/read_write_utils.py +0 -142
- abstract_utilities-0.2.2.448/src/abstract_utilities/robust_reader/__init__.py +0 -2
- abstract_utilities-0.2.2.448/src/abstract_utilities/robust_reader/imports/__init__.py +0 -1
- abstract_utilities-0.2.2.448/src/abstract_utilities/robust_reader/imports/imports.py +0 -12
- abstract_utilities-0.2.2.448/src/abstract_utilities/robust_readers/imports.py +0 -8
- abstract_utilities-0.2.2.448/src/abstract_utilities/robust_readers/initFuncGen.py +0 -143
- abstract_utilities-0.2.2.448/src/abstract_utilities/safe_utils.py +0 -133
- abstract_utilities-0.2.2.448/src/abstract_utilities/ssh_utils/__init__.py +0 -3
- abstract_utilities-0.2.2.448/src/abstract_utilities/ssh_utils/classes.py +0 -127
- abstract_utilities-0.2.2.448/src/abstract_utilities/ssh_utils/imports.py +0 -10
- abstract_utilities-0.2.2.448/src/abstract_utilities/ssh_utils/pexpect_utils.py +0 -315
- abstract_utilities-0.2.2.448/src/abstract_utilities/ssh_utils/utils.py +0 -188
- abstract_utilities-0.2.2.448/src/abstract_utilities/string_utils.py +0 -12
- abstract_utilities-0.2.2.448/src/abstract_utilities.egg-info/SOURCES.txt +0 -88
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/README.md +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/cmd_utils/__init__.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/cmd_utils/cmd_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/collator_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/doit.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/error_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/global_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/hash_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/history_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/list_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/math_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/parse_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_reader/file_reader2.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_reader/file_readers.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_reader/sadfsad.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/__init__.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/dot_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/function_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/import_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/impot_functions.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/safe_import_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/sysroot_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/robust_readers/import_utils/utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/string_clean.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/tetsts.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/thread_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/time_utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/utils.py +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities.egg-info/dependency_links.txt +0 -0
- {abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: abstract_utilities
|
|
3
|
-
Version: 0.2.2.
|
|
3
|
+
Version: 0.2.2.450
|
|
4
4
|
Summary: abstract_utilities is a collection of utility modules providing a variety of functions to aid in tasks such as data comparison, list manipulation, JSON handling, string manipulation, mathematical computations, and time operations.
|
|
5
5
|
Home-page: https://github.com/AbstractEndeavors/abstract_utilities
|
|
6
6
|
Author: putkoff
|
|
@@ -10,12 +10,10 @@ Classifier: Intended Audience :: Developers
|
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Requires-Python: >=3.
|
|
13
|
+
Requires-Python: >=3.6
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
|
-
Requires-Dist: pathlib>=1.0.1
|
|
16
|
-
Requires-Dist: abstract_security>=0.0.1
|
|
17
|
-
Requires-Dist: yt_dlp>=2023.10.13
|
|
18
15
|
Requires-Dist: pexpect>=4.8.0
|
|
16
|
+
Requires-Dist: abstract_security>=0.0.1
|
|
19
17
|
Dynamic: author
|
|
20
18
|
Dynamic: author-email
|
|
21
19
|
Dynamic: classifier
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
4
4
|
long_description = fh.read()
|
|
5
5
|
setuptools.setup(
|
|
6
6
|
name='abstract_utilities',
|
|
7
|
-
version='0.2.2.
|
|
7
|
+
version='0.2.2.450',
|
|
8
8
|
author='putkoff',
|
|
9
9
|
author_email='partners@abstractendeavors.com',
|
|
10
10
|
description='abstract_utilities is a collection of utility modules providing a variety of functions to aid in tasks such as data comparison, list manipulation, JSON handling, string manipulation, mathematical computations, and time operations.',
|
|
@@ -18,10 +18,10 @@ setuptools.setup(
|
|
|
18
18
|
'Programming Language :: Python :: 3',
|
|
19
19
|
'Programming Language :: Python :: 3.11',
|
|
20
20
|
],
|
|
21
|
-
install_requires=['
|
|
21
|
+
install_requires=['pexpect>=4.8.0', 'abstract_security>=0.0.1'],
|
|
22
22
|
package_dir={"": "src"},
|
|
23
23
|
packages=setuptools.find_packages(where="src"),
|
|
24
|
-
python_requires=">=3.
|
|
24
|
+
python_requires=">=3.6",
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
)
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/__init__.py
RENAMED
|
@@ -3,9 +3,8 @@ from datetime import timedelta
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from typing import *
|
|
5
5
|
from .hash_utils import *
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from .dynimport import get_abstract_import
|
|
6
|
+
from .dynimport import get_abstract_import,import_symbols_to_parent,call_for_all_tabs
|
|
7
|
+
|
|
9
8
|
from .json_utils import (unified_json_loader,
|
|
10
9
|
find_keys,
|
|
11
10
|
get_key_values_from_path,
|
|
@@ -41,8 +40,42 @@ from .json_utils import (unified_json_loader,
|
|
|
41
40
|
)
|
|
42
41
|
from .read_write_utils import (read_from_file,
|
|
43
42
|
write_to_file)
|
|
44
|
-
from .path_utils import
|
|
45
|
-
|
|
43
|
+
from .path_utils import (get_file_create_time,
|
|
44
|
+
get_files,
|
|
45
|
+
get_folders,
|
|
46
|
+
path_join,
|
|
47
|
+
mkdirs,
|
|
48
|
+
split_text,
|
|
49
|
+
get_all_item_paths,
|
|
50
|
+
get_directory_items,
|
|
51
|
+
get_files,
|
|
52
|
+
get_folders,
|
|
53
|
+
break_down_find_existing,
|
|
54
|
+
get_directory_items,
|
|
55
|
+
get_directory_files,
|
|
56
|
+
get_all_item_paths,
|
|
57
|
+
get_all_file_paths,
|
|
58
|
+
get_directory,
|
|
59
|
+
create_directory,
|
|
60
|
+
initialize_file,
|
|
61
|
+
join_path,
|
|
62
|
+
is_last_itter,
|
|
63
|
+
path_join,
|
|
64
|
+
is_file,
|
|
65
|
+
is_dir,
|
|
66
|
+
is_path,
|
|
67
|
+
get_all_directories,
|
|
68
|
+
get_all_files,
|
|
69
|
+
get_all_items,
|
|
70
|
+
collate_text_docs,
|
|
71
|
+
get_dirlist,
|
|
72
|
+
get_content,
|
|
73
|
+
is_directory_in_paths,
|
|
74
|
+
make_dirs,
|
|
75
|
+
remove_directory,
|
|
76
|
+
remove_path,
|
|
77
|
+
get_file_parts
|
|
78
|
+
)
|
|
46
79
|
from .list_utils import (get_highest_value_obj,
|
|
47
80
|
make_list,
|
|
48
81
|
safe_list_return,
|
|
@@ -87,8 +120,7 @@ from .type_utils import (make_bool,
|
|
|
87
120
|
get_numbers,
|
|
88
121
|
get_numbers_comp,
|
|
89
122
|
is_any_instance,
|
|
90
|
-
break_string
|
|
91
|
-
MIME_TYPES
|
|
123
|
+
break_string
|
|
92
124
|
)
|
|
93
125
|
get_media_types = get_all_types = get_all_file_types
|
|
94
126
|
from .math_utils import (convert_to_percentage,
|
|
@@ -100,10 +132,7 @@ from .math_utils import (convert_to_percentage,
|
|
|
100
132
|
return_0)
|
|
101
133
|
from .compare_utils import (create_new_name,
|
|
102
134
|
get_last_comp_list,
|
|
103
|
-
get_closest_match_from_list
|
|
104
|
-
get_first_match,
|
|
105
|
-
get_all_match,
|
|
106
|
-
best_match)
|
|
135
|
+
get_closest_match_from_list)
|
|
107
136
|
from .thread_utils import ThreadManager
|
|
108
137
|
from .history_utils import HistoryManager
|
|
109
138
|
from .abstract_classes import *
|
|
@@ -117,9 +146,6 @@ from .parse_utils import (num_tokens_from_string,
|
|
|
117
146
|
from .log_utils import get_caller_info,get_logFile,print_or_log,get_json_call_response,initialize_call_log
|
|
118
147
|
from .error_utils import try_func
|
|
119
148
|
from .class_utils import alias,get_class_inputs,get_set_attr
|
|
120
|
-
from .
|
|
121
|
-
from .
|
|
122
|
-
|
|
123
|
-
from .file_utils import *
|
|
124
|
-
from .file_utils import call_for_all_tabs
|
|
125
|
-
from .string_utils import *
|
|
149
|
+
from .robust_reader import *
|
|
150
|
+
from .robust_readers import *
|
|
151
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class SingletonMeta(type):
|
|
2
|
+
_instances = {}
|
|
3
|
+
def __call__(cls, *args, **kwargs):
|
|
4
|
+
if cls not in cls._instances:
|
|
5
|
+
cls._instances[cls] = super(SingletonMeta, cls).__call__(*args, **kwargs)
|
|
6
|
+
return cls._instances[cls]
|
|
7
|
+
def get_inputs(cls, *args, **kwargs):
|
|
8
|
+
"""
|
|
9
|
+
Dynamically construct a dataclass instance from args and kwargs,
|
|
10
|
+
filling missing values from defaults in the dataclass.
|
|
11
|
+
"""
|
|
12
|
+
fields = list(cls.__annotations__.keys())
|
|
13
|
+
values = {}
|
|
14
|
+
|
|
15
|
+
args = list(args)
|
|
16
|
+
for field in fields:
|
|
17
|
+
if field in kwargs:
|
|
18
|
+
values[field] = kwargs[field]
|
|
19
|
+
elif args:
|
|
20
|
+
values[field] = args.pop(0)
|
|
21
|
+
else:
|
|
22
|
+
values[field] = getattr(cls(), field) # default from dataclass
|
|
23
|
+
|
|
24
|
+
return cls(**values)
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/class_utils.py
RENAMED
|
@@ -44,9 +44,9 @@ Dependencies:
|
|
|
44
44
|
Each function is furnished with its own docstring that elaborates on its purpose, expected inputs, and outputs.
|
|
45
45
|
|
|
46
46
|
"""
|
|
47
|
-
import
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
import inspect
|
|
48
|
+
import json
|
|
49
|
+
import functools
|
|
50
50
|
def get_type_list() -> list:
|
|
51
51
|
"""Get a list of common Python types."""
|
|
52
52
|
return ['None','str','int','float','bool','list','tuple','set','dict','frozenset','bytearray','bytes','memoryview','range','enumerate','zip','filter','map','property','slice','super','type','Exception','object']
|
|
@@ -370,39 +370,3 @@ def get_class_inputs(cls, *args, **kwargs):
|
|
|
370
370
|
else:
|
|
371
371
|
values[field] = getattr(cls(), field)
|
|
372
372
|
return cls(**values)
|
|
373
|
-
def get_caller(i: Optional[int] = None) -> str:
|
|
374
|
-
"""
|
|
375
|
-
Return the filename of the calling frame.
|
|
376
|
-
|
|
377
|
-
Args:
|
|
378
|
-
i: Optional stack depth offset.
|
|
379
|
-
None = immediate caller (depth 1).
|
|
380
|
-
|
|
381
|
-
Returns:
|
|
382
|
-
Absolute path of the file for the stack frame.
|
|
383
|
-
"""
|
|
384
|
-
depth = 1 if i is None else int(i)
|
|
385
|
-
stack = inspect.stack()
|
|
386
|
-
if depth >= len(stack):
|
|
387
|
-
depth = len(stack) - 1
|
|
388
|
-
return stack[depth].filename
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
def get_caller_path(i: Optional[int] = None) -> str:
|
|
392
|
-
"""
|
|
393
|
-
Return the absolute path of the caller's file.
|
|
394
|
-
"""
|
|
395
|
-
depth = 1 if i is None else int(i)
|
|
396
|
-
file_path = get_caller(depth + 1)
|
|
397
|
-
return os.path.realpath(file_path)
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
def get_caller_dir(i: Optional[int] = None) -> str:
|
|
401
|
-
"""
|
|
402
|
-
Return the absolute directory of the caller's file.
|
|
403
|
-
"""
|
|
404
|
-
depth = 1 if i is None else int(i)
|
|
405
|
-
abspath = get_caller_path(depth + 1)
|
|
406
|
-
return os.path.dirname(abspath)
|
|
407
|
-
|
|
408
|
-
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/dynimport.py
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# abstract_utilities/dynimport.py
|
|
2
2
|
from __future__ import annotations
|
|
3
|
+
import importlib, sys, os
|
|
3
4
|
from functools import lru_cache
|
|
4
|
-
from typing import
|
|
5
|
-
import
|
|
6
|
-
from typing import Optional
|
|
5
|
+
from typing import Any, Callable, Iterable, Optional
|
|
6
|
+
import inspect, sys
|
|
7
7
|
from importlib import import_module
|
|
8
8
|
from .type_utils import make_list
|
|
9
|
-
|
|
9
|
+
from .robust_readers import get_for_all_tabs,call_for_all_tabs
|
|
10
10
|
class _LazyAttr:
|
|
11
11
|
"""Lazy resolver proxy to avoid import-time cycles.
|
|
12
12
|
First use triggers actual import & attribute lookup.
|
|
@@ -181,6 +181,14 @@ def get_many_module_imports(*args):
|
|
|
181
181
|
all_modules[symbol] = get_abstract_import(module = module,symbol=symbol)
|
|
182
182
|
import_symbols(all_modules)
|
|
183
183
|
return all_modules
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
def get_caller_path():
|
|
185
|
+
frame = inspect.stack()[1]
|
|
186
|
+
return os.path.abspath(frame.filename)
|
|
187
|
+
def get_caller_dir():
|
|
188
|
+
frame = inspect.stack()[1]
|
|
189
|
+
abspath = os.path.abspath(frame.filename)
|
|
190
|
+
return os.path.dirname(abspath)
|
|
191
|
+
def call_for_all_tabs():
|
|
192
|
+
|
|
193
|
+
root = get_caller_dir()
|
|
194
|
+
get_for_all_tabs(root)
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/json_utils.py
RENAMED
|
@@ -188,41 +188,6 @@ def find_keys(data, target_keys):
|
|
|
188
188
|
values = []
|
|
189
189
|
_find_keys_recursive(data, target_keys, values)
|
|
190
190
|
return values
|
|
191
|
-
def try_json_dumps_spec(obj, logger=True, level='error', file_path=None, **kwargs):
|
|
192
|
-
"""
|
|
193
|
-
Attempts to serialize an object to JSON using json.dumps or json.dump.
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
obj: The Python object to serialize (e.g., dict, list, str, int, etc.).
|
|
197
|
-
logger: Logger object or None to use _default_logger.
|
|
198
|
-
level: Logging level for errors (default: 'error').
|
|
199
|
-
file_path: If provided, writes JSON to this file using json.dump.
|
|
200
|
-
**kwargs: Additional arguments to pass to json.dumps or json.dump (e.g., indent, sort_keys).
|
|
201
|
-
|
|
202
|
-
Returns:
|
|
203
|
-
str: The JSON-serialized string if file_path is None and serialization succeeds.
|
|
204
|
-
None: If serialization fails or file_path is provided (in which case it writes to the file).
|
|
205
|
-
|
|
206
|
-
Raises:
|
|
207
|
-
ValueError: If file_path is provided but the file cannot be written.
|
|
208
|
-
"""
|
|
209
|
-
|
|
210
|
-
try:
|
|
211
|
-
if file_path:
|
|
212
|
-
# Use json.dump to write to a file
|
|
213
|
-
with open(file_path, 'w', encoding='utf-8') as f:
|
|
214
|
-
json.dump(obj, f, **kwargs)
|
|
215
|
-
return None
|
|
216
|
-
else:
|
|
217
|
-
# Use json.dumps to return a string
|
|
218
|
-
return json.dumps(obj)
|
|
219
|
-
except (TypeError, OverflowError, ValueError) as e:
|
|
220
|
-
if log_callable:
|
|
221
|
-
print_or_log(f"Exception in json.dumps/dump: {e}")
|
|
222
|
-
return None
|
|
223
|
-
def run_it(endpoint,**kwargs):
|
|
224
|
-
response= make_request_link('typicaly',endpoint,data=kwargs)
|
|
225
|
-
return response
|
|
226
191
|
def get_logNone(e):
|
|
227
192
|
logger(f"{e}")
|
|
228
193
|
return None
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/log_utils.py
RENAMED
|
@@ -5,17 +5,6 @@ from flask import jsonify
|
|
|
5
5
|
from .path_utils import mkdirs
|
|
6
6
|
from logging.handlers import RotatingFileHandler
|
|
7
7
|
from .abstract_classes import SingletonMeta
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
def _normalize(obj):
|
|
11
|
-
"""Recursively turn PosixPath into str, sets into list, etc."""
|
|
12
|
-
if isinstance(obj, Path):
|
|
13
|
-
return str(obj)
|
|
14
|
-
if isinstance(obj, dict):
|
|
15
|
-
return {k: _normalize(v) for k, v in obj.items()}
|
|
16
|
-
if isinstance(obj, (list, tuple, set)):
|
|
17
|
-
return [_normalize(x) for x in obj]
|
|
18
|
-
return obj
|
|
19
8
|
|
|
20
9
|
|
|
21
10
|
# from abstract_utilities import get_logFile # Potential conflict - consider removing or renaming
|
|
@@ -229,11 +218,11 @@ def initialize_call_log(value=None,
|
|
|
229
218
|
|
|
230
219
|
print_or_log(full_message,level=log_level)
|
|
231
220
|
|
|
232
|
-
def get_json_call_response(value
|
|
221
|
+
def get_json_call_response(value, status_code, data=None,logMsg=None,callLog = False):
|
|
233
222
|
response_body = {}
|
|
234
223
|
if status_code == 200:
|
|
235
224
|
response_body["success"] = True
|
|
236
|
-
response_body["result"] =
|
|
225
|
+
response_body["result"] = value
|
|
237
226
|
logMsg = logMsg or "success"
|
|
238
227
|
if callLog:
|
|
239
228
|
initialize_call_log(value=value,
|
|
@@ -242,7 +231,7 @@ def get_json_call_response(value=None, status_code=None, data=None, logMsg=None,
|
|
|
242
231
|
log_level='info')
|
|
243
232
|
else:
|
|
244
233
|
response_body["success"] = False
|
|
245
|
-
response_body["error"] =
|
|
234
|
+
response_body["error"] = value
|
|
246
235
|
logMsg = logMsg or f"ERROR: {logMsg}"
|
|
247
236
|
initialize_call_log(value=value,
|
|
248
237
|
data=data,
|
{abstract_utilities-0.2.2.448 → abstract_utilities-0.2.2.450}/src/abstract_utilities/path_utils.py
RENAMED
|
@@ -23,13 +23,8 @@ Date: 05/31/2023
|
|
|
23
23
|
Version: 0.1.2
|
|
24
24
|
"""
|
|
25
25
|
import os
|
|
26
|
-
|
|
27
|
-
from .
|
|
28
|
-
from .list_utils import make_list
|
|
29
|
-
from .type_utils import get_media_exts, is_media_type,MIME_TYPES
|
|
30
|
-
from .safe_utils import safe_join
|
|
31
|
-
from .class_utils import get_caller_path,get_caller_dir
|
|
32
|
-
|
|
26
|
+
import platform
|
|
27
|
+
from .read_write_utils import read_from_file
|
|
33
28
|
def get_os_info():
|
|
34
29
|
"""
|
|
35
30
|
Get Operating System Information
|
|
@@ -577,87 +572,8 @@ def remove_path(path=None):
|
|
|
577
572
|
remove_directory(path)
|
|
578
573
|
else:
|
|
579
574
|
os.remove(path)
|
|
580
|
-
def get_safe_dirname(path=None):
|
|
581
|
-
if path:
|
|
582
|
-
path_str = str(path)
|
|
583
|
-
return os.path.dirname(path_str)
|
|
584
|
-
def get_safe_basename(path=None):
|
|
585
|
-
if path:
|
|
586
|
-
path_str = str(path)
|
|
587
|
-
return os.path.basename(path_str)
|
|
588
|
-
def get_safe_splitext(path=None,basename=None):
|
|
589
|
-
basename = basename or get_safe_basename(path=path)
|
|
590
|
-
if basename:
|
|
591
|
-
basename_str = str(basename)
|
|
592
|
-
filename,ext = os.path.splitext(basename_str)
|
|
593
|
-
return filename,ext
|
|
594
|
-
def get_safe_filename(path=None,basename=None):
|
|
595
|
-
filename,_ = get_safe_splitext(path=path,basename=basename)
|
|
596
|
-
return filename
|
|
597
|
-
def get_safe_ext(path=None,basename=None):
|
|
598
|
-
_,ext = get_safe_splitext(path=path,basename=basename)
|
|
599
|
-
return ext
|
|
600
|
-
def raw_create_dirs(*paths):
|
|
601
|
-
"""Recursively create all directories along the given path."""
|
|
602
|
-
full_path = os.path.abspath(safe_join(*paths))
|
|
603
|
-
sub_parts = [p for p in full_path.split(os.sep) if p]
|
|
604
|
-
|
|
605
|
-
current_path = "/" if full_path.startswith(os.sep) else ""
|
|
606
|
-
for part in sub_parts:
|
|
607
|
-
current_path = safe_join(current_path, part)
|
|
608
|
-
os.makedirs(current_path, exist_ok=True)
|
|
609
|
-
return full_path
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
def create_dirs(directory, child=None):
|
|
613
|
-
"""Create directory and optional child path safely."""
|
|
614
|
-
full_path = os.path.abspath(safe_join(directory, child))
|
|
615
|
-
if not os.path.exists(full_path):
|
|
616
|
-
raw_create_dirs(full_path)
|
|
617
|
-
return full_path
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
def get_base_dir(directory=None):
|
|
621
|
-
"""Return given directory or _BASE_DIR fallback."""
|
|
622
|
-
return directory or _BASE_DIR
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
def create_base_path(directory=None, child=None):
|
|
626
|
-
"""Join base dir with child."""
|
|
627
|
-
directory = get_base_dir(directory)
|
|
628
|
-
return safe_join(directory, child)
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
def create_base_dir(directory=None, child=None):
|
|
632
|
-
"""Ensure existence of base directory path."""
|
|
633
|
-
full_path = create_base_path(directory, child)
|
|
634
|
-
if not os.path.exists(full_path):
|
|
635
|
-
raw_create_dirs(full_path)
|
|
636
|
-
return full_path
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
575
|
def get_file_parts(path):
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
dirname = get_safe_dirname(path)
|
|
646
|
-
dirbase = get_safe_basename(dirname)
|
|
647
|
-
|
|
648
|
-
parent_dirname = get_safe_dirname(dirname)
|
|
649
|
-
parent_dirbase = get_safe_basename(parent_dirname)
|
|
650
|
-
|
|
651
|
-
super_dirname = get_safe_dirname(parent_dirname)
|
|
652
|
-
super_dirbase = get_safe_basename(super_dirname)
|
|
653
|
-
|
|
654
|
-
return {"dirname": dirname,
|
|
655
|
-
"basename": basename,
|
|
656
|
-
"filename": filename,
|
|
657
|
-
"ext": ext,
|
|
658
|
-
"dirbase":dirbase,
|
|
659
|
-
"parent_dirname":parent_dirname,
|
|
660
|
-
"parent_dirbase":parent_dirbase,
|
|
661
|
-
"super_dirname":super_dirname,
|
|
662
|
-
"super_dirbase":super_dirbase
|
|
663
|
-
}
|
|
576
|
+
dirName = os.path.dirname(path)
|
|
577
|
+
baseName = os.path.basename(path)
|
|
578
|
+
fileName, ext = os.path.splitext(baseName)
|
|
579
|
+
return {"dirName": dirName, "baseName": baseName, "fileName": fileName, "ext": ext}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""
|
|
2
|
+
read_write_utils.py
|
|
3
|
+
|
|
4
|
+
This module, 'read_write_utils.py', provides utility functions for reading and writing to files.
|
|
5
|
+
These include functions to:
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
import abstract_utilities.read_write_utils as read_write_utils
|
|
9
|
+
|
|
10
|
+
1. Write content to a file.
|
|
11
|
+
2. Read content from a file.
|
|
12
|
+
3. Check if a string has a file extension.
|
|
13
|
+
4. Read from or write to a file depending on the number of arguments.
|
|
14
|
+
5. Create a file if it does not exist, then read from it.
|
|
15
|
+
|
|
16
|
+
Each function includes a docstring to further explain its purpose, input parameters, and return values.
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
# File and Directory Operations
|
|
20
|
+
os.rename(src, dst) # Rename a file or directory
|
|
21
|
+
os.remove(path) # Remove a file
|
|
22
|
+
os.unlink(path) # Alias for os.remove()
|
|
23
|
+
os.rmdir(path) # Remove an empty directory
|
|
24
|
+
os.makedirs(path) # Create directories recursively
|
|
25
|
+
os.makedirs(path, exist_ok=True) # Create directories, ignore if exists
|
|
26
|
+
os.mkdir(path) # Create a single directory
|
|
27
|
+
os.listdir(path) # List files and directories in a path
|
|
28
|
+
os.chdir(path) # Change current working directory
|
|
29
|
+
os.getcwd() # Get current working directory
|
|
30
|
+
os.stat(path) # Get file/directory information
|
|
31
|
+
os.lstat(path) # Get symbolic link information
|
|
32
|
+
os.symlink(src, dst) # Create a symbolic link
|
|
33
|
+
os.readlink(path) # Read the target of a symbolic link
|
|
34
|
+
os.getcwd() # Get current working directory
|
|
35
|
+
os.chdir(path) # Change current working directory
|
|
36
|
+
|
|
37
|
+
# File and Directory Information
|
|
38
|
+
os.path.exists(path) # Check if a path exists
|
|
39
|
+
os.path.isfile(path) # Check if a path points to a file
|
|
40
|
+
os.path.isdir(path) # Check if a path points to a directory
|
|
41
|
+
os.path.islink(path) # Check if a path points to a symbolic link
|
|
42
|
+
os.path.abspath(path) # Get the absolute path of a file/directory
|
|
43
|
+
os.path.basename(path) # Get the base name of a path
|
|
44
|
+
os.path.dirname(path) # Get the directory name of a path
|
|
45
|
+
os.path.join(path1, path2, ...) # Join path components into a single path
|
|
46
|
+
|
|
47
|
+
# File Permissions
|
|
48
|
+
os.chmod(path, mode) # Change file permissions
|
|
49
|
+
os.access(path, mode) # Check if a file is accessible with given mode
|
|
50
|
+
|
|
51
|
+
# File Times
|
|
52
|
+
os.path.getatime(path) # Get last access time of a file
|
|
53
|
+
os.path.getmtime(path) # Get last modification time of a file
|
|
54
|
+
os.path.getctime(path) # Get creation time of a file
|
|
55
|
+
os.utime(path, times) # Set access and modification times
|
|
56
|
+
|
|
57
|
+
# Working with Paths
|
|
58
|
+
os.path.split(path) # Split a path into (head, tail)
|
|
59
|
+
os.path.splitext(path) # Split a path into (root, ext)
|
|
60
|
+
os.path.normpath(path) # Normalize a path (e.g., convert slashes)
|
|
61
|
+
|
|
62
|
+
# Other
|
|
63
|
+
os.path.samefile(path1, path2) # Check if two paths refer to the same file
|
|
64
|
+
|
|
65
|
+
# Directory Traversal
|
|
66
|
+
for root, dirs, files in os.walk(top, topdown=True):
|
|
67
|
+
# Traverse a directory tree, yielding root, dirs, and files lists
|
|
68
|
+
|
|
69
|
+
# Temporary Files and Directories
|
|
70
|
+
import tempfile
|
|
71
|
+
tempfile.mkstemp() # Create a temporary file
|
|
72
|
+
tempfile.mkdtemp() # Create a temporary directory
|
|
73
|
+
tempfile.TemporaryFile() # Create a temporary file object
|
|
74
|
+
|
|
75
|
+
# Environment Variables
|
|
76
|
+
os.environ # Dictionary of environment variables
|
|
77
|
+
os.environ['VAR_NAME'] # Access an environment variable
|
|
78
|
+
os.environ.get('VAR_NAME') # Access an environment variable (with default)
|
|
79
|
+
|
|
80
|
+
# Path Manipulation
|
|
81
|
+
os.path.abspath(path) # Convert relative path to absolute path
|
|
82
|
+
os.path.join(path1, path2, ...) # Join paths together
|
|
83
|
+
os.path.split(path) # Split a path into directory and filename
|
|
84
|
+
os.path.dirname(path) # Get the directory part of a path
|
|
85
|
+
os.path.basename(path) # Get the filename part of a path
|
|
86
|
+
os.path.exists(path) # Check if a path exists
|
|
87
|
+
os.path.isfile(path) # Check if a path points to a file
|
|
88
|
+
os.path.isdir(path) # Check if a path points to a directory
|
|
89
|
+
|
|
90
|
+
# File Permissions
|
|
91
|
+
os.chmod(path, mode) # Change file permissions
|
|
92
|
+
|
|
93
|
+
# Miscellaneous
|
|
94
|
+
os.getpid() # Get the current process ID
|
|
95
|
+
os.getlogin() # Get the name of the logged-in user
|
|
96
|
+
|
|
97
|
+
"""
|
|
98
|
+
import os
|
|
99
|
+
def break_down_find_existing(path):
|
|
100
|
+
test_path = ''
|
|
101
|
+
for part in path.split(os.sep):
|
|
102
|
+
test_path = os.path.join(test_path, part)
|
|
103
|
+
if not os.path.exists(test_path):
|
|
104
|
+
return test_path if test_path else None
|
|
105
|
+
return test_path
|
|
106
|
+
|
|
107
|
+
def string_in_keys(strings, kwargs):
|
|
108
|
+
return next((key for key in kwargs if any(s.lower() in key.lower() for s in strings)), None)
|
|
109
|
+
|
|
110
|
+
def get_path(paths):
|
|
111
|
+
for path in paths:
|
|
112
|
+
if isinstance(path,str):
|
|
113
|
+
if os.path.isfile(path):
|
|
114
|
+
return path
|
|
115
|
+
dirname = os.path.dirname(path)
|
|
116
|
+
if os.path.exists(dirname):
|
|
117
|
+
return path
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
def check_read_write_params(*args, **kwargs):
|
|
121
|
+
file_path = kwargs.get('file_path', None)
|
|
122
|
+
contents = kwargs.get('contents', None)
|
|
123
|
+
if contents is None:
|
|
124
|
+
contents = kwargs.get('data', None)
|
|
125
|
+
|
|
126
|
+
# Handle positional arguments
|
|
127
|
+
if file_path is None and len(args) > 0:
|
|
128
|
+
file_path = args[0]
|
|
129
|
+
if contents is None and len(args) > 1:
|
|
130
|
+
contents = args[1]
|
|
131
|
+
elif contents is None and len(args) > 0 and file_path != args[0]:
|
|
132
|
+
contents = args[0]
|
|
133
|
+
|
|
134
|
+
if file_path is None or contents is None:
|
|
135
|
+
raise ValueError("Both 'file_path' and 'contents' (or 'data') are required.")
|
|
136
|
+
|
|
137
|
+
return file_path, contents
|
|
138
|
+
|
|
139
|
+
def write_to_file(file_path=None, contents=None,*args, **kwargs):
|
|
140
|
+
"""
|
|
141
|
+
Write contents to a file. If the file does not exist, it is created.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
file_path: The path of the file to write to.
|
|
145
|
+
contents: The content to write to the file.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
The contents that were written to the file.
|
|
149
|
+
"""
|
|
150
|
+
params = check_read_write_params(file_path=file_path, contents=contents,*args, **kwargs)
|
|
151
|
+
if params:
|
|
152
|
+
with open(params[0], 'w', encoding='UTF-8') as f:
|
|
153
|
+
f.write(params[1])
|
|
154
|
+
return contents
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def read_from_file(file_path) -> str:
|
|
158
|
+
"""
|
|
159
|
+
Read the contents of a file.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
file_path: The path of the file to read from.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
The contents of the file.
|
|
166
|
+
"""
|
|
167
|
+
with open(file_path, 'r', encoding='UTF-8') as f:
|
|
168
|
+
return f.read()
|
|
169
|
+
|
|
170
|
+
def create_and_read_file(file_path=None, contents:str='',*args, **kwargs) -> str:
|
|
171
|
+
"""
|
|
172
|
+
Create a file if it does not exist, then read from it.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
file_path: The path of the file to create and read from.
|
|
176
|
+
contents: The content to write to the file if it does not exist.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
The contents of the file.
|
|
180
|
+
"""
|
|
181
|
+
if not os.path.isfile(file_path):
|
|
182
|
+
write_to_file(contents, file_path)
|
|
183
|
+
return read_from_file(file_path)
|
|
184
|
+
def is_file_extension(obj: str) -> bool:
|
|
185
|
+
"""
|
|
186
|
+
Check if a string has a file extension.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
obj: The string to check.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
True if the string has a file extension, False otherwise.
|
|
193
|
+
"""
|
|
194
|
+
return len(obj) >= 4 and '.' in obj[-4:-3]
|
|
195
|
+
|
|
196
|
+
def delete_file(file_path: str):
|
|
197
|
+
if os.path.isfile(file_path):
|
|
198
|
+
os.remove(file_path)
|
|
199
|
+
|