abstract-utilities 0.2.2.398__tar.gz → 0.2.2.485__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.

Files changed (101) hide show
  1. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/PKG-INFO +1 -1
  2. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/setup.py +1 -1
  3. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/__init__.py +14 -46
  4. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/class_utils.py +38 -3
  5. abstract_utilities-0.2.2.485/src/abstract_utilities/cmd_utils/imports/__init__.py +1 -0
  6. abstract_utilities-0.2.2.485/src/abstract_utilities/cmd_utils/imports/imports.py +10 -0
  7. abstract_utilities-0.2.2.485/src/abstract_utilities/cmd_utils/pexpect_utils.py +310 -0
  8. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/cmd_utils/user_utils.py +1 -1
  9. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/dynimport.py +7 -15
  10. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/__init__.py +3 -0
  11. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/abstractEnv.py +129 -0
  12. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/envy_it.py +33 -0
  13. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/imports/__init__.py +2 -0
  14. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/imports/imports.py +8 -0
  15. abstract_utilities-0.2.2.485/src/abstract_utilities/env_utils/imports/utils.py +122 -0
  16. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/__init__.py +3 -0
  17. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/__init__.py +8 -0
  18. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/file_filters.py +104 -0
  19. {abstract_utilities-0.2.2.398/src/abstract_utilities/robust_reader → abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils}/file_reader.py +5 -19
  20. abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/file_filters.py → abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/file_utils.py +3 -1
  21. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/find_collect.py +154 -0
  22. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/imports/__init__.py +3 -0
  23. {abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils → abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils}/imports/constants.py +4 -1
  24. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/imports/imports.py +39 -0
  25. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/imports/module_imports.py +14 -0
  26. {abstract_utilities-0.2.2.398/src/abstract_utilities/robust_reader → abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils}/pdf_utils.py +1 -9
  27. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/type_checks.py +91 -0
  28. {abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils → abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils}/imports/__init__.py +2 -1
  29. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/imports/classes.py +381 -0
  30. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/imports/clean_imps.py +158 -0
  31. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/imports/constants.py +39 -0
  32. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/imports/imports.py +65 -0
  33. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/imports/module_imports.py +13 -0
  34. abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/req.py +329 -0
  35. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/log_utils.py +1 -1
  36. {abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils → abstract_utilities-0.2.2.485/src/abstract_utilities}/path_utils.py +91 -11
  37. abstract_utilities-0.2.2.485/src/abstract_utilities/read_write_utils.py +292 -0
  38. abstract_utilities-0.2.2.485/src/abstract_utilities/robust_reader/__init__.py +2 -0
  39. abstract_utilities-0.2.2.485/src/abstract_utilities/robust_reader/imports/__init__.py +1 -0
  40. abstract_utilities-0.2.2.485/src/abstract_utilities/robust_reader/imports/imports.py +3 -0
  41. abstract_utilities-0.2.2.485/src/abstract_utilities/robust_readers/__init__.py +2 -0
  42. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/__init__.py +1 -0
  43. abstract_utilities-0.2.2.485/src/abstract_utilities/robust_readers/import_utils/clean_imports.py +175 -0
  44. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/imports.py +1 -1
  45. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/initFuncGen.py +10 -2
  46. abstract_utilities-0.2.2.485/src/abstract_utilities/safe_utils.py +133 -0
  47. abstract_utilities-0.2.2.485/src/abstract_utilities/ssh_utils/__init__.py +3 -0
  48. abstract_utilities-0.2.2.485/src/abstract_utilities/ssh_utils/classes.py +127 -0
  49. abstract_utilities-0.2.2.485/src/abstract_utilities/ssh_utils/imports.py +10 -0
  50. abstract_utilities-0.2.2.485/src/abstract_utilities/ssh_utils/pexpect_utils.py +315 -0
  51. abstract_utilities-0.2.2.485/src/abstract_utilities/ssh_utils/utils.py +188 -0
  52. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/string_clean.py +40 -1
  53. abstract_utilities-0.2.2.485/src/abstract_utilities/string_utils.py +51 -0
  54. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/type_utils.py +25 -1
  55. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities.egg-info/PKG-INFO +1 -1
  56. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities.egg-info/SOURCES.txt +42 -12
  57. abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/__init__.py +0 -4
  58. abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/imports/imports.py +0 -4
  59. abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/imports/module_imports.py +0 -5
  60. abstract_utilities-0.2.2.398/src/abstract_utilities/read_write_utils.py +0 -199
  61. abstract_utilities-0.2.2.398/src/abstract_utilities/robust_reader/__init__.py +0 -2
  62. abstract_utilities-0.2.2.398/src/abstract_utilities/robust_readers/__init__.py +0 -1
  63. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/README.md +0 -0
  64. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/pyproject.toml +0 -0
  65. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/setup.cfg +0 -0
  66. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/abstract_classes.py +0 -0
  67. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/cmd_utils/__init__.py +0 -0
  68. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/cmd_utils/cmd_utils.py +0 -0
  69. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/collator_utils.py +0 -0
  70. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/compare_utils/__init__.py +0 -0
  71. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/compare_utils/best_match.py +0 -0
  72. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/compare_utils/compare_utils.py +0 -0
  73. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/compare_utils/find_value.py +0 -0
  74. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/doit.py +0 -0
  75. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/error_utils.py +0 -0
  76. /abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/file_params.py → /abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/filter_params.py +0 -0
  77. /abstract_utilities-0.2.2.398/src/abstract_utilities/path_utils/file_utils.py → /abstract_utilities-0.2.2.485/src/abstract_utilities/file_utils/file_utils/map_utils.py +0 -0
  78. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/global_utils.py +0 -0
  79. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/hash_utils.py +0 -0
  80. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/history_utils.py +0 -0
  81. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/json_utils.py +0 -0
  82. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/list_utils.py +0 -0
  83. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/math_utils.py +0 -0
  84. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/parse_utils.py +0 -0
  85. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_reader/file_reader2.py +0 -0
  86. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_reader/file_readers.py +0 -0
  87. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_reader/sadfsad.py +0 -0
  88. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/dot_utils.py +0 -0
  89. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/function_utils.py +0 -0
  90. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/import_utils.py +0 -0
  91. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/impot_functions.py +0 -0
  92. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/safe_import_utils.py +0 -0
  93. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/sysroot_utils.py +0 -0
  94. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/robust_readers/import_utils/utils.py +0 -0
  95. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/tetsts.py +0 -0
  96. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/thread_utils.py +0 -0
  97. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/time_utils.py +0 -0
  98. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities/utils.py +0 -0
  99. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities.egg-info/dependency_links.txt +0 -0
  100. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/src/abstract_utilities.egg-info/requires.txt +0 -0
  101. {abstract_utilities-0.2.2.398 → abstract_utilities-0.2.2.485}/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.398
