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

@@ -1,137 +1,58 @@
1
- from .imports import *
2
- # -------- Public API drop-ins that mirror your originals --------
1
+ from pathlib import Path
2
+ from typing import *
3
+ import fnmatch, os, glob
3
4
  from .filter_params import *
4
- from .file_filters import *
5
- # -------------------------------------------------------------
6
- # Wrapper: respects your original API and naming conventions
7
- # -------------------------------------------------------------
8
-
5
+ ##from abstract_utilities import make_list,get_media_exts, is_media_type
9
6
  def get_allowed_predicate(allowed=None):
10
- if allowed is not False:
11
- if allowed is True:
7
+ if allowed != False:
8
+ if allowed == True:
12
9
  allowed = None
13
10
  allowed = allowed or make_allowed_predicate()
14
11
  else:
15
12
  def allowed(*args):
16
13
  return True
14
+ allowed = allowed
17
15
  return allowed
18
-
19
-
20
- # -------------------------------------------------------------
21
- # Remote-aware globbing
22
- # -------------------------------------------------------------
23
- def get_globs(items, recursive: bool = True, allowed=None, **kwargs):
24
- """
25
- Behaves like your original get_globs(), but can traverse both
26
- local and remote paths transparently via normalize_items().
27
- """
16
+ def get_globs(items,recursive: bool = True,allowed=None):
28
17
  glob_paths = []
29
- roots = [p for p in make_list(items) if p]
30
-
31
- kwargs.setdefault("mindepth", 0)
32
- if not recursive:
33
- kwargs.setdefault("maxdepth", 1)
34
-
35
- for fs, root, _ in normalize_items(roots, **kwargs):
36
- # use the backend's recursive walker
37
- nu_items = fs.glob_recursive(root, **kwargs)
18
+ items = [item for item in make_list(items) if item]
19
+ for item in items:
20
+ pattern = os.path.join(item, "**/*") # include all files recursively\n
21
+ nuItems = glob.glob(pattern, recursive=recursive)
38
22
  if allowed:
39
-
40
- nu_items = [n for n in nu_items if n and allowed(n)]
41
-
42
- glob_paths += nu_items
23
+ nuItems = [nuItem for nuItem in nuItems if nuItem and allowed(nuItem)]
24
+ glob_paths += nuItems
43
25
  return glob_paths
44
-
45
-
46
- # -------------------------------------------------------------
47
- # Allowed filters
48
- # -------------------------------------------------------------
49
- def get_allowed_files(items, allowed=True, **kwargs):
26
+ def get_allowed_files(items,allowed=True):
50
27
  allowed = get_allowed_predicate(allowed=allowed)
51
- out = []
52
- for fs, item, _ in normalize_items(items, **kwargs):
53
- if fs.isfile(item) and allowed(item):
54
- out.append(item)
55
- return out
56
-
57
-
58
- def get_allowed_dirs(items, allowed=False, **kwargs):
28
+ return [item for item in items if item and os.path.isfile(item) and allowed(item)]
29
+ def get_allowed_dirs(items,allowed=False):
59
30
  allowed = get_allowed_predicate(allowed=allowed)
60
- out = []
61
- for fs, item, _ in normalize_items(items, **kwargs):
62
- if fs.isdir(item) and allowed(item):
63
- out.append(item)
64
- return out
65
-
31
+ return [item for item in items if item and os.path.isdir(item) and allowed(item)]
66
32
 
67
- # -------------------------------------------------------------
68
- # Filtered sets
69
- # -------------------------------------------------------------
70
- def get_filtered_files(items, allowed=None, files=None, **kwargs):
33
+ def get_filtered_files(items,allowed=None,files = []):
71
34
  allowed = get_allowed_predicate(allowed=allowed)
72
- files = set(files or [])
73
- out = []
74
- for fs, root, _ in normalize_items(items, **kwargs):
75
- for p in fs.glob_recursive(root, **kwargs):
76
- if p in files:
77
- continue
78
- if allowed(p) and fs.isfile(p):
79
- out.append(p)
80
- return out
81
-
82
-
83
- def get_filtered_dirs(items, allowed=None, dirs=None, **kwargs):
35
+ glob_paths = get_globs(items)
36
+ return [glob_path for glob_path in glob_paths if glob_path and os.path.isfile(glob_path) and glob_path not in files and allowed(glob_path)]
37
+ def get_filtered_dirs(items,allowed=None,dirs = []):
84
38
  allowed = get_allowed_predicate(allowed=allowed)
