abstract-utilities 0.2.2.488__py3-none-any.whl → 0.2.2.492__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.
- abstract_utilities/read_write_utils.py +56 -39
- {abstract_utilities-0.2.2.488.dist-info → abstract_utilities-0.2.2.492.dist-info}/METADATA +1 -1
- {abstract_utilities-0.2.2.488.dist-info → abstract_utilities-0.2.2.492.dist-info}/RECORD +5 -5
- {abstract_utilities-0.2.2.488.dist-info → abstract_utilities-0.2.2.492.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.488.dist-info → abstract_utilities-0.2.2.492.dist-info}/top_level.txt +0 -0
|
@@ -14,10 +14,12 @@ Usage:
|
|
|
14
14
|
|
|
15
15
|
import os
|
|
16
16
|
import shlex
|
|
17
|
+
from .string_clean import *
|
|
17
18
|
from .ssh_utils.utils import run_cmd,get_print_sudo_cmd,run_local_cmd,run_remote_cmd
|
|
18
19
|
from .file_utils.file_utils.type_checks import is_file,is_dir,get_user_pass_host_key,is_exists
|
|
19
20
|
from .abstract_classes import run_pruned_func
|
|
20
21
|
from .string_utils import get_from_kwargs
|
|
22
|
+
|
|
21
23
|
_FILE_PATH_KEYS = ['file', 'filepath', 'file_path', 'path', 'directory', 'f', 'dst', 'dest']
|
|
22
24
|
_CONTENTS_KEYS = ['cont', 'content', 'contents', 'data', 'datas', 'dat', 'src', 'source']
|
|
23
25
|
|
|
@@ -30,15 +32,54 @@ def string_in_keys(strings, kwargs):
|
|
|
30
32
|
if s.lower() in key.lower():
|
|
31
33
|
return key
|
|
32
34
|
return None
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
def make_dirs(path, exist_ok=True, **kwargs):
|
|
36
|
+
remote = get_user_pass_host_key(**kwargs)
|
|
37
|
+
print(remote)
|
|
38
|
+
if remote:
|
|
39
|
+
kwargs['cmd'] = f"mkdir -p {path}"
|
|
40
|
+
print(kwargs)
|
|
41
|
+
resp = run_pruned_func(run_cmd, **kwargs)
|
|
42
|
+
print(resp)
|
|
43
|
+
else:
|
|
44
|
+
os.makedirs(path, exist_ok=exist_ok)
|
|
41
45
|
return path
|
|
46
|
+
def make_path(path, home_dir=None, file=None, **kwargs):
|
|
47
|
+
if not path:
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
basename = os.path.basename(path)
|
|
51
|
+
parts = [p for p in path.split('/') if p]
|
|
52
|
+
|
|
53
|
+
# Detect whether this is a file or a folder
|
|
54
|
+
is_file = file if file is not None else ('.' in basename)
|
|
55
|
+
pieces = parts[:-1] if is_file else parts
|
|
56
|
+
print(pieces)
|
|
57
|
+
full_dir = home_dir or '/'
|
|
58
|
+
for piece in pieces:
|
|
59
|
+
full_dir = os.path.join(full_dir, piece)
|
|
60
|
+
make_dirs(full_dir, exist_ok=True, **kwargs)
|
|
61
|
+
print(f"✅ full_dir == {full_dir}")
|
|
62
|
+
if is_file:
|
|
63
|
+
full_dir = os.path.join(full_dir, basename)
|
|
64
|
+
|
|
65
|
+
print(f"✅ full_dir == {full_dir}")
|
|
66
|
+
return full_dir
|
|
67
|
+
def get_rel_path(src,src_rel,dst,**kwargs):
|
|
68
|
+
if src.startswith(src_rel):
|
|
69
|
+
nu_src = src[len(src_rel):]
|
|
70
|
+
nu_src= eatAll(nu_src,'/')
|
|
71
|
+
directory= eatOuter(dst,'/')
|
|
72
|
+
rel_path = os.path.join(dst,nu_src)
|
|
73
|
+
return rel_path
|
|
74
|
+
def make_relative_path(src,src_rel,dst,**kwargs):
|
|
75
|
+
print(f"src == {src}\nsrc_rel == {src_rel}\dst == {dst}")
|
|
76
|
+
if src.startswith(src_rel):
|
|
77
|
+
rel_path = get_rel_path(src,src_rel,dst)
|
|
78
|
+
print(rel_path)
|
|
79
|
+
path = make_path(rel_path,**kwargs)
|
|
80
|
+
print(f"path == {path}")
|
|
81
|
+
return path
|
|
82
|
+
|
|
42
83
|
def path_join(*args):
|
|
43
84
|
path = None
|
|
44
85
|
for i,arg in enumerate(args):
|
|
@@ -48,25 +89,7 @@ def path_join(*args):
|
|
|
48
89
|
else:
|
|
49
90
|
path = os.path.join(path,arg)
|
|
50
91
|
return path
|
|
51
|
-
|
|
52
|
-
if path:
|
|
53
|
-
basename = os.path.basename(path)
|
|
54
|
-
parts = path.split('/')
|
|
55
|
-
parts = [part for part in parts if part]
|
|
56
|
-
|
|
57
|
-
full_dir = home_dir or ''
|
|
58
|
-
if file == True or (file == None and ('.' in basename)):
|
|
59
|
-
pieces = parts[:-1] if len(parts) > 1 else []
|
|
60
|
-
else:
|
|
61
|
-
pieces=parts
|
|
62
|
-
basename=None
|
|
63
|
-
for piece in pieces:
|
|
64
|
-
full_dir = os.path.join(full_dir,piece)
|
|
65
|
-
make_dirs(full_dir,exist_ok=True,**kwargs)
|
|
66
|
-
if basename:
|
|
67
|
-
full_dir=path_join(full_dir,basename)
|
|
68
|
-
print(f"full_dir == {full_dir}")
|
|
69
|
-
return full_dir
|
|
92
|
+
|
|
70
93
|
def get_path(paths,**kwargs):
|
|
71
94
|
"""Return the first valid path among given paths."""
|
|
72
95
|
for path in paths:
|
|
@@ -204,6 +227,8 @@ def write_to_file(*args, **kwargs):
|
|
|
204
227
|
if not kwargs.get('password') and not kwargs.get('key'):
|
|
205
228
|
kwargs["cmd"]=f'sudo {kwargs["cmd"]}'
|
|
206
229
|
result = run_pruned_func(run_cmd,**kwargs)
|
|
230
|
+
if 'file_path' in kwargs:
|
|
231
|
+
del kwargs['file_path']
|
|
207
232
|
if not is_file(file_path,**kwargs) or str(contents) != read_from_file(file_path,**kwargs):
|
|
208
233
|
kwargs["cmd"]=f'sudo {kwargs["cmd"]}'
|
|
209
234
|
result = run_pruned_func(run_cmd,**kwargs)
|
|
@@ -224,18 +249,7 @@ def read_from_file(file_path,**kwargs):
|
|
|
224
249
|
"""Read text content from a file."""
|
|
225
250
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
226
251
|
return f.read()
|
|
227
|
-
|
|
228
|
-
if src.startswith(src_rel):
|
|
229
|
-
src = src[len(src_rel):]
|
|
230
|
-
rel_path = os.path.join(directory,src)
|
|
231
|
-
return rel_path
|
|
232
|
-
def make_relative_path(src,src_rel,dst,**kwargs):
|
|
233
|
-
print(f"src == {src}\nsrc_rel == {src_rel}\dst == {dst}")
|
|
234
|
-
if src.startswith(src_rel):
|
|
235
|
-
rel_path = get_rel_path(src,src_rel,dst)
|
|
236
|
-
path = make_path(src,home_dir=rel_path,**kwargs)
|
|
237
|
-
print(f"path == {path}")
|
|
238
|
-
return path
|
|
252
|
+
|
|
239
253
|
def copy_dirs(dirs,dst,src_rel=None,**kwargs):
|
|
240
254
|
for src in dirs:
|
|
241
255
|
if rel_path:
|
|
@@ -243,13 +257,16 @@ def copy_dirs(dirs,dst,src_rel=None,**kwargs):
|
|
|
243
257
|
make_path(dst,**kwargs)
|
|
244
258
|
|
|
245
259
|
def copy_file(src,dst,rel_path=None,**kwargs):
|
|
260
|
+
|
|
246
261
|
if rel_path:
|
|
247
262
|
dst = make_relative_path(src,rel_path,dst,**kwargs)
|
|
263
|
+
print(dst)
|
|
248
264
|
if get_user_pass_host_key(**kwargs):
|
|
249
265
|
contents=read_from_file(src,**kwargs)
|
|
250
266
|
write_to_file(contents=contents,file_path=dst,**kwargs)
|
|
251
267
|
else:
|
|
252
268
|
shutil.copy(src,dst)
|
|
269
|
+
print(dst)
|
|
253
270
|
return dst
|
|
254
271
|
def copy_files(files,dst,rel_path=None,**kwargs):
|
|
255
272
|
for file in files:
|
|
@@ -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.492
|
|
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
|
|
@@ -14,7 +14,7 @@ abstract_utilities/log_utils.py,sha256=W74Y-CmdQP4Kj88HmAgejVxWgyWlvgCKMwLvOfyFf
|
|
|
14
14
|
abstract_utilities/math_utils.py,sha256=0o1ls1En03UAkYmxTBildCCJDfHygmNuvVnrNrLYtK0,6578
|
|
15
15
|
abstract_utilities/parse_utils.py,sha256=Z5OGRwHuzCzY91fz0JJojk1BPAo1XF2quNNLuBF4_Vk,18602
|
|
16
16
|
abstract_utilities/path_utils.py,sha256=X_U9cPBbNu5Wi0F3hQE0gXQX1gfhzxhxALbairTEOZU,19252
|
|
17
|
-
abstract_utilities/read_write_utils.py,sha256=
|
|
17
|
+
abstract_utilities/read_write_utils.py,sha256=pNDmrAJe1OlS3lmG52bcR1rMKwCd2Yffg_bvuLKP-Uk,10168
|
|
18
18
|
abstract_utilities/safe_utils.py,sha256=_uoZny6dJjopVakOiaf0UIZcvRRXMh51FpfDUooe0xY,3733
|
|
19
19
|
abstract_utilities/string_clean.py,sha256=oQv85J-mA4sP2NJwbTI-1k0RXw7V0AmqZolYaAZvex4,6916
|
|
20
20
|
abstract_utilities/string_utils.py,sha256=PnII0wFQBchVzFjhvEHP9ej1zxLehsRKodtc8Qol4-8,1645
|
|
@@ -86,7 +86,7 @@ abstract_utilities/ssh_utils/classes.py,sha256=3Q9BfLpyagNFYyiF4bt-5UCezeUJv9NK9
|
|
|
86
86
|
abstract_utilities/ssh_utils/imports.py,sha256=oX8WAv-pkhizzko_h3fIUp9Vhsse4nR7RN2vwONxIx0,317
|
|
87
87
|
abstract_utilities/ssh_utils/pexpect_utils.py,sha256=JBdOIXBTXAqE5TrsFjmPWJgwSaWyRJN8rbJ6y3_zKPY,10556
|
|
88
88
|
abstract_utilities/ssh_utils/utils.py,sha256=smUWAx3nW1h0etTndJ_te9bkUX5YzQ8kYd9_gD1TXLk,4882
|
|
89
|
-
abstract_utilities-0.2.2.
|
|
90
|
-
abstract_utilities-0.2.2.
|
|
91
|
-
abstract_utilities-0.2.2.
|
|
92
|
-
abstract_utilities-0.2.2.
|
|
89
|
+
abstract_utilities-0.2.2.492.dist-info/METADATA,sha256=2Ys2KmfYJBDHWBKXOek_sMRZ3wt1Hz70iGVYwOi8ZrE,28108
|
|
90
|
+
abstract_utilities-0.2.2.492.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
91
|
+
abstract_utilities-0.2.2.492.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
|
|
92
|
+
abstract_utilities-0.2.2.492.dist-info/RECORD,,
|
|
File without changes
|
{abstract_utilities-0.2.2.488.dist-info → abstract_utilities-0.2.2.492.dist-info}/top_level.txt
RENAMED
|
File without changes
|