abstract-utilities 0.2.2.449__py3-none-any.whl → 0.2.2.476__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.
- abstract_utilities/__init__.py +18 -44
- abstract_utilities/abstract_classes.py +49 -0
- abstract_utilities/class_utils.py +38 -3
- abstract_utilities/cmd_utils/imports/__init__.py +1 -0
- abstract_utilities/cmd_utils/imports/imports.py +10 -0
- abstract_utilities/cmd_utils/pexpect_utils.py +310 -0
- abstract_utilities/cmd_utils/user_utils.py +1 -1
- abstract_utilities/compare_utils/__init__.py +3 -0
- abstract_utilities/compare_utils/best_match.py +150 -0
- abstract_utilities/{compare_utils.py → compare_utils/compare_utils.py} +1 -1
- abstract_utilities/compare_utils/find_value.py +105 -0
- abstract_utilities/dynimport.py +7 -15
- abstract_utilities/env_utils/__init__.py +3 -0
- abstract_utilities/env_utils/abstractEnv.py +129 -0
- abstract_utilities/env_utils/envy_it.py +33 -0
- abstract_utilities/env_utils/imports/__init__.py +2 -0
- abstract_utilities/env_utils/imports/imports.py +8 -0
- abstract_utilities/env_utils/imports/utils.py +122 -0
- abstract_utilities/file_utils/__init__.py +3 -0
- abstract_utilities/file_utils/file_utils/__init__.py +8 -0
- abstract_utilities/file_utils/file_utils/file_filters.py +104 -0
- abstract_utilities/{robust_reader → file_utils/file_utils}/file_reader.py +5 -19
- abstract_utilities/{robust_readers/file_filters.py → file_utils/file_utils/file_utils.py} +5 -4
- abstract_utilities/{robust_readers → file_utils/file_utils}/filter_params.py +1 -38
- abstract_utilities/file_utils/file_utils/find_collect.py +154 -0
- abstract_utilities/file_utils/file_utils/imports/__init__.py +3 -0
- abstract_utilities/file_utils/file_utils/imports/constants.py +39 -0
- abstract_utilities/file_utils/file_utils/imports/file_functions.py +10 -0
- abstract_utilities/file_utils/file_utils/imports/imports.py +39 -0
- abstract_utilities/file_utils/file_utils/imports/module_imports.py +13 -0
- abstract_utilities/file_utils/file_utils/imports.py +10 -0
- abstract_utilities/file_utils/file_utils/map_utils.py +29 -0
- abstract_utilities/{robust_reader → file_utils/file_utils}/pdf_utils.py +1 -9
- abstract_utilities/file_utils/file_utils/type_checks.py +82 -0
- abstract_utilities/file_utils/imports/__init__.py +4 -0
- abstract_utilities/file_utils/imports/classes.py +381 -0
- abstract_utilities/file_utils/imports/clean_imps.py +158 -0
- abstract_utilities/file_utils/imports/constants.py +39 -0
- abstract_utilities/file_utils/imports/file_functions.py +10 -0
- abstract_utilities/file_utils/imports/imports.py +65 -0
- abstract_utilities/file_utils/imports/module_imports.py +13 -0
- abstract_utilities/file_utils/req.py +329 -0
- abstract_utilities/json_utils.py +35 -0
- abstract_utilities/log_utils.py +14 -3
- abstract_utilities/path_utils.py +90 -6
- abstract_utilities/read_write_utils.py +176 -154
- abstract_utilities/robust_reader/__init__.py +1 -1
- abstract_utilities/robust_reader/imports/__init__.py +1 -0
- abstract_utilities/robust_reader/imports/imports.py +3 -0
- abstract_utilities/robust_readers/__init__.py +0 -1
- abstract_utilities/robust_readers/import_utils/__init__.py +1 -0
- abstract_utilities/robust_readers/import_utils/clean_imports.py +175 -0
- abstract_utilities/robust_readers/imports.py +8 -0
- abstract_utilities/robust_readers/initFuncGen.py +92 -76
- abstract_utilities/safe_utils.py +133 -0
- abstract_utilities/ssh_utils/__init__.py +3 -0
- abstract_utilities/ssh_utils/classes.py +127 -0
- abstract_utilities/ssh_utils/imports.py +10 -0
- abstract_utilities/ssh_utils/pexpect_utils.py +315 -0
- abstract_utilities/ssh_utils/utils.py +188 -0
- abstract_utilities/string_clean.py +40 -1
- abstract_utilities/string_utils.py +48 -0
- abstract_utilities/type_utils.py +25 -2
- {abstract_utilities-0.2.2.449.dist-info → abstract_utilities-0.2.2.476.dist-info}/METADATA +15 -4
- abstract_utilities-0.2.2.476.dist-info/RECORD +92 -0
- {abstract_utilities-0.2.2.449.dist-info → abstract_utilities-0.2.2.476.dist-info}/WHEEL +1 -1
- abstract_utilities-0.2.2.449.dist-info/RECORD +0 -49
- {abstract_utilities-0.2.2.449.dist-info → abstract_utilities-0.2.2.476.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from .imports import *
|
|
2
|
+
from .filter_params import *
|
|
3
|
+
from .file_filters import enumerate_source_files
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def check_path_type(
|
|
7
|
+
path: str,
|
|
8
|
+
user: Optional[str] = None,
|
|
9
|
+
host: Optional[str] = None,
|
|
10
|
+
user_as_host: Optional[str] = None,
|
|
11
|
+
use_shell: bool = False
|
|
12
|
+
) -> Literal["file", "directory", "missing", "unknown"]:
|
|
13
|
+
"""
|
|
14
|
+
Determine whether a given path is a file, directory, or missing.
|
|
15
|
+
Works locally or remotely (via SSH).
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
path: The path to check.
|
|
19
|
+
user, host, user_as_host: SSH parameters if remote.
|
|
20
|
+
use_shell: Force shell test instead of Python os.path.
|
|
21
|
+
Returns:
|
|
22
|
+
One of: 'file', 'directory', 'missing', or 'unknown'
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# --- remote check if user/host is given ---
|
|
26
|
+
if user_as_host or (user and host):
|
|
27
|
+
remote_target = user_as_host or f"{user}@{host}"
|
|
28
|
+
cmd = f"if [ -f '{path}' ]; then echo file; elif [ -d '{path}' ]; then echo directory; else echo missing; fi"
|
|
29
|
+
try:
|
|
30
|
+
result = subprocess.check_output(
|
|
31
|
+
["ssh", remote_target, cmd],
|
|
32
|
+
stderr=subprocess.DEVNULL,
|
|
33
|
+
text=True,
|
|
34
|
+
timeout=5
|
|
35
|
+
).strip()
|
|
36
|
+
return result if result in ("file", "directory", "missing") else "unknown"
|
|
37
|
+
except Exception:
|
|
38
|
+
return "unknown"
|
|
39
|
+
|
|
40
|
+
# --- local check ---
|
|
41
|
+
if not use_shell:
|
|
42
|
+
if os.path.isfile(path):
|
|
43
|
+
return "file"
|
|
44
|
+
elif os.path.isdir(path):
|
|
45
|
+
return "directory"
|
|
46
|
+
elif not os.path.exists(path):
|
|
47
|
+
return "missing"
|
|
48
|
+
return "unknown"
|
|
49
|
+
else:
|
|
50
|
+
# fallback using shell tests (useful for sandboxed contexts)
|
|
51
|
+
cmd = f"if [ -f '{path}' ]; then echo file; elif [ -d '{path}' ]; then echo directory; else echo missing; fi"
|
|
52
|
+
try:
|
|
53
|
+
output = subprocess.check_output(
|
|
54
|
+
cmd, shell=True, stderr=subprocess.DEVNULL, text=True
|
|
55
|
+
).strip()
|
|
56
|
+
return output if output in ("file", "directory", "missing") else "unknown"
|
|
57
|
+
except Exception:
|
|
58
|
+
return "unknown"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_find_cmd(
|
|
64
|
+
directory: str,
|
|
65
|
+
*,
|
|
66
|
+
mindepth: Optional[int] = None,
|
|
67
|
+
maxdepth: Optional[int] = None,
|
|
68
|
+
depth: Optional[int] = None,
|
|
69
|
+
file_type: Optional[str] = None, # 'f' or 'd'
|
|
70
|
+
name: Optional[str] = None,
|
|
71
|
+
size: Optional[str] = None,
|
|
72
|
+
mtime: Optional[str] = None,
|
|
73
|
+
perm: Optional[str] = None,
|
|
74
|
+
user: Optional[str] = None,
|
|
75
|
+
**kwargs
|
|
76
|
+
) -> str:
|
|
77
|
+
"""Constructs a Unix `find` command string from keyword args."""
|
|
78
|
+
cmd = [f"find {directory}"]
|
|
79
|
+
|
|
80
|
+
if depth is not None:
|
|
81
|
+
cmd += [f"-mindepth {depth}", f"-maxdepth {depth}"]
|
|
82
|
+
else:
|
|
83
|
+
if mindepth is not None:
|
|
84
|
+
cmd.append(f"-mindepth {mindepth}")
|
|
85
|
+
if maxdepth is not None:
|
|
86
|
+
cmd.append(f"-maxdepth {maxdepth}")
|
|
87
|
+
|
|
88
|
+
if file_type in ("f", "d"):
|
|
89
|
+
cmd.append(f"-type {file_type}")
|
|
90
|
+
if name:
|
|
91
|
+
cmd.append(f"-name '{name}'")
|
|
92
|
+
if size:
|
|
93
|
+
cmd.append(f"-size {size}")
|
|
94
|
+
if mtime:
|
|
95
|
+
cmd.append(f"-mtime {mtime}")
|
|
96
|
+
if perm:
|
|
97
|
+
cmd.append(f"-perm {perm}")
|
|
98
|
+
if user:
|
|
99
|
+
cmd.append(f"-user {user}")
|
|
100
|
+
|
|
101
|
+
return " ".join(cmd)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def collect_globs(
|
|
105
|
+
directory: str,
|
|
106
|
+
cfg: Optional["ScanConfig"] = None,
|
|
107
|
+
*,
|
|
108
|
+
exts: Optional[Set[str]] = None,
|
|
109
|
+
patterns: Optional[List[str]] = None,
|
|
110
|
+
mindepth: Optional[int] = None,
|
|
111
|
+
maxdepth: Optional[int] = None,
|
|
112
|
+
depth: Optional[int] = None,
|
|
113
|
+
file_type: Optional[str] = None,
|
|
114
|
+
user_at_host: Optional[str] = None,
|
|
115
|
+
add: bool = False,
|
|
116
|
+
**kwargs
|
|
117
|
+
) -> List[str]:
|
|
118
|
+
"""
|
|
119
|
+
Collect file or directory paths using either:
|
|
120
|
+
- local recursive logic (rglob)
|
|
121
|
+
- or remote shell call (find via run_cmd)
|
|
122
|
+
"""
|
|
123
|
+
cfg = cfg or define_defaults(add=add)
|
|
124
|
+
directory = str(directory)
|
|
125
|
+
exts = ensure_exts(exts)
|
|
126
|
+
patterns = ensure_patterns(patterns)
|
|
127
|
+
|
|
128
|
+
# Remote path via SSH
|
|
129
|
+
if user_at_host:
|
|
130
|
+
find_cmd = get_find_cmd(
|
|
131
|
+
directory,
|
|
132
|
+
mindepth=mindepth,
|
|
133
|
+
maxdepth=maxdepth,
|
|
134
|
+
depth=depth,
|
|
135
|
+
file_type=file_type,
|
|
136
|
+
**{k: v for k, v in kwargs.items() if v},
|
|
137
|
+
)
|
|
138
|
+
return run_cmd(find_cmd, user_at_host=user_at_host)
|
|
139
|
+
|
|
140
|
+
# Local path (Python-native walk)
|
|
141
|
+
root = Path(directory)
|
|
142
|
+
results = []
|
|
143
|
+
for p in root.rglob("*"):
|
|
144
|
+
if file_type == "f" and not p.is_file():
|
|
145
|
+
continue
|
|
146
|
+
if file_type == "d" and not p.is_dir():
|
|
147
|
+
continue
|
|
148
|
+
if exts and p.suffix.lower() not in exts:
|
|
149
|
+
continue
|
|
150
|
+
if patterns and not any(p.match(pat) for pat in patterns):
|
|
151
|
+
continue
|
|
152
|
+
results.append(str(p.resolve()))
|
|
153
|
+
|
|
154
|
+
return sorted(results)
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
|
@@ -0,0 +1,10 @@
|
|
|
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)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# ============================================================
|
|
2
|
+
# abstract_utilities/imports/imports.py
|
|
3
|
+
# Global imports hub — everything imported here will be
|
|
4
|
+
# automatically available to any module that does:
|
|
5
|
+
# from ..imports import *
|
|
6
|
+
# ============================================================
|
|
7
|
+
# ---- Core standard library modules -------------------------
|
|
8
|
+
import os, sys, re, shlex, glob, platform, textwrap, subprocess, inspect, json, time
|
|
9
|
+
import tempfile, shutil, logging, pathlib, fnmatch, importlib, importlib.util, types
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from types import ModuleType
|
|
13
|
+
|
|
14
|
+
# ---- Dataclasses and typing --------------------------------
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
from typing import (
|
|
17
|
+
Any, Optional, List, Dict, Set, Tuple,
|
|
18
|
+
Iterable, Callable, Literal, Union, TypeVar
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# ---- Common 3rd-party dependencies --------------------------
|
|
22
|
+
import pandas as pd
|
|
23
|
+
import geopandas as gpd
|
|
24
|
+
import pytesseract
|
|
25
|
+
import pdfplumber
|
|
26
|
+
import PyPDF2
|
|
27
|
+
import ezodf
|
|
28
|
+
from pdf2image import convert_from_path
|
|
29
|
+
from werkzeug.utils import secure_filename
|
|
30
|
+
from werkzeug.datastructures import FileStorage
|
|
31
|
+
|
|
32
|
+
# ---- Helpers ------------------------------------------------
|
|
33
|
+
import textwrap as tw
|
|
34
|
+
from pprint import pprint
|
|
35
|
+
|
|
36
|
+
# ============================================================
|
|
37
|
+
# AUTO-EXPORT ALL NON-PRIVATE NAMES
|
|
38
|
+
# ============================================================
|
|
39
|
+
__all__ = [name for name in globals() if not name.startswith("_")]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .imports import *
|
|
2
|
+
from ....string_clean import eatAll
|
|
3
|
+
from ....list_utils import make_list
|
|
4
|
+
from ....type_utils import get_media_exts, is_media_type, MIME_TYPES, is_str
|
|
5
|
+
from ....ssh_utils import *
|
|
6
|
+
from ....env_utils import *
|
|
7
|
+
from ....read_write_utils import *
|
|
8
|
+
from ....abstract_classes import SingletonMeta
|
|
9
|
+
|
|
10
|
+
from ....class_utils import get_caller, get_caller_path, get_caller_dir
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = [name for name in globals() if not name.startswith("_")]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from ..imports import *
|
|
2
|
+
from typing import *
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
@dataclass
|
|
5
|
+
class ScanConfig:
|
|
6
|
+
allowed_exts: Set[str]
|
|
7
|
+
unallowed_exts: Set[str]
|
|
8
|
+
exclude_types: Set[str]
|
|
9
|
+
exclude_dirs: List[str] = field(default_factory=list)
|
|
10
|
+
exclude_patterns: List[str] = field(default_factory=list)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from .imports import MIME_TYPES,make_list,os
|
|
2
|
+
from .file_filters import get_globs
|
|
3
|
+
def get_file_type(file_path,types=None,default=None):
|
|
4
|
+
mime_types = {}
|
|
5
|
+
if types:
|
|
6
|
+
types = make_list(types)
|
|
7
|
+
for typ in types:
|
|
8
|
+
mime_types[typ] = MIME_TYPES.get(typ)
|
|
9
|
+
else:
|
|
10
|
+
mime_types = MIME_TYPES
|
|
11
|
+
|
|
12
|
+
if os.path.isfile(file_path):
|
|
13
|
+
basename = os.path.basename(file_path)
|
|
14
|
+
filename,ext = os.path.splitext(basename)
|
|
15
|
+
for file_type,ext_values in mime_types.items():
|
|
16
|
+
if ext in ext_values:
|
|
17
|
+
return file_type
|
|
18
|
+
def get_file_map(directory,types=None,default=None):
|
|
19
|
+
if directory and os.path.isfile(directory):
|
|
20
|
+
directory = os.path.dirname(directory)
|
|
21
|
+
all_types = {}
|
|
22
|
+
files = get_globs(directory)
|
|
23
|
+
for file in files:
|
|
24
|
+
file_type = get_file_type(file,types=types,default=default)
|
|
25
|
+
if file_type:
|
|
26
|
+
if file_type not in all_types:
|
|
27
|
+
all_types[file_type] = []
|
|
28
|
+
all_types[file_type].append(file)
|
|
29
|
+
return all_types
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
from typing import *
|
|
3
|
-
from pdf2image import convert_from_path
|
|
4
|
-
from abstract_utilities.path_utils import (is_file, mkdirs, get_directory,
|
|
5
|
-
get_base_name, split_text,
|
|
6
|
-
get_ext, get_file_name)
|
|
7
|
-
from abstract_utilities.type_utils import is_str
|
|
8
|
-
from abstract_utilities.cmd_utils import cmd_input
|
|
9
|
-
from abstract_utilities.read_write_utils import write_to_file
|
|
1
|
+
from .imports import *
|
|
10
2
|
def if_none_return(obj: object, obj_2: object) -> object:
|
|
11
3
|
"""
|
|
12
4
|
Return obj if obj_2 is None, otherwise return obj_2.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from .imports import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# --- Base remote checker -----------------------------------------------------
|
|
5
|
+
def _remote_test(path: str, test_flag: str, user_at_host: str, timeout: int = 5) -> bool:
|
|
6
|
+
"""
|
|
7
|
+
Run a remote shell test (e.g. -f, -d) via SSH.
|
|
8
|
+
Returns True if test succeeds, False otherwise.
|
|
9
|
+
"""
|
|
10
|
+
cmd = f"[ {test_flag} {shlex.quote(path)} ] && echo 1 || echo 0"
|
|
11
|
+
try:
|
|
12
|
+
result = subprocess.check_output(
|
|
13
|
+
["ssh", user_at_host, cmd],
|
|
14
|
+
stderr=subprocess.DEVNULL,
|
|
15
|
+
text=True,
|
|
16
|
+
timeout=timeout
|
|
17
|
+
).strip()
|
|
18
|
+
return result == "1"
|
|
19
|
+
except Exception:
|
|
20
|
+
return False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# --- Individual path checks --------------------------------------------------
|
|
24
|
+
def is_remote_file(path: str, user_at_host: str) -> bool:
|
|
25
|
+
"""True if remote path is a file."""
|
|
26
|
+
return _remote_test(path, "-f", user_at_host)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def is_remote_dir(path: str, user_at_host: str) -> bool:
|
|
30
|
+
"""True if remote path is a directory."""
|
|
31
|
+
return _remote_test(path, "-d", user_at_host)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_local_file(path: str) -> bool:
|
|
35
|
+
"""True if local path is a file."""
|
|
36
|
+
return os.path.isfile(path)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_local_dir(path: str) -> bool:
|
|
40
|
+
"""True if local path is a directory."""
|
|
41
|
+
return os.path.isdir(path)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# --- Unified interface -------------------------------------------------------
|
|
45
|
+
def is_file(path: str,*args, user_at_host: Optional[str] = None,**kwargs) -> bool:
|
|
46
|
+
"""Determine if path is a file (works local or remote)."""
|
|
47
|
+
if user_at_host:
|
|
48
|
+
return is_remote_file(path, user_at_host)
|
|
49
|
+
return is_local_file(path)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def is_dir(path: str, *args,user_at_host: Optional[str] = None,**kwargs) -> bool:
|
|
53
|
+
"""Determine if path is a directory (works local or remote)."""
|
|
54
|
+
if user_at_host:
|
|
55
|
+
return is_remote_dir(path, user_at_host)
|
|
56
|
+
return is_local_dir(path)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# --- Optional: keep your original all-in-one wrapper ------------------------
|
|
60
|
+
def check_path_type(
|
|
61
|
+
path: str,
|
|
62
|
+
user_at_host: Optional[str] = None,
|
|
63
|
+
) -> str:
|
|
64
|
+
"""
|
|
65
|
+
Return 'file', 'directory', 'missing', or 'unknown'.
|
|
66
|
+
Uses isolated is_file/is_dir functions.
|
|
67
|
+
"""
|
|
68
|
+
if user_at_host:
|
|
69
|
+
if is_remote_file(path, user_at_host):
|
|
70
|
+
return "file"
|
|
71
|
+
elif is_remote_dir(path, user_at_host):
|
|
72
|
+
return "directory"
|
|
73
|
+
else:
|
|
74
|
+
return "missing"
|
|
75
|
+
else:
|
|
76
|
+
if os.path.isfile(path):
|
|
77
|
+
return "file"
|
|
78
|
+
elif os.path.isdir(path):
|
|
79
|
+
return "directory"
|
|
80
|
+
elif not os.path.exists(path):
|
|
81
|
+
return "missing"
|
|
82
|
+
return "unknown"
|