85
- dirs = set(dirs or [])
86
- out = []
87
- for fs, root, _ in normalize_items(items, **kwargs):
88
- for p in fs.glob_recursive(root, **kwargs):
89
- if p in dirs:
90
- continue
91
- if allowed(p) and fs.isdir(p):
92
- out.append(p)
93
- return out
94
-
95
-
96
- # -------------------------------------------------------------
97
- # Recursive expansion
98
- # -------------------------------------------------------------
99
- def get_all_allowed_files(items, allowed=None, **kwargs):
100
- dirs = get_all_allowed_dirs(items, allowed=allowed, **kwargs)
101
- files = get_allowed_files(items, allowed=allowed, **kwargs)
102
- seen = set(files)
103
- for fs, directory, _ in normalize_items(dirs, **kwargs):
104
- for p in fs.glob_recursive(directory, **kwargs):
105
- if p in seen:
106
- continue
107
- if allowed and not allowed(p):
108
- continue
109
- if fs.isfile(p):
110
- files.append(p)
111
- seen.add(p)
39
+ glob_paths = get_globs(items)
40
+ return [glob_path for glob_path in glob_paths if glob_path and os.path.isdir(glob_path) and glob_path not in dirs and allowed(glob_path)]
41
+
42
+ def get_all_allowed_files(items,allowed=None):
43
+ dirs = get_all_allowed_dirs(items)
44
+ files = get_allowed_files(items)
45
+ nu_files = []
46
+ for directory in dirs:
47
+ files += get_filtered_files(directory,allowed=allowed,files=files)
112
48
  return files
113
-
114
-
115
- def get_all_allowed_dirs(items, allowed=None, **kwargs):
49
+ def get_all_allowed_dirs(items,allowed=None):
116
50
  allowed = get_allowed_predicate(allowed=allowed)
117
- out = []
118
- seen = set()
119
- for fs, root, _ in normalize_items(items, **kwargs):
120
- if fs.isdir(root) and allowed(root):
121
- out.append(root)
122
- seen.add(root)
123
- for p in fs.glob_recursive(root, **kwargs):
124
- if p in seen:
125
- continue
126
- if allowed(p) and fs.isdir(p):
127
- out.append(p)
128
- seen.add(p)
129
- return out
130
-
131
-
132
- # -------------------------------------------------------------
133
- # Unified directory scan
134
- # -------------------------------------------------------------
51
+ dirs = get_allowed_dirs(items)
52
+ nu_dirs=[]
53
+ for directory in dirs:
54
+ nu_dirs += get_filtered_dirs(directory,allowed=allowed,dirs=nu_dirs)
55
+ return nu_dirs
135
56
  def get_files_and_dirs(
136
57
  directory: str,
137
58
  cfg: Optional["ScanConfig"] = None,
@@ -140,15 +61,11 @@ def get_files_and_dirs(
140
61
  exclude_types: Optional[Set[str]] = False,
141
62
  exclude_dirs: Optional[List[str]] = False,
142
63
  exclude_patterns: Optional[List[str]] = False,
143
- add=False,
64
+ add = False,
144
65
  recursive: bool = True,
145
66
  include_files: bool = True,
146
67
  **kwargs
147
- ):
148
- """
149
- Same public signature as your original get_files_and_dirs(),
150
- but powered by backend objects (LocalFS or SSHFS).
151
- """
68
+ ):
152
69
  cfg = cfg or define_defaults(
153
70
  allowed_exts=allowed_exts,
154
71
  unallowed_exts=unallowed_exts,
@@ -156,43 +73,34 @@ def get_files_and_dirs(
156
73
  exclude_dirs=exclude_dirs,
157
74
  exclude_patterns=exclude_patterns,
158
75
  add=add
159
- )
76
+ )
160
77
  allowed = make_allowed_predicate(cfg)
161
- items = []
162
- files = []
78
+ items=[]
79
+ files =[]
163
80
  if recursive:
164
- items = get_globs(directory, recursive=recursive, allowed=allowed, **kwargs)
81
+ items = get_globs(directory,recursive=recursive,allowed=allowed)
165
82
  else:
166
- for fs, base, _ in normalize_items(make_list(directory), **kwargs):
167
- try:
168
- items += [fs.join(base, name) for name in fs.listdir(base)]
169
- except Exception:
170
- pass
171
-
172
- dirs = get_allowed_dirs(items, allowed=allowed, **kwargs)
83
+ directories = make_list(directory)
84
+ for directory in directories:
85
+ items +=[os.path.join(directory,item) for item in os.listdir(directory)]
86
+ dirs = get_allowed_dirs(items,allowed=allowed)
173
87
  if include_files:
