abstract-utilities 0.2.2.448__py3-none-any.whl → 0.2.2.450__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.

Files changed (57) hide show
  1. abstract_utilities/__init__.py +43 -17
  2. abstract_utilities/abstract_classes.py +0 -49
  3. abstract_utilities/class_utils.py +3 -39
  4. abstract_utilities/cmd_utils/user_utils.py +1 -1
  5. abstract_utilities/{compare_utils/compare_utils.py → compare_utils.py} +1 -1
  6. abstract_utilities/dynimport.py +15 -7
  7. abstract_utilities/json_utils.py +0 -35
  8. abstract_utilities/log_utils.py +3 -14
  9. abstract_utilities/path_utils.py +6 -90
  10. abstract_utilities/read_write_utils.py +156 -99
  11. abstract_utilities/robust_reader/__init__.py +1 -1
  12. abstract_utilities/{file_utils/file_utils → robust_reader}/file_reader.py +19 -5
  13. abstract_utilities/{file_utils/file_utils → robust_reader}/pdf_utils.py +9 -1
  14. abstract_utilities/robust_readers/__init__.py +1 -0
  15. abstract_utilities/{file_utils/file_utils/file_utils.py → robust_readers/file_filters.py} +1 -2
  16. abstract_utilities/{file_utils/file_utils → robust_readers}/filter_params.py +38 -1
  17. abstract_utilities/robust_readers/initFuncGen.py +74 -82
  18. abstract_utilities/type_utils.py +1 -0
  19. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.450.dist-info}/METADATA +3 -5
  20. abstract_utilities-0.2.2.450.dist-info/RECORD +49 -0
  21. abstract_utilities/cmd_utils/imports/__init__.py +0 -1
  22. abstract_utilities/cmd_utils/imports/imports.py +0 -10
  23. abstract_utilities/cmd_utils/pexpect_utils.py +0 -310
  24. abstract_utilities/compare_utils/__init__.py +0 -3
  25. abstract_utilities/compare_utils/best_match.py +0 -150
  26. abstract_utilities/compare_utils/find_value.py +0 -105
  27. abstract_utilities/env_utils/__init__.py +0 -3
  28. abstract_utilities/env_utils/abstractEnv.py +0 -129
  29. abstract_utilities/env_utils/envy_it.py +0 -33
  30. abstract_utilities/env_utils/imports/__init__.py +0 -2
  31. abstract_utilities/env_utils/imports/imports.py +0 -8
  32. abstract_utilities/env_utils/imports/utils.py +0 -122
  33. abstract_utilities/file_utils/__init__.py +0 -3
  34. abstract_utilities/file_utils/file_utils/__init__.py +0 -6
  35. abstract_utilities/file_utils/file_utils/file_filters.py +0 -104
  36. abstract_utilities/file_utils/file_utils/imports.py +0 -1
  37. abstract_utilities/file_utils/file_utils/map_utils.py +0 -29
  38. abstract_utilities/file_utils/imports/__init__.py +0 -5
  39. abstract_utilities/file_utils/imports/classes.py +0 -381
  40. abstract_utilities/file_utils/imports/constants.py +0 -39
  41. abstract_utilities/file_utils/imports/file_functions.py +0 -10
  42. abstract_utilities/file_utils/imports/imports.py +0 -14
  43. abstract_utilities/file_utils/imports/module_imports.py +0 -9
  44. abstract_utilities/file_utils/req.py +0 -329
  45. abstract_utilities/robust_reader/imports/__init__.py +0 -1
  46. abstract_utilities/robust_reader/imports/imports.py +0 -12
  47. abstract_utilities/robust_readers/imports.py +0 -8
  48. abstract_utilities/safe_utils.py +0 -133
  49. abstract_utilities/ssh_utils/__init__.py +0 -3
  50. abstract_utilities/ssh_utils/classes.py +0 -127
  51. abstract_utilities/ssh_utils/imports.py +0 -10
  52. abstract_utilities/ssh_utils/pexpect_utils.py +0 -315
  53. abstract_utilities/ssh_utils/utils.py +0 -188
  54. abstract_utilities/string_utils.py +0 -12
  55. abstract_utilities-0.2.2.448.dist-info/RECORD +0 -83
  56. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.450.dist-info}/WHEEL +0 -0
  57. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.450.dist-info}/top_level.txt +0 -0
