abstract-utilities 0.2.2.488__py3-none-any.whl → 0.2.2.490__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.
@@ -30,15 +30,54 @@ def string_in_keys(strings, kwargs):
30
30
  if s.lower() in key.lower():
31
31
  return key
32
32
  return None
33
-
34
- def make_dirs(path,exist_ok=True,**kwargs):
35
- if exist_ok or (not exist_ok and not is_dir(path,**kwargs)):
36
- if get_user_pass_host_key(**kwargs):
37
- kwargs['cmd']=f"mkdir {path}"
38
- run_pruned_func(run_cmd,**kwargs)
39
- else:
40
- os.makedirs(path,exist_ok=exist_ok)
33
+ def make_dirs(path, exist_ok=True, **kwargs):
34
+ remote = get_user_pass_host_key(**kwargs)
35
+ print(remote)
36
+ if remote:
37
+ kwargs['cmd'] = f"mkdir -p {path}"
38
+ print(kwargs)
39
+ resp = run_pruned_func(run_cmd, **kwargs)
40
+ print(resp)
41
+ else:
42
+ os.makedirs(path, exist_ok=exist_ok)
41
43
  return path
44
+ def make_path(path, home_dir=None, file=None, **kwargs):
45
+ if not path:
46
+ return None
47
+
48
+ basename = os.path.basename(path)
49
+ parts = [p for p in path.split('/') if p]
50
+
51
+ # Detect whether this is a file or a folder
52
+ is_file = file if file is not None else ('.' in basename)
53
+ pieces = parts[:-1] if is_file else parts
54
+ print(pieces)
55
+ full_dir = home_dir or '/'
56
+ for piece in pieces:
57
+ full_dir = os.path.join(full_dir, piece)
58
+ make_dirs(full_dir, exist_ok=True, **kwargs)
59
+ print(f"✅ full_dir == {full_dir}")
60
+ if is_file:
61
+ full_dir = os.path.join(full_dir, basename)
62
+
63
+ print(f"✅ full_dir == {full_dir}")
64
+ return full_dir
65
+ def get_rel_path(src,src_rel,dst,**kwargs):
66
+ if src.startswith(src_rel):
67
+ nu_src = src[len(src_rel):]
68
+ nu_src= eatAll(nu_src,'/')
69
+ directory= eatOuter(dst,'/')
70
+ rel_path = os.path.join(dst,nu_src)
71
+ return rel_path
72
+ def make_relative_path(src,src_rel,dst,**kwargs):
73
+ print(f"src == {src}\nsrc_rel == {src_rel}\dst == {dst}")
74
+ if src.startswith(src_rel):
75
+ rel_path = get_rel_path(src,src_rel,dst)
76
+ print(rel_path)
77
+ path = make_path(rel_path,**kwargs)
78
+ print(f"path == {path}")
79
+ return path
80
+
42
81
  def path_join(*args):
43
82
  path = None
44
83
  for i,arg in enumerate(args):
@@ -48,25 +87,7 @@ def path_join(*args):
48
87
  else:
49
88
  path = os.path.join(path,arg)
50
89
  return path
51
- def make_path(path,home_dir=None,file=None,**kwargs):
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
90
+
70
91
  def get_path(paths,**kwargs):
71
92
  """Return the first valid path among given paths."""
72
93
  for path in paths:
@@ -204,6 +225,8 @@ def write_to_file(*args, **kwargs):
204
225
  if not kwargs.get('password') and not kwargs.get('key'):
205
226
  kwargs["cmd"]=f'sudo {kwargs["cmd"]}'
206
227
  result = run_pruned_func(run_cmd,**kwargs)
228
+ if 'file_path' in kwargs:
229
+ del kwargs['file_path']
207
230
  if not is_file(file_path,**kwargs) or str(contents) != read_from_file(file_path,**kwargs):
208
231
  kwargs["cmd"]=f'sudo {kwargs["cmd"]}'
209
232
  result = run_pruned_func(run_cmd,**kwargs)
@@ -224,18 +247,7 @@ def read_from_file(file_path,**kwargs):
224
247
  """Read text content from a file."""
225
248
  with open(file_path, "r", encoding="utf-8") as f:
226
249
  return f.read()
227
- def get_rel_path(src,src_rel,directory):
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
250
+
239
251
  def copy_dirs(dirs,dst,src_rel=None,**kwargs):
240
252
  for src in dirs:
241
253
  if rel_path:
@@ -243,13 +255,16 @@ def copy_dirs(dirs,dst,src_rel=None,**kwargs):
243
255
  make_path(dst,**kwargs)
244
256
 
245
257
  def copy_file(src,dst,rel_path=None,**kwargs):
258
+
246
259
  if rel_path:
247
260
  dst = make_relative_path(src,rel_path,dst,**kwargs)
261
+ print(dst)
248
262
  if get_user_pass_host_key(**kwargs):
249
263
  contents=read_from_file(src,**kwargs)
250
264
  write_to_file(contents=contents,file_path=dst,**kwargs)
251
265
  else:
252
266
  shutil.copy(src,dst)
267
+ print(dst)
253
268
  return dst
254
269
  def copy_files(files,dst,rel_path=None,**kwargs):
255
270
  for file in files:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_utilities
3
- Version: 0.2.2.488
3
+ Version: 0.2.2.490
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=9jW-eQojjXGAtyeCQp2m_1Rx6KgDGp3GHN0jwdqZlcA,9941
17
+ abstract_utilities/read_write_utils.py,sha256=jcdMLBFrLRzkGRvEXS7PArh182Q2nVMIDn3Jf6sN27k,10139
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.488.dist-info/METADATA,sha256=rta42TF8pwLWyBz2dR-dx085mU_Sd-HOpzQLVpeLYro,28108
90
- abstract_utilities-0.2.2.488.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
- abstract_utilities-0.2.2.488.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
92
- abstract_utilities-0.2.2.488.dist-info/RECORD,,
89
+ abstract_utilities-0.2.2.490.dist-info/METADATA,sha256=WWRDaP8kZyQEUTeFvVxSfRwPk_Kj1s5JZ3jf-lqiUMM,28108
90
+ abstract_utilities-0.2.2.490.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
+ abstract_utilities-0.2.2.490.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
92
+ abstract_utilities-0.2.2.490.dist-info/RECORD,,