174
- files = get_allowed_files(items, allowed=allowed, **kwargs)
175
- return dirs, files
176
-
177
-
178
- # -------------------------------------------------------------
179
- # Unchanged predicate builder
180
- # -------------------------------------------------------------
88
+ files = get_allowed_files(items,allowed=allowed)
89
+ return dirs,files
181
90
  def make_allowed_predicate(cfg: ScanConfig) -> Callable[[str], bool]:
182
91
  def allowed(path: str) -> bool:
183
92
  p = Path(path)
184
93
  name = p.name.lower()
185
94
  path_str = str(p).lower()
186
-
187
- # A) directory exclusions
95
+ # A) directories
188
96
  if cfg.exclude_dirs:
189
97
  for dpat in cfg.exclude_dirs:
190
98
  if dpat in path_str or fnmatch.fnmatch(name, dpat.lower()):
191
99
  if p.is_dir() or dpat in path_str:
192
100
  return False
193
101
 
194
- # B) filename pattern exclusions
195
102
  if cfg.exclude_patterns:
103
+ # B) filename patterns
196
104
  for pat in cfg.exclude_patterns:
197
105
  if fnmatch.fnmatch(name, pat.lower()):
198
106
  return False
@@ -200,8 +108,106 @@ def make_allowed_predicate(cfg: ScanConfig) -> Callable[[str], bool]:
200
108
  # C) extension gates
201
109
  if p.is_file():
202
110
  ext = p.suffix.lower()
203
- if (cfg.allowed_exts and ext not in cfg.allowed_exts) or \
204
- (cfg.unallowed_exts and ext in cfg.unallowed_exts):
111
+ if (cfg.allowed_exts and ext not in cfg.allowed_exts) or (cfg.unallowed_exts and ext in cfg.unallowed_exts):
205
112
  return False
206
113
  return True
207
114
  return allowed
115
+ def collect_filepaths(
116
+ directory: List[str],
117
+ cfg: ScanConfig=None,
118
+ allowed_exts: Optional[Set[str]] = False,
119
+ unallowed_exts: Optional[Set[str]] = False,
120
+ exclude_types: Optional[Set[str]] = False,
121
+ exclude_dirs: Optional[List[str]] = False,
122
+ exclude_patterns: Optional[List[str]] = False,
123
+ add=False,
124
+ allowed: Optional[Callable[[str], bool]] = None,
125
+ **kwargs
126
+ ) -> List[str]:
127
+ cfg = cfg or define_defaults(
128
+ allowed_exts=allowed_exts,
129
+ unallowed_exts=unallowed_exts,
130
+ exclude_types=exclude_types,
131
+ exclude_dirs=exclude_dirs,
132
+ exclude_patterns=exclude_patterns,
133
+ add = add
134
+ )
135
+ allowed = allowed or make_allowed_predicate(cfg)
136
+ directories = make_list(directory)
137
+ roots = [r for r in directories if r]
138
+
139
+ # your existing helpers (get_dirs, get_globs, etc.) stay the same
140
+ original_dirs = get_allowed_dirs(roots, allowed=allowed)
141
+ original_globs = get_globs(original_dirs)
142
+ files = get_allowed_files(original_globs, allowed=allowed)
143
+
144
+ for d in get_filtered_dirs(original_dirs, allowed=allowed):
145
+ files += get_filtered_files(d, allowed=allowed, files=files)
146
+
147
+ # de-dupe while preserving order
148
+ seen, out = set(), []
149
+ for f in files:
150
+ if f not in seen:
151
+ seen.add(f)
152
+ out.append(f)
153
+ return out
154
+
155
+
156
+ def _fast_walk(
157
+ root: Path,
158
+ exts: Iterable[str],
159
+ skip_dirs: Iterable[str] = (),
160
+ skip_patterns: Iterable[str] = (),
161
+ ) -> List[Path]:
162
+ exts = tuple(exts)
163
+ skip_dirs = set(sd.lower() for sd in skip_dirs or ())
164
+ skip_patterns = tuple(sp.lower() for sp in (skip_patterns or ()))
165
+
166
+ out = []
167
+ for p in root.rglob("*"):
168
+ # skip directories by name hit
169
+ if p.is_dir():
170
+ name = p.name.lower()
171
+ if name in skip_dirs:
172
+ # rglob doesn't let us prune mid-iteration cleanly; we just won't collect under it
173
+ continue
174
+ # nothing to collect for dirs
175
+ continue
176
+
177
+ # file filters
178
+ name = p.name.lower()
179
+ if any(fnmatch.fnmatch(name, pat) for pat in skip_patterns):
180
+ continue
181
+ if p.suffix.lower() in exts:
182
+ out.append(p)
183
+
184
+ # de-dup and normalize
185
+ return sorted({pp.resolve() for pp in out})
186
+
187
+
188
+ def enumerate_source_files(
189
+ src_root: Path,
190
+ cfg: Optional["ScanConfig"] = None,
191
+ *,
192
+ exts: Optional[Iterable[str]] = None,
193
+ fast_skip_dirs: Optional[Iterable[str]] = None,
194
+ fast_skip_patterns: Optional[Iterable[str]] = None,
195
+ ) -> List[Path]:
196
+ """
197
+ Unified enumerator:
198
+ - If `cfg` is provided: use collect_filepaths(...) with full rules.
199
+ - Else: fast walk using rglob over `exts` (defaults to EXTS) with optional light excludes.
200
+ """
201
+ src_root = Path(src_root)
202
+
203
+ if cfg is not None:
204
+ files = collect_filepaths([str(src_root)], cfg=cfg)
205
+ return sorted({Path(f).resolve() for f in files})
206
+
207
+ # Fast mode
208
+ return _fast_walk(
209
+ src_root,
210
+ exts or EXTS,
211
+ skip_dirs=fast_skip_dirs or (),
212
+ skip_patterns=fast_skip_patterns or (),
213
+ )
@@ -343,7 +343,7 @@ def normalize_items(
343
343
  ) -> List[tuple[PathBackend, str, dict]]:
