dcicutils 8.8.4.1b20__py3-none-any.whl → 8.8.4.1b21__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.
- dcicutils/file_utils.py +37 -16
- dcicutils/misc_utils.py +13 -0
- {dcicutils-8.8.4.1b20.dist-info → dcicutils-8.8.4.1b21.dist-info}/METADATA +1 -1
- {dcicutils-8.8.4.1b20.dist-info → dcicutils-8.8.4.1b21.dist-info}/RECORD +7 -7
- {dcicutils-8.8.4.1b20.dist-info → dcicutils-8.8.4.1b21.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.8.4.1b20.dist-info → dcicutils-8.8.4.1b21.dist-info}/WHEEL +0 -0
- {dcicutils-8.8.4.1b20.dist-info → dcicutils-8.8.4.1b21.dist-info}/entry_points.txt +0 -0
dcicutils/file_utils.py
CHANGED
@@ -10,6 +10,8 @@ from tempfile import gettempdir as get_temporary_directory
|
|
10
10
|
from typing import List, Optional, Union
|
11
11
|
from uuid import uuid4 as uuid
|
12
12
|
|
13
|
+
HOME_DIRECTORY = str(pathlib.Path().home())
|
14
|
+
|
13
15
|
|
14
16
|
def search_for_file(file: str,
|
15
17
|
location: Union[str, Optional[List[str]]] = None,
|
@@ -77,24 +79,43 @@ def search_for_file(file: str,
|
|
77
79
|
return None if single is True else []
|
78
80
|
|
79
81
|
|
80
|
-
def
|
82
|
+
def normalize_path(value: Union[str, pathlib.Path], absolute: bool = False, home: Optional[bool] = None) -> str:
|
81
83
|
"""
|
82
|
-
Normalizes the given
|
83
|
-
consecutive
|
84
|
-
|
85
|
-
|
84
|
+
Normalizes the given path value and returns the result; does things like remove redundant
|
85
|
+
consecutive directory separators and redundant parent paths. If the given absolute argument
|
86
|
+
is True than converts the path to an absolute path. If the given home argument is True and
|
87
|
+
if the path can reasonably be represented with a home directory indicator (i.e. "~"), then
|
88
|
+
converts it to such. If the home argument is False and path starts with the home directory
|
89
|
+
indicator then expands it to the actual (absolute) home path. If the given value is not
|
90
|
+
actually even a string (or pathlib.Path) then returns an empty string.
|
86
91
|
"""
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
if isinstance(value, pathlib.Path):
|
93
|
+
value = str(value)
|
94
|
+
elif not isinstance(value, str):
|
95
|
+
return ""
|
96
|
+
if not (value := value.strip()) or not (value := os.path.normpath(value)):
|
97
|
+
return ""
|
98
|
+
if home is False:
|
99
|
+
value = os.path.expanduser(value)
|
100
|
+
elif (home is True) and (os.name == "posix") and value.startswith(home := HOME_DIRECTORY + os.sep):
|
101
|
+
value = "~/" + value[len(home):]
|
102
|
+
if absolute is True:
|
103
|
+
value = os.path.abspath(value)
|
104
|
+
return value
|
105
|
+
|
106
|
+
|
107
|
+
def get_file_size(file: str) -> Optional[int]:
|
108
|
+
try:
|
109
|
+
return os.path.getsize(file) if isinstance(file, str) else None
|
110
|
+
except Exception:
|
111
|
+
return None
|
112
|
+
|
113
|
+
|
114
|
+
def get_file_modified_datetime(file: str) -> Optional[datetime]:
|
115
|
+
try:
|
116
|
+
return datetime.fromtimestamp(os.path.getmtime(file)) if isinstance(file, str) else None
|
117
|
+
except Exception:
|
118
|
+
return None
|
98
119
|
|
99
120
|
|
100
121
|
def are_files_equal(filea: str, fileb: str) -> bool:
|
dcicutils/misc_utils.py
CHANGED
@@ -2551,6 +2551,19 @@ def normalize_spaces(value: str) -> str:
|
|
2551
2551
|
return re.sub(r"\s+", " ", value).strip()
|
2552
2552
|
|
2553
2553
|
|
2554
|
+
def normalize_string(value: Optional[str]) -> Optional[str]:
|
2555
|
+
"""
|
2556
|
+
Strips leading/trailing spaces, and converts multiple consecutive spaces to a single space
|
2557
|
+
in the given string value and returns the result. If the given value is None returns an
|
2558
|
+
empty string. If the given value is not actually even a string then return None.
|
2559
|
+
"""
|
2560
|
+
if value is None:
|
2561
|
+
return ""
|
2562
|
+
elif isinstance(value, str):
|
2563
|
+
return value.strip()
|
2564
|
+
return None
|
2565
|
+
|
2566
|
+
|
2554
2567
|
def find_nth_from_end(string: str, substring: str, nth: int) -> int:
|
2555
2568
|
"""
|
2556
2569
|
Returns the index of the nth occurrence of the given substring within
|
@@ -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=haP4JIqE5T0pmAY_pjibEIN8a98_B3v-BXq8fTifzL0,9905
|
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
|
@@ -44,7 +44,7 @@ dcicutils/license_policies/park-lab-gpl-pipeline.jsonc,sha256=vLZkwm3Js-kjV44nug
|
|
44
44
|
dcicutils/license_policies/park-lab-pipeline.jsonc,sha256=9qlY0ASy3iUMQlr3gorVcXrSfRHnVGbLhkS427UaRy4,283
|
45
45
|
dcicutils/license_utils.py,sha256=d1cq6iwv5Ju-VjdoINi6q7CPNNL7Oz6rcJdLMY38RX0,46978
|
46
46
|
dcicutils/log_utils.py,sha256=7pWMc6vyrorUZQf-V-M3YC6zrPgNhuV_fzm9xqTPph0,10883
|
47
|
-
dcicutils/misc_utils.py,sha256=
|
47
|
+
dcicutils/misc_utils.py,sha256=ZW2ElovbsrPoMFco6GmZ24zJHyvx6Ky-csr3TDlOli4,106213
|
48
48
|
dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
|
49
49
|
dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
|
50
50
|
dcicutils/portal_object_utils.py,sha256=gDXRgPsRvqCFwbC8WatsuflAxNiigOnqr0Hi93k3AgE,15422
|
@@ -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.1b21.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
77
|
+
dcicutils-8.8.4.1b21.dist-info/METADATA,sha256=L64XCFbcLBijgZiY6g823l5rAh7tFDsYU1OmsD1KuKo,3440
|
78
|
+
dcicutils-8.8.4.1b21.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
79
|
+
dcicutils-8.8.4.1b21.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
|
80
|
+
dcicutils-8.8.4.1b21.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|