dcicutils 8.8.4.1b17__py3-none-any.whl → 8.8.4.1b18__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dcicutils/file_utils.py +50 -37
- {dcicutils-8.8.4.1b17.dist-info → dcicutils-8.8.4.1b18.dist-info}/METADATA +1 -1
- {dcicutils-8.8.4.1b17.dist-info → dcicutils-8.8.4.1b18.dist-info}/RECORD +6 -6
- {dcicutils-8.8.4.1b17.dist-info → dcicutils-8.8.4.1b18.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.8.4.1b17.dist-info → dcicutils-8.8.4.1b18.dist-info}/WHEEL +0 -0
- {dcicutils-8.8.4.1b17.dist-info → dcicutils-8.8.4.1b18.dist-info}/entry_points.txt +0 -0
dcicutils/file_utils.py
CHANGED
@@ -23,46 +23,59 @@ def search_for_file(file: str,
|
|
23
23
|
first file which is found is returns (as a string), or None if none; if the single flag
|
24
24
|
is False, then all matched files are returned in a list, or and empty list if none.
|
25
25
|
"""
|
26
|
-
if file and isinstance(file, (str, pathlib.PosixPath)):
|
27
|
-
if
|
28
|
-
|
29
|
-
|
30
|
-
return
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
if not (file and isinstance(file, (str, pathlib.PosixPath))):
|
27
|
+
return None if single is True else []
|
28
|
+
if os.path.isabs(file):
|
29
|
+
if os.path.exists(file):
|
30
|
+
return file if single is True else [file]
|
31
|
+
return None if single is True else []
|
32
|
+
files_found = []
|
33
|
+
if not location:
|
34
|
+
location = ["."]
|
35
|
+
elif isinstance(location, (str, pathlib.PosixPath)):
|
36
|
+
location = [location]
|
37
|
+
elif not isinstance(location, list):
|
38
|
+
location = []
|
39
|
+
location_pruned = []
|
40
|
+
for directory in location:
|
41
|
+
if not isinstance(directory, str):
|
42
|
+
if not isinstance(directory, pathlib.PosixPath):
|
43
|
+
continue
|
44
|
+
directory = str(directory)
|
45
|
+
if not (directory := directory.strip()):
|
46
|
+
continue
|
47
|
+
if os.path.isfile(directory):
|
48
|
+
# Allow a file; assume its parent directory was intended.
|
49
|
+
if not (directory := os.path.dirname(directory)):
|
50
|
+
continue
|
51
|
+
location_pruned.append(directory)
|
52
|
+
location = location_pruned
|
53
|
+
for directory in location:
|
54
|
+
if os.path.exists(os.path.join(directory, file)):
|
55
|
+
file_found = os.path.abspath(os.path.normpath(os.path.join(directory, file)))
|
56
|
+
if single is True:
|
57
|
+
return file_found
|
58
|
+
if file_found not in files_found:
|
59
|
+
files_found.append(file_found)
|
60
|
+
if recursive is True:
|
38
61
|
for directory in location:
|
39
62
|
if not directory:
|
40
63
|
continue
|
41
|
-
if
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if files:
|
57
|
-
for file_found in files:
|
58
|
-
file_found = os.path.abspath(file_found)
|
59
|
-
if single:
|
60
|
-
return file_found
|
61
|
-
if file_found not in files_found:
|
62
|
-
files_found.append(file_found)
|
63
|
-
if files_found:
|
64
|
-
return files_found[0] if single else files_found
|
65
|
-
return None if single else []
|
64
|
+
if not directory.endswith("/**") and not file.startswith("**/"):
|
65
|
+
path = f"{directory}/**/{file}"
|
66
|
+
else:
|
67
|
+
path = f"{directory}/{file}"
|
68
|
+
files = glob.glob(path, recursive=True if recursive is True else False)
|
69
|
+
if files:
|
70
|
+
for file_found in files:
|
71
|
+
file_found = os.path.abspath(file_found)
|
72
|
+
if single is True:
|
73
|
+
return file_found
|
74
|
+
if file_found not in files_found:
|
75
|
+
files_found.append(file_found)
|
76
|
+
if files_found:
|
77
|
+
return files_found[0] if single is True else files_found
|
78
|
+
return None if single is True else []
|
66
79
|
|
67
80
|
|
68
81
|
def normalize_file_path(path: str, home_directory: bool = True) -> str:
|
@@ -28,7 +28,7 @@ dcicutils/es_utils.py,sha256=ZksLh5ei7kRUfiFltk8sd2ZSfh15twbstrMzBr8HNw4,7541
|
|
28
28
|
dcicutils/exceptions.py,sha256=4giQGtpak-omQv7BP6Ckeu91XK5fnDosC8gfdmN_ccA,9931
|
29
29
|
dcicutils/ff_mocks.py,sha256=6RKS4eUiu_Wl8yP_8V0CaV75w4ZdWxdCuL1CVlnMrek,36918
|
30
30
|
dcicutils/ff_utils.py,sha256=oIhuZPnGtfwj6bWyCc1u23JbMB_6InPp01ZqUOljd8M,73123
|
31
|
-
dcicutils/file_utils.py,sha256=
|
31
|
+
dcicutils/file_utils.py,sha256=GI3DfD11iM4Z76QbZftIJ1e6tWATxFtZ8as-vrlHTps,9139
|
32
32
|
dcicutils/function_cache_decorator.py,sha256=XMyiEGODVr2WoAQ68vcoX_9_Xb9p8pZXdXl7keU8i2g,10026
|
33
33
|
dcicutils/glacier_utils.py,sha256=Q4CVXsZCbP-SoZIsZ5NMcawDfelOLzbQnIlQn-GdlTo,34149
|
34
34
|
dcicutils/http_utils.py,sha256=Je5ErNjR5e6lfSXGRncK_lcR_-zP38PIpmHjApy9Wi4,1289
|
@@ -73,8 +73,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
|
|
73
73
|
dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
|
74
74
|
dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
|
75
75
|
dcicutils/zip_utils.py,sha256=_Y9EmL3D2dUZhxucxHvrtmmlbZmK4FpSsHEb7rGSJLU,3265
|
76
|
-
dcicutils-8.8.4.
|
77
|
-
dcicutils-8.8.4.
|
78
|
-
dcicutils-8.8.4.
|
79
|
-
dcicutils-8.8.4.
|
80
|
-
dcicutils-8.8.4.
|
76
|
+
dcicutils-8.8.4.1b18.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
77
|
+
dcicutils-8.8.4.1b18.dist-info/METADATA,sha256=YbKpFyKttkQQ6Exbw6SfcOkW76dDpxqlJ2DhyBHzTxM,3440
|
78
|
+
dcicutils-8.8.4.1b18.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
79
|
+
dcicutils-8.8.4.1b18.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
|
80
|
+
dcicutils-8.8.4.1b18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|