344
344
  pairs: List[tuple[PathBackend, str, dict]] = []
345
345
  host = user_at_host or kwargs.get("host") or kwargs.get("user")
346
-
346
+ paths = make_list(paths)
347
347
  for item in paths:
348
348
  if not item:
349
349
  continue
@@ -8,6 +8,7 @@ from pdf2image import convert_from_path
8
8
  from dataclasses import dataclass, field
9
9
  from werkzeug.utils import secure_filename
10
10
  from werkzeug.datastructures import FileStorage
11
- import fnmatch, fnmatch,shlex, os, glob, platform, textwrap, pkgutil
11
+ import fnmatch, fnmatch,shlex, os, glob, platform, textwrap, pkgutil,time
12
12
  import tempfile,shutil,logging,ezodf,fnmatch,pytesseract,pdfplumber,re
13
13
  import textwrap, sys, types, importlib, importlib.util, inspect,PyPDF2
14
+
@@ -5,4 +5,4 @@ from ...ssh_utils import *
5
5
  from ...env_utils import *
6
6
  from ...read_write_utils import *
7
7
  from ...abstract_classes import SingletonMeta
8
-
8
+ from ...log_utils import get_logFile
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_utilities
3
- Version: 0.2.2.430
3
+ Version: 0.2.2.432
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
@@ -42,17 +42,17 @@ abstract_utilities/file_utils/req.py,sha256=CsdGHAWIHOLqjzyoOSZ7XYbNciVYnTgaUs5q
42
42
  abstract_utilities/file_utils/file_utils/__init__.py,sha256=fm_uNRnfKfZOIg7e1HXhWbHac5VoUgRD2iTO5cxLkA0,160
43
43
  abstract_utilities/file_utils/file_utils/file_filters.py,sha256=khfbonAPEAhW1wxfFo0I4dawYPCrIKEjNc7VKb1RvzA,3437
44
44
  abstract_utilities/file_utils/file_utils/file_reader.py,sha256=2MRj2PGKq4C-iKL8dmhHwWnhmA8GPVsNaWkTREOF9vo,24545
45
- abstract_utilities/file_utils/file_utils/file_utils.py,sha256=0tZlCD3faJSNc4AgtsN-EKojmQT0uVMHOMe75_daGmw,6992
45
+ abstract_utilities/file_utils/file_utils/file_utils.py,sha256=2aVuD0sB-P2gmo_kUsE11aHc6WzLvHUAerMkmy3y9vk,7751
46
46
  abstract_utilities/file_utils/file_utils/filter_params.py,sha256=NF692W0cBhEsbtmaVzb8EKMAasasHDElSRaC9fnzYwE,3382
