sapiopycommons 2025.1.7rc401__py3-none-any.whl → 2025.1.20a403__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 sapiopycommons might be problematic. Click here for more details.

@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import time
4
4
  from collections.abc import Mapping, Iterable
5
+ from typing import TypeAlias
5
6
  from weakref import WeakValueDictionary
6
7
 
7
8
  from sapiopylib.rest.DataMgmtService import DataMgmtServer
@@ -28,7 +29,7 @@ from sapiopycommons.general.aliases import AliasUtil, SapioRecord, ExperimentIde
28
29
  DataTypeIdentifier, RecordModel
29
30
  from sapiopycommons.general.exceptions import SapioException
30
31
 
31
- Step = str | ElnEntryStep
32
+ Step: TypeAlias = str | ElnEntryStep
32
33
  """An object representing an identifier to an ElnEntryStep. May be either the name of the step or the ElnEntryStep
33
34
  itself."""
34
35
 
@@ -1,6 +1,7 @@
1
1
  import base64
2
2
  import io
3
3
  import urllib.parse
4
+ from typing import Any
4
5
 
5
6
  from requests import Response
6
7
  from sapiopylib.rest.User import SapioUser
@@ -8,6 +9,36 @@ from sapiopylib.rest.User import SapioUser
8
9
  from sapiopycommons.general.aliases import UserIdentifier, AliasUtil
9
10
 
10
11
 
12
+ # FR-47387: Add support for the metadata endpoints in FileBridge.
13
+ class FileBridgeMetadata:
14
+ """
15
+ Metadata for a file or directory in FileBridge.
16
+ """
17
+ file_name: str
18
+ """The name of the file or directory."""
19
+ is_file: bool
20
+ """True if the metadata is for a file, False if it is for a directory."""
21
+ is_directory: bool
22
+ """True if the metadata is for a directory, False if it is for a file."""
23
+ size: int
24
+ """The size of the file in bytes. For directories, this value will always be zero."""
25
+ creation_time: int
26
+ """The time the file or directory was created, in milliseconds since the epoch."""
27
+ last_accessed_time: int
28
+ """The time the file or directory was last accessed, in milliseconds since the epoch."""
29
+ last_modified_time: int
30
+ """The time the file or directory was last modified, in milliseconds since the epoch."""
31
+
32
+ def __init__(self, json_dict: dict[str, Any]):
33
+ self.file_name = json_dict['fileName']
34
+ self.is_file = json_dict['isFile']
35
+ self.is_directory = json_dict['isDirectory']
36
+ self.size = json_dict['size']
37
+ self.creation_time = json_dict['creationTime']
38
+ self.last_accessed_time = json_dict['lastAccessTime']
39
+ self.last_modified_time = json_dict['lastModifiedTime']
40
+
41
+
11
42
  # FR-46064 - Initial port of PyWebhookUtils to sapiopycommons.
12
43
  class FileBridge:
13
44
  @staticmethod
@@ -137,3 +168,48 @@ class FileBridge:
137
168
  user: SapioUser = AliasUtil.to_sapio_user(context)
138
169
  response = user.delete(sub_path, params=params)
139
170
  user.raise_for_status(response)
171
+
172
+ @staticmethod
173
+ def file_metadata(context: UserIdentifier, bridge_name: str, file_path: str) -> FileBridgeMetadata:
174
+ """
175
+ Get metadata for a file or directory in FileBridge.
176
+
177
+ The file path may be to a directory, in which case only the metadata for that directory will be returned. If you
178
+ want the metadata for the contents of a directory, then use the directory_metadata function.
179
+
180
+ :param context: The current webhook context or a user object to send requests from.
181
+ :param bridge_name: The name of the bridge to use. This is the "connection name" in the
182
+ file bridge configurations.
183
+ :param file_path: The path to the file to retrieve the metadata from.
184
+ :return: The metadata for the file.
185
+ """
186
+ sub_path = '/ext/filebridge/file/metadata'
187
+ params = {
188
+ 'Filepath': f"bridge://{bridge_name}/{file_path}"
189
+ }
190
+ user: SapioUser = AliasUtil.to_sapio_user(context)
191
+ response = user.get(sub_path, params=params)
192
+ user.raise_for_status(response)
193
+ response_body: dict[str, Any] = response.json()
194
+ return FileBridgeMetadata(response_body)
195
+
196
+ @staticmethod
197
+ def directory_metadata(context: UserIdentifier, bridge_name: str, file_path: str) -> list[FileBridgeMetadata]:
198
+ """
199
+ Get metadata for every file or nested directory in a directory in FileBridge.
200
+
201
+ :param context: The current webhook context or a user object to send requests from.
202
+ :param bridge_name: The name of the bridge to use. This is the "connection name" in the
203
+ file bridge configurations.
204
+ :param file_path: The path to the directory to retrieve the metadata of the contents.
205
+ :return: A list of the metadata for the contents of the directory.
206
+ """
207
+ sub_path = '/ext/filebridge/directory/metadata'
208
+ params = {
209
+ 'Filepath': f"bridge://{bridge_name}/{file_path}"
210
+ }
211
+ user: SapioUser = AliasUtil.to_sapio_user(context)
212
+ response = user.get(sub_path, params=params)
213
+ user.raise_for_status(response)
214
+ response_body: list[dict[str, Any]] = response.json()
215
+ return [FileBridgeMetadata(x) for x in response_body]