3
+ Version: 0.2.2.485
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
@@ -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.398',
7
+ version='0.2.2.485',
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.',
@@ -3,8 +3,9 @@ from datetime import timedelta
3
3
  from datetime import datetime
4
4
  from typing import *
5
5
  from .hash_utils import *
6
- from .dynimport import get_abstract_import,import_symbols_to_parent,call_for_all_tabs
7
-
6
+ ##from .dynimport import get_abstract_import,import_symbols_to_parent,call_for_all_tabs
7
+ from .robust_readers import *
8
+ from .dynimport import get_abstract_import
8
9
  from .json_utils import (unified_json_loader,
9
10
  find_keys,
10
11
  get_key_values_from_path,
@@ -40,45 +41,8 @@ from .json_utils import (unified_json_loader,
40
41
  )
41
42
  from .read_write_utils import (read_from_file,
42
43
  write_to_file)
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
- get_file_map,
79
- get_file_type,
80
- MIME_TYPES
81
- )
44
+ from .path_utils import *
45
+ from .file_utils import *
82
46
  from .list_utils import (get_highest_value_obj,
83
47
  make_list,
84
48
  safe_list_return,
@@ -123,7 +87,8 @@ from .type_utils import (make_bool,
123
87
  get_numbers,
124
88
  get_numbers_comp,
125
89
  is_any_instance,
126
- break_string
90
+ break_string,
91
+ MIME_TYPES
127
92
  )
128
93
  get_media_types = get_all_types = get_all_file_types
129
94
  from .math_utils import (convert_to_percentage,
@@ -151,7 +116,10 @@ from .parse_utils import (num_tokens_from_string,
151
116
 
152
117
  from .log_utils import get_caller_info,get_logFile,print_or_log,get_json_call_response,initialize_call_log
153
118
  from .error_utils import try_func
154
- from .class_utils import alias,get_class_inputs,get_set_attr
155
- from .robust_reader import *
156
- from .robust_readers import *
157
-
119
+ from .ssh_utils import *
120
+ from .env_utils import *
121
+ from .path_utils import *
122
+ from .file_utils import *
123
+ from .file_utils import call_for_all_tabs
124
+ from .string_utils import *
125
+ from .class_utils import alias,get_class_inputs,get_set_attr,get_caller_path,get_caller_dir
@@ -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 inspect
48
- import json
49
- import functools
47
+ import os,json,functools,inspect
48
+ from typing import *
49
+
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,3 +370,38 @@ 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
+
@@ -0,0 +1,10 @@
1
+ # remote_fs.py
2
+ from __future__ import annotations
3
+ from typing import *
4
+ import subprocess, shlex, os, fnmatch, glob, posixpath, re
5
+ # ---- import your existing pieces ----
6
+ from ...type_utils import make_list # whatever you already have
7
+ from ...time_utils import get_sleep
8
+ from ...ssh_utils import *
9
+ from ...env_utils import *
10
+ from ...string_clean import eatOuter
@@ -0,0 +1,310 @@
1
+
2
+ from .ssh_utils import *
3
+ from ..env_utils import *
4
+ # pexpect is optional; import lazily if you prefer
5
+
6
+ # keep your execute_cmd; add a thin wrapper that supports stdin text cleanly
7
+ def execute_cmd_input(
8
+ *args,
9
+ input_text: str | None = None,
10
+ outfile: str | None = None,
11
+ **kwargs
12
+ ) -> str:
13
+ """
14
+ Like execute_cmd, but lets you pass text to stdin (subprocess.run(input=...)).
15
+ """
16
+ if input_text is not None:
17
+ kwargs["input"] = input_text
18
+ # ensure text mode so Python passes str not bytes
19
+ kwargs.setdefault("text", True)
20
+ return execute_cmd(*args, outfile=outfile, **kwargs)
21
+
22
+ # -------------------------
23
+ # Core: capture + printing
24
+ # -------------------------
25
+ def exec_sudo_capture(
26
+ cmd: str,
27
+ *,
28
+ password: str | None = None,
29
+ key: str | None = None,
30
+ user_at_host: str | None = None,
31
+ cwd: str | None = None,
32
+ print_output: bool = False,
33
+ ) -> str:
34
+ """
35
+ Run a sudo command and return its output (no temp file).
36
+ """
37
+ if password is None:
38
+ password = get_env_value(key=key) if key else get_sudo_password()
39
+
40
+ sudo_cmd = f"sudo -S -k {cmd}"
41
+
42
+ if user_at_host:
43
+ # build the remote command (bash -lc + optional cd)
44
+ remote = get_remote_cmd(cmd=sudo_cmd, user_at_host=user_at_host, cwd=cwd)
45
+ # feed password to remote's stdin (ssh forwards stdin)
46
+ out = execute_cmd_input(remote, input_text=password + "\n",
47
+ shell=True, text=True, capture_output=True)
48
+ else:
49
+ out = execute_cmd_input(sudo_cmd, input_text=password + "\n",
50
+ shell=True, text=True, capture_output=True, cwd=cwd)
51
+
52
+ if print_output:
53
+ print_cmd(cmd, out or "")
54
+ return out or ""
55
+
56
+
57
+
58
+ # ---------------------------------------------------
59
+ # SUDO helpers (local + SSH) with env/password options
60
+ # ---------------------------------------------------
61
+ def exec_sudo(
62
+ cmd: str,
63
+ *,
64
+ password: Optional[str] = None,
65
+ key: Optional[str] = None,
66
+ user_at_host: Optional[str] = None,
67
+ cwd: Optional[str] = None,
68
+ outfile: Optional[str] = None,
69
+ print_output: bool = False,
70
+ ) -> str:
71
+ """
72
+ Execute `cmd` via sudo either locally or on remote.
73
+ Password order of precedence:
74
+ 1) `password` arg
75
+ 2) `key` -> get_env_value(key)
76
+ 3) get_sudo_password()
77
+
78
+ Uses: sudo -S -k (-S read password from stdin, -k invalidate cached timestamp)
79
+ """
80
+ if password is None:
81
+ if key:
82
+ password = get_env_value(key=key)
83
+ else:
84
+ password = get_sudo_password()
85
+
86
+ # Compose the sudo command that reads from stdin
87
+ sudo_cmd = f"sudo -S -k {cmd}"
88
+
89
+ if user_at_host:
90
+ # For remote: the password is piped to SSH stdin, which flows to remote sudo's stdin.
91
+ remote = get_remote_cmd(cmd=sudo_cmd, user_at_host=user_at_host, cwd=cwd)
92
+ full = f"printf %s {shlex.quote(password)} | {remote}"
93
+ out = execute_cmd(full, shell=True, text=True, capture_output=True, outfile=outfile)
94
+ else:
95
+ # Local
96
+ full = f"printf %s {shlex.quote(password)} | {sudo_cmd}"
97
+ out = execute_cmd(full, shell=True, text=True, capture_output=True, outfile=outfile)
98
+
99
+ if print_output:
100
+ print_cmd(cmd, out or "")
101
+ return out or ""
102
+
103
+
104
+ # -------------------------------------------------
105
+ # Fire-and-forget (file-backed) compatible runner
106
+ # -------------------------------------------------
107
+ def cmd_run(
108
+ cmd: str,
109
+ output_text: str | None = None,
110
+ print_output: bool = False,
111
+ *,
112
+ user_at_host: str | None = None,
113
+ cwd: str | None = None,
114
+ ) -> str | None:
115
+ """
116
+ If output_text is None → capture+return output (no file).
117
+ If output_text is provided → legacy file-backed behavior.
118
+ """
119
+ if output_text is None:
120
+ # capture mode
121
+ if user_at_host:
122
+ remote = get_remote_cmd(cmd=cmd, user_at_host=user_at_host, cwd=cwd)
123
+ out = execute_cmd(remote, shell=True, text=True, capture_output=True)
124
+ else:
125
+ out = execute_cmd(cmd, shell=True, text=True, capture_output=True, cwd=cwd)
126
+ if print_output:
127
+ print_cmd(cmd, out or "")
128
+ return out or ""
129
+
130
+ # ---- legacy file-backed path (unchanged in spirit) ----
131
+ # Clear output file
132
+ with open(output_text, 'w'):
133
+ pass
134
+
135
+ # Append redirection + sentinel
136
+ full_cmd = f'{cmd} >> {output_text}; echo END_OF_CMD >> {output_text}'
137
+
138
+ # Execute local/remote
139
+ if user_at_host:
140
+ remote_line = get_remote_cmd(cmd=full_cmd, user_at_host=user_at_host, cwd=cwd)
141
+ subprocess.call(remote_line, shell=True)
142
+ else:
143
+ subprocess.call(full_cmd, shell=True, cwd=cwd)
144
+
145
+ # Wait for sentinel
146
+ while True:
147
+ get_sleep(sleep_timer=0.5)
148
+ with open(output_text, 'r') as f:
149
+ lines = f.readlines()
150
+ if lines and lines[-1].strip() == 'END_OF_CMD':
151
+ break
152
+
153
+ if print_output:
154
+ with open(output_text, 'r') as f:
155
+ print_cmd(full_cmd, f.read().strip())
156
+
157
+ try:
158
+ os.remove(output_text)
159
+ except OSError:
160
+ pass
161
+
162
+ return None
163
+
164
+
165
+ # ----------------------------------------------------
166
+ # pexpect wrappers (local + SSH) for interactive flows
167
+ # ----------------------------------------------------
168
+ def exec_expect(
169
+ command: str,
170
+ child_runs: List[Dict[str, Any]],
171
+ *,
172
+ user_at_host: Optional[str] = None,
173
+ cwd: Optional[str] = None,
174
+ print_output: bool = False,
175
+ ) -> int:
176
+ """
177
+ Run `command` and answer interactive prompts.
178
+
179
+ child_runs: list of dicts like:
180
+ { "prompt": r"Password:", "pass": "xyz" }
181
+ { "prompt": r"Enter passphrase:", "key": "MY_KEY", "env_path": "/path/for/.env" }
182
+ If "pass" is None, we resolve via get_env_value(key=..., start_path=env_path).
183
+
184
+ Returns exitstatus (0=success).
185
+ """
186
+ if user_at_host:
187
+ # Wrap command for remote execution
188
+ remote_line = get_remote_cmd(cmd=command, user_at_host=user_at_host, cwd=cwd)
189
+ spawn_cmd = f"{remote_line}"
190
+ else:
191
+ spawn_cmd = f"bash -lc {shlex.quote((f'cd {shlex.quote(cwd)} && {command}') if cwd else command)}"
192
+
193
+ child = pexpect.spawn(spawn_cmd)
194
+
195
+ for each in child_runs:
196
+ child.expect(each["prompt"])
197
+
198
+ if each.get("pass") is not None:
199
+ pass_phrase = each["pass"]
200
+ else:
201
+ args = {}
202
+ if "key" in each and each["key"] is not None:
203
+ args["key"] = each["key"]
204
+ if "env_path" in each and each["env_path"] is not None:
205
+ args["start_path"] = each["env_path"]
206
+ pass_phrase = get_env_value(**args)
207
+
208
+ child.sendline(pass_phrase)
209
+ if print_output:
210
+ print("Answered prompt:", each["prompt"])
211
+
212
+ child.expect(pexpect.EOF)
213
+ out = child.before.decode("utf-8", errors="ignore")
214
+ if print_output:
215
+ print_cmd(command, out)
216
+
217
+ return child.exitstatus if child.exitstatus is not None else 0
218
+
219
+
220
+ # ---------------------------------------
221
+ # Convenience shims to mirror your names
222
+ # ---------------------------------------
223
+ def cmd_run_sudo(
224
+ cmd: str,
225
+ password: str | None = None,
226
+ key: str | None = None,
227
+ output_text: str | None = None,
228
+ *,
229
+ user_at_host: str | None = None,
230
+ cwd: str | None = None,
231
+ print_output: bool = False,
232
+ ) -> str | None:
233
+ """
234
+ If output_text is None → capture sudo output and return it.
235
+ If output_text is provided → legacy file-backed behavior feeding sudo via stdin.
236
+ """
237
+ if output_text is None:
238
+ return exec_sudo_capture(
239
+ cmd,
240
+ password=password,
241
+ key=key,
242
+ user_at_host=user_at_host,
243
+ cwd=cwd,
244
+ print_output=print_output,
245
+ )
246
+
247
+ # ---- legacy file-backed path ----
248
+ # build the underlying sudo command
249
+ sudo_cmd = f"sudo -S -k {cmd}"
250
+ pw = password if password is not None else (get_env_value(key=key) if key else get_sudo_password())
251
+
252
+ # We need to feed password to stdin in the same shell that runs sudo.
253
+ # For file-backed mode we’ll inline a small shell that reads from a here-string.
254
+ # Local:
255
+ if not user_at_host:
256
+ full = f'bash -lc {shlex.quote((f"cd {shlex.quote(cwd)} && " if cwd else "") + f"printf %s {shlex.quote(pw)} | {sudo_cmd}")}'
257
+ return cmd_run(full, output_text=output_text, print_output=print_output)
258
+ # Remote:
259
+ # On remote, do the same in the remote bash -lc
260
+ remote_sudo_line = f'printf %s {shlex.quote(pw)} | {sudo_cmd}'
261
+ remote_full = get_remote_cmd(cmd=remote_sudo_line, user_at_host=user_at_host, cwd=cwd)
262
+ return cmd_run(remote_full, output_text=output_text, print_output=print_output)
263
+ def pexpect_cmd_with_args(
264
+ command: str,
265
+ child_runs: list,
266
+ output_text: str | None = None,
267
+ *,
268
+ user_at_host: str | None = None,
269
+ cwd: str | None = None,
270
+ print_output: bool = False
271
+ ) -> int:
272
+ """
273
+ If output_text is None → return output string via print_output, else write to file then remove (legacy).
274
+ """
275
+ if user_at_host:
276
+ spawn_cmd = get_remote_cmd(cmd=command, user_at_host=user_at_host, cwd=cwd)
277
+ else:
278
+ spawn_cmd = f"bash -lc {shlex.quote((f'cd {shlex.quote(cwd)} && {command}') if cwd else command)}"
279
+
280
+ child = pexpect.spawn(spawn_cmd)
281
+
282
+ for each in child_runs:
283
+ child.expect(each["prompt"])
284
+ if each.get("pass") is not None:
285
+ pass_phrase = each["pass"]
286
+ else:
287
+ args = {}
288
+ if "key" in each and each["key"] is not None:
289
+ args["key"] = each["key"]
290
+ if "env_path" in each and each["env_path"] is not None:
291
+ args["start_path"] = each["env_path"]
292
+ pass_phrase = get_env_value(**args)
293
+ child.sendline(pass_phrase)
294
+ if print_output:
295
+ print("Answered prompt:", each["prompt"])
296
+
297
+ child.expect(pexpect.EOF)
298
+ out = child.before.decode("utf-8", errors="ignore")
299
+
300
+ if output_text:
301
+ with open(output_text, "w") as f:
302
+ f.write(out)
303
+ if print_output:
304
+ print_cmd(command, out)
305
+ # keep legacy? your old code removed the file; here we’ll keep it (safer).
306
+ # If you want the old behavior, uncomment:
307
+ # os.remove(output_text)
308
+ else:
309
+ if print_output:
310
+ print_cmd(command, out)
@@ -1,4 +1,4 @@
1
- from ..string_clean import eatOuter
1
+
2
2
  def get_user_input(text,default='y'):
3
3
  choices = '(y/n)' if default in ['y','n'] else ''
4
4
  response = input(f"{text} {choices}:({default}) ") or default
@@ -1,12 +1,12 @@
1
1
  # abstract_utilities/dynimport.py
2
2
  from __future__ import annotations
3
- import importlib, sys, os
4
3
  from functools import lru_cache
5
- from typing import Any, Callable, Iterable, Optional
6
- import inspect, sys
4
+ from typing import *
5
+ import importlib, sys, os, sys,inspect
6
+ from typing import Optional
7
7
  from importlib import import_module
8
8
  from .type_utils import make_list
9
- from .robust_readers import get_for_all_tabs,call_for_all_tabs
9
+
10
10
  class _LazyAttr:
11
11
  """Lazy resolver proxy to avoid import-time cycles.
12
12
  First use triggers actual import & attribute lookup.
@@ -181,14 +181,6 @@ 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
- 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(root=None):
192
-
193
- root = root or get_caller_dir()
194
- get_for_all_tabs(root)
184
+
185
+
186
+
@@ -0,0 +1,3 @@
1
+ from .imports import *
2
+ from .abstractEnv import *
3
+ from .envy_it import *
@@ -0,0 +1,129 @@
1
+ from .imports import *
2
+ class abstractEnv:
3
+ def __init__(self,key='MY_PASSWORD',file_name=None,path=os.getcwd(),deep_scan=False):
4
+ file_name = file_name or '.env'
5
+ self.re_initialize(file_name=file_name,key=key,path=path,deep_scan=deep_scan)
6
+ def re_initialize(self,key='MY_PASSWORD',file_name='.env',path=os.getcwd(),deep_scan=False):
7
+ """
8
+ Initializes an AbstractEnv object to manage environment variables.
9
+
10
+ Args:
11
+ key (str, optional): The key to search for in the .env file. Defaults to 'MY_PASSWORD'.
12
+ file_name (str, optional): The name of the .env file. Defaults to '.env'.
13
+ path (str, optional): The path where the .env file is located. Defaults to the current working directory.
14
+ """
15
+
16
+ self.key = key or 'MY_PASSWORD'
17
+
18
+ file_name = file_name or '.env'
19
+ self.key = key or 'MY_PASSWORD'
20
+ self.deep_scan=deep_scan
21
+ self.current_folder = os.getcwd()
22
+ if path and os.path.isfile(path):
23
+ self.file_name = os.path.basename(path)
24
+ self.path = os.path.dirname(path)
25
+ else:
26
+ self.path = path or self.current_folder
27
+ self.file_name = file_name or '.env'
28
+ self.start_path_env = os.path.join(self.path,self.file_name)
29
+ self.home_folder = os.path.expanduser("~")
30
+ self.envy_all = os.path.join(self.home_folder,'.envy_all')
31
+ self.directories = self.get_directories()
32
+ self.env_value = self.find_and_read_env_file(key=self.key,file_name=self.file_name, path=self.path,initialize=False)
33
+
34
+ def find_and_read_env_file(self,key:str=None, file_name:str=None, path=None,initialize=True,deep_scan=False):
35
+ """
36
+ Search for an environment file and read a specific key from it.
37
+
38
+ Args:
39
+ file_name (str): Name of the .env file to be searched. Defaults to '.env'.
40
+ key (str): Key to be retrieved from the .env file. Defaults to 'MY_PASSWORD'.
41
+ start_path (str): Directory path to start the search from. If None, search starts from current directory.
42
+
43
+ Returns:
44
+ str: The value corresponding to the key if found, otherwise None.
45
+ """
46
+ # Set the default start_path to the current directory if it's None
47
+ # Try to find the file in the start_path
48
+ key = key or self.key
49
+ path = path or self.start_path_env
50
+ file_name = file_name or self.file_name
51
+ if initialize:
52
+ self.re_initialize(key=key,file_name=file_name,path=path)
53
+ for directory in self.directories:
54
+ if directory and os.path.isdir(directory) and self.file_name:
55
+ env_path = os.path.join(directory,self.file_name)
56
+ if os.path.isfile(env_path):
57
+ value = self.search_for_env_key(key=key,path=env_path)
58
+ self.env_path = os.path.join(directory,self.file_name)
59
+ if os.path.isfile(self.env_path):
60
+ value = self.search_for_env_key(key=key,path=self.env_path,deep_scan=deep_scan)
61
+ if value:
62
+ return value
63
+ def get_directories(self):
64
+ """
65
+ Retrieves a list of directories to search for the .env file.
66
+
67
+ Returns:
68
+ list: A list of directories including the specified path, current folder, home folder, and '.envy_all' directory.
69
+ """
70
+ directories=[]
71
+ for directory in [self.path,self.current_folder,self.home_folder,self.envy_all]:
72
+ if os.path.isdir(directory) and directory not in directories:
73
+ directories.append(directory)
74
+ return directories
75
+
76
+
77
+ def search_for_env_key(self,key:str=None,path:str=None,deep_scan=False):
78
+
79
+ """
80
+ Retrieves the value of a specified environment variable from a .env file.
81
+
82
+ Args:
83
+ key (str, optional): The key to search for in the .env file. Defaults to None.
84
+ path (str, optional): The path to the .env file. Defaults to None.
85
+ file_name (str, optional): The name of the .env file. Defaults to None.
86
+
87
+ Returns:
88
+ str: The value of the environment variable if found, otherwise None.
89
+ """
90
+
91
+ highest = [None,0,0.0]
92
+ key = key or self.default_env_key
93
+ path = path or self.start_path_env
94
+ if path and os.path.isfile(path):
95
+ with open(path, "r") as f:
96
+ for line in f:
97
+ line_key,line_value = split_eq(line)
98
+ # If the line contains the key, return the value after stripping extra characters
99
+ if line_key == key:
100
+ return line_value
101
+ if deep_scan:
102
+ line_keys = []
103
+ key_parts=0
104
+ for key_part in key.split('_'):
105
+ line_keys.append([])
106
+ if key_part in line_key:
107
+ line_keys[-1].append(line_key)
108
+ key_parts+=len(key_part)
109
+ if float(key_parts/len(key))>=0.5 and key_parts >highest[1]:
110
+ highest = [line_value,key_parts]
111
+ if deep_scan and highest[0] != None:
112
+ return line_value
113
+ def get_env_value(key:str=None,path:str=os.getcwd(),file_name:str=None):
114
+ """
115
+ Retrieves the value of the specified environment variable.
116
+
117
+ Args:
118
+ path (str): The path to the environment file. Defaults to None.
119
+ file_name (str): The name of the environment file. Defaults to '.env'.
120
+ key (str): The key to search for in the .env file. Defaults to 'MY_PASSWORD'.
121
+
122
+ Returns:
123
+ str: The value of the environment variable if found, otherwise None.
124
+ """
125
+ if safe_env_load(path):
126
+ return os.getenv(key)
127
+ return find_and_read_env_file(file_name=file_name, key=key, path=path_ls)
128
+
129
+ AbstractEnv = abstractEnv