47
47
  abstract_utilities/file_utils/file_utils/imports.py,sha256=SXCMBuHUwqXbfRBk4LjKehsBKZa8-Po5UfEcNTwn4Es,24
48
48
  abstract_utilities/file_utils/file_utils/map_utils.py,sha256=B_MlkLP8s-o0yU0R3Y2LcTpBntBzysJO18qq181xz9c,1043
49
49
  abstract_utilities/file_utils/file_utils/pdf_utils.py,sha256=D_wg8h-SapCvqinxRIKxMri1jWZNpr5jGvKq9EJePfY,10335
50
50
  abstract_utilities/file_utils/imports/__init__.py,sha256=VWN_3t0gRSYCalXI0nRLEUB3O2kbqA_Y8wnFq_m5F7A,131
51
- abstract_utilities/file_utils/imports/classes.py,sha256=BlAI-_U3fj4ESi-DbqWBDo9xbEISwG5n1-u3MWLyTFI,12231
51
+ abstract_utilities/file_utils/imports/classes.py,sha256=zw16D_h5AxJiks4ydbqkWkXVfvgmE-BpiC4eKInY_KI,12259
52
52
  abstract_utilities/file_utils/imports/constants.py,sha256=kSWXjZrbM7MmkytpiCFnsEJcfhPGI5ztUmrvTmT1xpU,1571
53
53
  abstract_utilities/file_utils/imports/file_functions.py,sha256=25yta20DDsdgenXYjpm4Ma3Fd6WK9Q16EjyhcZubDFg,291
54
- abstract_utilities/file_utils/imports/imports.py,sha256=OjHHuys4ue01PjTIBJuOBAseWUN9pxmAvWsPEj0QcCw,532
55
- abstract_utilities/file_utils/imports/module_imports.py,sha256=llHjA8krD-4AA0SbCybeyLza5iWrzt0HvNIxfX3G-_w,280
54
+ abstract_utilities/file_utils/imports/imports.py,sha256=mrXR2rEpb12Wve91eQehSxwR-gqc_UxJnqBKTrf7hjU,538
55
+ abstract_utilities/file_utils/imports/module_imports.py,sha256=FZTwNZFi2DmWzooJZHVXzY_HA6_u9tZzOoIjmrz1YB4,316
56
56
  abstract_utilities/robust_reader/__init__.py,sha256=7JVGEqZ2VFyFF06cqQ8TFz8EyreOB7Jhisnd69rxL-8,28
57
57
  abstract_utilities/robust_reader/file_reader2.py,sha256=U-5opkLu-bct091Eb-5CiNBTf0UFoSITYi8zR-Sz38w,25077
58
58
  abstract_utilities/robust_reader/file_readers.py,sha256=U-5opkLu-bct091Eb-5CiNBTf0UFoSITYi8zR-Sz38w,25077
@@ -75,7 +75,7 @@ abstract_utilities/ssh_utils/classes.py,sha256=3Q9BfLpyagNFYyiF4bt-5UCezeUJv9NK9
75
75
  abstract_utilities/ssh_utils/imports.py,sha256=7-pVJK1RfR0KiZsv0mNYGPuNXA4iYqmDvqbAR9h1llU,371
76
76
  abstract_utilities/ssh_utils/pexpect_utils.py,sha256=JBdOIXBTXAqE5TrsFjmPWJgwSaWyRJN8rbJ6y3_zKPY,10556
77
77
  abstract_utilities/ssh_utils/utils.py,sha256=smUWAx3nW1h0etTndJ_te9bkUX5YzQ8kYd9_gD1TXLk,4882
78
- abstract_utilities-0.2.2.430.dist-info/METADATA,sha256=Ynjx-XrAK_F-ZvDVdxam4jmai8qDcbbIdpMiExh8uhg,28108
79
- abstract_utilities-0.2.2.430.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
80
- abstract_utilities-0.2.2.430.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
81
- abstract_utilities-0.2.2.430.dist-info/RECORD,,
78
+ abstract_utilities-0.2.2.432.dist-info/METADATA,sha256=yvTQRtwB1ve7WGeFUz88CCow62AcO-MVL1oWj9h8W-w,28108
79
+ abstract_utilities-0.2.2.432.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
80
+ abstract_utilities-0.2.2.432.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
81
+ abstract_utilities-0.2.2.432.dist-info/RECORD,,