|
1 | 1 | """File System Specification for CDF Files."""
|
| 2 | + |
2 | 3 | import logging
|
3 | 4 | import time
|
4 | 5 | from concurrent.futures import ThreadPoolExecutor
|
@@ -147,22 +148,26 @@ def _suffix_exists(self, path: str) -> List:
|
147 | 148 | """
|
148 | 149 | return [file_part for file_part in path.split("/") if Path(file_part).suffix]
|
149 | 150 |
|
150 |
| - def split_path(self, path: str, validate_suffix: bool = True) -> Tuple[str, str, str]: |
| 151 | + def split_path(self, path: str, validate_suffix: bool = True, directory_prefix: str = "") -> Tuple[str, str, str]: |
151 | 152 | """Split the path and extract root_dir, external_id and a filename.
|
152 | 153 |
|
153 | 154 | Args:
|
154 | 155 | path (str): Path to split.
|
155 | 156 | validate_suffix (bool): Flag to validate if the file name must have a valid suffix.
|
| 157 | + directory_prefix(str): Directory prefix. |
156 | 158 |
|
157 | 159 | Returns:
|
158 | 160 | Tuple: Returns a tuple with root_dir, external_id_prefix and external_id.
|
159 | 161 |
|
160 | 162 | Raises:
|
161 | 163 | ValueError: When an invalid input path is given.
|
162 | 164 | """
|
163 |
| - if self.file_metadata.directory: |
164 |
| - root_dir = self.file_metadata.directory.strip("/") |
165 |
| - external_id = path.replace(root_dir, "").lstrip("/") |
| 165 | + if directory_prefix or self.file_metadata.directory: |
| 166 | + root_dir = directory_prefix.strip("/") if directory_prefix else self.file_metadata.directory.strip("/") |
| 167 | + if root_dir in path: |
| 168 | + external_id = path.replace(root_dir, "").lstrip("/") |
| 169 | + else: |
| 170 | + external_id = path.split("/")[-1] |
166 | 171 | external_id_prefix = Path(external_id).parts[0]
|
167 | 172 |
|
168 | 173 | elif self._suffix_exists(path):
|
@@ -505,7 +510,12 @@ def open(
|
505 | 510 | Returns:
|
506 | 511 | CdfFile: An instance of a 'CdfFile' to allow reading/writing file to Cdf.
|
507 | 512 | """
|
508 |
| - root_dir, _, external_id = self.split_path(path) |
| 513 | + if isinstance(kwargs.get("file_metadata"), FileMetadata): |
| 514 | + file_metadata: FileMetadata = kwargs.get("file_metadata") |
| 515 | + root_dir, _, external_id = self.split_path(path, directory_prefix=file_metadata.directory) |
| 516 | + else: |
| 517 | + root_dir, _, external_id = self.split_path(path) |
| 518 | + |
509 | 519 | return CdfFile(
|
510 | 520 | self,
|
511 | 521 | self.cognite_client,
|
|
0 commit comments