Skip to content
Snippets Groups Projects

Add uption to create (POST) metadata in update_metadata function in the resource class

Closed Nicole Parks requested to merge nikki-patch-create-metadata into master
2 unresolved threads
1 file
+ 24
7
Compare changes
  • Side-by-side
  • Inline
+ 24
7
@@ -570,7 +570,8 @@ class Resource:
@@ -570,7 +570,8 @@ class Resource:
path: str,
path: str,
handle: BinaryIO | bytes | str,
handle: BinaryIO | bytes | str,
metadata: MetadataForm | dict | rdflib.Graph | None = None,
metadata: MetadataForm | dict | rdflib.Graph | None = None,
progress: Callable[[int], None] | None = None
progress: Callable[[int], None] | None = None,
 
overwrite: bool =True
) -> None:
) -> None:
"""
"""
Uploads a file-like object to a resource in Coscine.
Uploads a file-like object to a resource in Coscine.
@@ -590,6 +591,9 @@ class Resource:
@@ -590,6 +591,9 @@ class Resource:
progress
progress
Optional callback function that gets occasionally called
Optional callback function that gets occasionally called
during the upload with the progress in bytes.
during the upload with the progress in bytes.
 
overwrite
 
Bool that designates whether existing files should be overwritten.
 
Default set to True (files will be overwritten).
"""
"""
if isinstance(metadata, MetadataForm):
if isinstance(metadata, MetadataForm):
metadata = metadata.serialize(path)
metadata = metadata.serialize(path)
@@ -615,12 +619,20 @@ class Resource:
@@ -615,12 +619,20 @@ class Resource:
if isinstance(handle, bytes):
if isinstance(handle, bytes):
handle = BytesIO(handle)
handle = BytesIO(handle)
if metadata is not None:
if metadata is not None:
self.post_metadata(metadata)
try:
assert isinstance(handle, IOBase)
self.post_metadata(metadata)
if self.type.general_type == "rdss3":
except RequestRejected:
self._upload_blob_s3(path, handle)
self.put_metadata(metadata)
 
assert isinstance(handle, IOBase)
 
 
if overwrite or path not in [f.name for f in self.files()]:
 
if self.type.general_type == "rdss3":
 
self._upload_blob_s3(path, handle)
 
else:
 
self._upload_blob(path, handle, progress)
else:
else:
self._upload_blob(path, handle, progress)
print('File already exists and overwrite is set to False!')
 
def post_metadata(self, metadata: dict) -> None:
def post_metadata(self, metadata: dict) -> None:
"""
"""
@@ -656,7 +668,12 @@ class Resource:
@@ -656,7 +668,12 @@ class Resource:
This comes at the cost of possibly sending two requests, where
This comes at the cost of possibly sending two requests, where
one would have sufficed.
one would have sufficed.
"""
"""
self.put_metadata(metadata)
try:
 
self.put_metadata(metadata)
 
except RequestRejected:
 
self.post_metadata(metadata)
 
 
def _upload_blob(
def _upload_blob(
self,
self,
Loading