@@ -1,381 +0,0 @@
1
- from .imports import *
2
- from .module_imports import *
3
- from .constants import *
4
- def get_item_check_cmd(path, file=True, directory=False, exists=False):
5
- if (directory and file) or exists:
6
- typ = "e"
7
- elif file:
8
- typ = "f"
9
- elif directory:
10
- typ = "d"
11
- elif isinstance(file, str):
12
- if "f" in file:
13
- typ = "f"
14
- elif "d" in file:
15
- typ = "d"
16
- else:
17
- typ = "e"
18
- else:
19
- typ = "e"
20
- return f"test -{typ} {shlex.quote(path)} && echo __OK__ || true"
21
-
22
-
23
- def get_all_item_check_cmd(path, file=True, directory=True, exists=True):
24
- collects = []
25
- out_js = {}
26
-
27
- if file:
28
- collects.append("file")
29
- if directory:
30
- collects.append("dir")
31
- if exists:
32
- collects.append("exists")
33
-
34
- if not collects:
35
- return out_js
36
-
37
- path = shlex.quote(path)
38
- for typ in collects:
39
- t = typ[0] # f, d, or e
40
- out_js[typ] = f"test -{t} {path} && echo __OK__ || true"
41
-
42
- return out_js
43
-
44
-
45
- def is_file(
46
- path,
47
- user_at_host=None,
48
- password=None,
49
- key=None,
50
- env_path=None,
51
- **kwargs
52
- ):
53
- contingencies = list(set([user_at_host,password,key,env_path]))
54
- len_contingencies = len(contingencies)
55
- is_potential = (len_contingencies >1 or (None not in contingencies))
56
- if not is_potential:
57
- return os.path.isfile(path)
58
- cmd = get_item_check_cmd(path,file=True)
59
- return run_cmd(cmd=cmd,
60
- user_at_host=user_at_host,
61
- password=password,
62
- key=key,
63
- env_path=env_path,
64
- **kwargs
65
- )
66
- def is_dir(
67
- path,
68
- user_at_host=None,
69
- password=None,
70
- key=None,
71
- env_path=None,
72
- **kwargs
73
- ):
74
- contingencies = list(set([user_at_host,password,key,env_path]))
75
- len_contingencies = len(contingencies)
76
- is_potential = (len_contingencies >1 or (None not in contingencies))
77
- if not is_potential:
78
- return os.path.isdir(path)
79
- cmd = get_item_check_cmd(path,file=False,directory=True)
80
- return run_cmd(cmd=cmd,
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)
102
- return run_cmd(cmd=cmd,
103
- user_at_host=user_at_host,
104
- password=password,
105
- key=key,
106
- env_path=env_path,
107
- **kwargs
108
- )
109
- def is_any(
110
- path,
111
- user_at_host=None,
112
- password=None,
113
- key=None,
114
- env_path=None,
115
- **kwargs
116
- ):
117
- contingencies = list(set([user_at_host,password,key,env_path]))
118
- len_contingencies = len(contingencies)
119
- is_potential = (len_contingencies >1 or (None not in contingencies))
120
- if not is_potential:
121
- return os.path.exists(path)
122
- if is_potential == True:
123
- out_js = get_all_item_check_cmd(path,file=True,directory=True,exists=True)
124
- for typ,cmd in out_js.items():
125
- response = run_cmd(cmd=cmd,
126
- user_at_host=user_at_host,
127
- password=password,
128
- key=key,
129
- env_path=env_path,
130
- **kwargs
131
- )
132
- result = "__OK__" in (response or "")
133
- if result:
134
- return typ
135
- return None
136
- class PathBackend(Protocol):
137
- def join(self, *parts: str) -> str: ...
138
- def isfile(self, path: str) -> bool: ...
139
- def isdir(self, path: str) -> bool: ...
140
- def glob_recursive(self, base: str, **opts) -> List[str]: ...
141
- def listdir(self, base: str) -> List[str]: ...
142
-
143
- class LocalFS:
144
- def __init__(self, get_type=False, get_is_dir=False, get_is_file=False, get_is_exists=False, **kwargs):
145
- self.get_type = get_type
146
- self.get_is_dir = get_is_dir
147
- self.get_is_file = get_is_file
148
- self.get_is_exists = get_is_exists
149
-
150
- def join(self, *parts: str) -> str:
151
- return os.path.join(*parts)
152
-
153
- def isfile(self, path: str) -> bool:
154
- return os.path.isfile(path)
155
-
156
- def isdir(self, path: str) -> bool:
157
- return os.path.isdir(path)
158
-
159
- def isexists(self, path: str) -> bool:
160
- return os.path.exists(path)
161
-
162
- def istype(self, path: str) -> str | None:
163
- funcs_js = {"file": os.path.isfile, "dir": os.path.isdir, "exists": os.path.exists}
164
- for key, func in funcs_js.items():
165
- if func(path):
166
- return key
167
- return None
168
-
169
- def is_included(self, path, **kwargs):
170
- include_js = {}
171
- if self.get_type:
172
- include_js["typ"] = self.istype(path)
173
- if self.get_is_dir:
174
- include_js["dir"] = self.isdir(path)
175
- if self.get_is_file:
176
- include_js["file"] = self.isfile(path)
177
- if self.get_is_exists:
178
- include_js["exists"] = self.isexists(path)
179
- return include_js
180
- def glob_recursive(self, base: str, **opts) -> List[str]:
181
- """
182
- opts:
183
- - maxdepth: int | None
184
- - mindepth: int (default 1)
185
- - follow_symlinks: bool
186
- - include_dirs: bool
187
- - include_files: bool
188
- - exclude_hidden: bool
189
- """
190
- maxdepth = opts.get("maxdepth")
191
- mindepth = opts.get("mindepth", 1)
192
- follow = opts.get("follow_symlinks", False)
193
- want_d = opts.get("include_dirs", True)
194
- want_f = opts.get("include_files", True)
195
- hide = opts.get("exclude_hidden", False)
196
-
197
- results: List[str] = []
198
- base_depth = os.path.normpath(base).count(os.sep)
199
-
200
- for root, dirs, files in os.walk(base, followlinks=follow):
201
- depth = os.path.normpath(root).count(os.sep) - base_depth
202
- if maxdepth is not None and depth > maxdepth:
203
- dirs[:] = []
204
- continue
205
- if want_d and depth >= mindepth:
206
- for d in dirs:
207
- if hide and d.startswith("."): continue
208
- results.append(os.path.join(root, d))
209
- if want_f and depth >= mindepth:
210
- for f in files:
211
- if hide and f.startswith("."): continue
212
- results.append(os.path.join(root, f))
213
- return results
214
-
215
- def listdir(self, base: str) -> List[str]:
216
- try:
217
- return [os.path.join(base, name) for name in os.listdir(base)]
218
- except Exception:
219
- return []
220
- def get_spec_kwargs(
221
- user_at_host=None,
222
- password=None,
223
- key=None,
224
- env_path=None,
225
- kwargs=None
226
- ):
227
- kwargs = kwargs or {}
228
- kwargs["user_at_host"] = kwargs.get("user_at_host") or user_at_host
229
- kwargs["password"] = kwargs.get("password") or password
230
- kwargs["key"] = kwargs.get("key") or key
231
- kwargs["env_path"] = kwargs.get("env_path") or env_path
232
- return kwargs
233
- class SSHFS:
234
- """Remote POSIX backend via run_remote_cmd."""
235
- def __init__(self, password=None, key=None, env_path=None,
236
- get_type=False, get_is_dir=False, get_is_file=False, get_is_exists=False, **kwargs):
237
- self.user_at_host = kwargs.get('user_at_host') or kwargs.get('user') or kwargs.get('host')
238
- self.password = password
239
- self.key = key
240
- self.env_path = env_path
241
- self.get_type = get_type
242
- self.get_is_dir = get_is_dir
243
- self.get_is_file = get_is_file
244
- self.get_is_exists = get_is_exists
245
-
246
- def cell_spec_kwargs(self, func, path, **kwargs):
247
- kwargs = get_spec_kwargs(
248
- user_at_host=self.user_at_host,
249
- password=self.password,
250
- key=self.key,
251
- env_path=self.env_path,
252
- kwargs=kwargs
253
- )
254
- return func(path, **kwargs)
255
-
256
- def is_included(self, path, **kwargs):
257
- include_js = {}
258
- if self.get_type:
259
- include_js["typ"] = self.istype(path, **kwargs)
260
- if self.get_is_dir:
261
- include_js["dir"] = self.isdir(path, **kwargs)
262
- if self.get_is_file:
263
- include_js["file"] = self.isfile(path, **kwargs)
264
- if self.get_is_exists:
265
- include_js["exists"] = self.isexists(path, **kwargs)
266
- return include_js
267
-
268
- def join(self, *parts: str) -> str:
269
- return posixpath.join(*parts)
270
-
271
- def isfile(self, path: str, **kwargs) -> bool:
272
- out = self.cell_spec_kwargs(is_file, path, **kwargs)
273
- return "__OK__" in (out or "")
274
-
275
- def isdir(self, path: str, **kwargs) -> bool:
276
- out = self.cell_spec_kwargs(is_dir, path, **kwargs)
277
- return "__OK__" in (out or "")
278
-
279
- def isexists(self, path: str, **kwargs) -> bool:
280
- out = self.cell_spec_kwargs(is_exists, path, **kwargs)
281
- return "__OK__" in (out or "")
282
-
283
- def istype(self, path: str, **kwargs) -> str | None:
284
- out = self.cell_spec_kwargs(is_any, path, **kwargs)
285
- return out
286
-
287
- def glob_recursive(self, base: str, **opts) -> List[str]:
288
- maxdepth = opts.get("maxdepth")
289
- mindepth = opts.get("mindepth", 1)
290
- follow = opts.get("follow_symlinks", False)
291
- want_d = opts.get("include_dirs", True)
292
- want_f = opts.get("include_files", True)
293
- hide = opts.get("exclude_hidden", False)
294
-
295
- parts = []
296
- if follow:
297
- parts.append("-L")
298
- parts += ["find", shlex.quote(base)]
299
- if mindepth is not None:
300
- parts += ["-mindepth", str(mindepth)]
301
- if maxdepth is not None:
302
- parts += ["-maxdepth", str(maxdepth)]
303
-
304
- type_filters = []
305
- if want_d and not want_f:
306
- type_filters = ["-type", "d"]
307
- elif want_f and not want_d:
308
- type_filters = ["-type", "f"]
309
-
310
- hidden_filter = []
311
- if hide:
312
- hidden_filter = ["!", "-regex", r".*/\..*"]
313
-
314
- cmd = " ".join(parts + type_filters + hidden_filter + ["-printf", r"'%p\n'"]) + " 2>/dev/null"
315
- out = run_remote_cmd(self.user_at_host, cmd)
316
- return [line.strip().strip("'") for line in (out or "").splitlines() if line.strip()]
317
-
318
- def listdir(self, base: str) -> List[str]:
319
- cmd = f"find {shlex.quote(base)} -maxdepth 1 -mindepth 1 -printf '%p\\n' 2>/dev/null"
320
- out = run_remote_cmd(self.user_at_host, cmd)
321
- return [line.strip() for line in (out or "").splitlines() if line.strip()]
322
-
323
-
324
-
325
- def try_group(pre,item,strings):
326
-
327
- try:
328
- m = pre.match(item)
329
- for i,string in enumerate(strings):
330
- strings[i] = m.group(string)
331
-
332
- except:
333
- return None
334
- return strings
335
- def normalize_items(
336
- paths: Iterable[str],
337
- user_at_host=None,
338
- get_type=True,
339
- get_is_dir=False,
340
- get_is_file=False,
341
- get_is_exists=False,
342
- **kwargs
343
- ) -> List[tuple[PathBackend, str, dict]]:
344
- pairs: List[tuple[PathBackend, str, dict]] = []
345
- host = user_at_host or kwargs.get("host") or kwargs.get("user")
346
- paths = make_list(paths)
347
- for item in paths:
348
- if not item:
349
- continue
350
-
351
- strings = try_group(REMOTE_RE, item, ["host", "path"])
352
- fs_host = None
353
- nuhost = None
354
-
355
- if (strings and None not in strings) or host:
356
- if strings and None not in strings:
357
- nuhost = strings[0]
358
- item = strings[1] or item
359
- nuhost = nuhost or host
360
- fs_host = SSHFS(
361
- nuhost,
362
- user_at_host=user_at_host,
363
- get_type=get_type,
364
- get_is_dir=get_is_dir,
365
- get_is_file=get_is_file,
366
- get_is_exists=get_is_exists,
367
- **kwargs
368
- )
369
- else:
370
- fs_host = LocalFS(
371
- get_type=get_type,
372
- get_is_dir=get_is_dir,
373
- get_is_file=get_is_file,
374
- get_is_exists=get_is_exists
375
- )
376
-
377
- includes = fs_host.is_included(item)
378
- pairs.append((fs_host, item, includes))
379
- return pairs
380
-
381
-
@@ -1,39 +0,0 @@
1
- from .imports import *
2
- from .module_imports import *
3
- @dataclass
4
- class ScanConfig:
5
- allowed_exts: Set[str]
6
- unallowed_exts: Set[str]
7
- exclude_types: Set[str]
8
- exclude_dirs: List[str] = field(default_factory=list)
9
- exclude_patterns: List[str] = field(default_factory=list)
10
- DEFAULT_ALLOWED_EXTS: Set[str] = {
11
- ".py", ".pyw", # python
12
- ".js", ".jsx", ".ts", ".tsx", ".mjs", # JS/TS
13
- ".html", ".htm", ".xml", # markup
14
- ".css", ".scss", ".sass", ".less", # styles
15
- ".json", ".yaml", ".yml", ".toml", ".ini", # configs
16
- ".cfg", ".md", ".markdown", ".rst", # docs
17
- ".sh", ".bash", ".env", # scripts/env
18
- ".txt" # plain text
19
- }
20
-
21
- DEFAULT_EXCLUDE_TYPES: Set[str] = {
22
- "image", "video", "audio", "presentation",
23
- "spreadsheet", "archive", "executable"
24
- }
25
-
26
- # never want these—even if they sneak into ALLOWED
27
- _unallowed = set(get_media_exts(DEFAULT_EXCLUDE_TYPES)) | {'.bak', '.shp', '.cpg', '.dbf', '.shx','.geojson',".pyc",'.shx','.geojson','.prj','.sbn','.sbx'}
28
- DEFAULT_UNALLOWED_EXTS = {e for e in _unallowed if e not in DEFAULT_ALLOWED_EXTS}
29
-
30
- DEFAULT_EXCLUDE_DIRS: Set[str] = {
31
- "node_modules", "old","__pycache__", "backups", "backup", "backs", "trash", "depriciated", "old", "__init__"
32
- }
33
-
34
- DEFAULT_EXCLUDE_PATTERNS: Set[str] = {
35
- "__init__*", "*.tmp", "*.log", "*.lock", "*.zip","*~"
36
- }
37
- REMOTE_RE = re.compile(r"^(?P<host>[^:\s]+@[^:\s]+):(?P<path>/.*)$")
38
- AllowedPredicate = Optional[Callable[[str], bool]]
39
- DEFAULT_EXCLUDE_FILE_PATTERNS=DEFAULT_EXCLUDE_PATTERNS
@@ -1,10 +0,0 @@
1
- from .imports import *
2
- def get_caller_path():
3
- i = i or 1
4
- frame = inspect.stack()[i]
5
- return os.path.abspath(frame.filename)
6
- def get_caller_dir(i=None):
7
- i = i or 1
8
- frame = inspect.stack()[i]
9
- abspath = os.path.abspath(frame.filename)
10
- return os.path.dirname(abspath)
@@ -1,14 +0,0 @@
1
- import pandas as pd
2
- from typing import *
3
- import geopandas as gpd
4
- from pathlib import Path
5
- from types import ModuleType
6
- from datetime import datetime
7
- from pdf2image import convert_from_path
8
- from dataclasses import dataclass, field
9
- from werkzeug.utils import secure_filename
10
- from werkzeug.datastructures import FileStorage
11
- import fnmatch, fnmatch,shlex, os, glob, platform, textwrap, pkgutil,time
12
- import tempfile,shutil,logging,ezodf,fnmatch,pytesseract,pdfplumber,re
13
- import textwrap, sys, types, importlib, importlib.util, inspect,PyPDF2
14
-
@@ -1,9 +0,0 @@
1
- from ...string_clean import eatAll
2
- from ...list_utils import make_list
3
- from ...type_utils import get_media_exts, is_media_type,MIME_TYPES,is_str
4
- from ...ssh_utils import *
5
- from ...env_utils import *
6
- from ...read_write_utils import *
7
- from ...abstract_classes import SingletonMeta
8
- from ...log_utils import get_logFile
9
- from ...class_utils import get_caller,get_caller_path,get_caller_dir