Skip to content

Commit

Permalink
LocalDataset: Prevent upload if a remote version exists
Browse files Browse the repository at this point in the history
  • Loading branch information
girgink committed Mar 22, 2023
1 parent 33f12f8 commit 138a685
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/fairly/dataset/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_archive_method(self) -> str:
return "deflate"


def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -> RemoteDataset:
def upload(self, repository=None, notify: Callable=None, strategy: str="auto", force: bool=False) -> RemoteDataset:
"""Uploads dataset to the repository.
Available upload strategies:
Expand All @@ -372,6 +372,7 @@ def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -
repository: Repository identifier or client. If not specified, template identifier is used.
notify (Callable): Notification callback function.
strategy (str): Folder upload strategy (default = "auto")
force (bool): Set True to upload dataset even if a remote version exists (default = False)
Returns:
Remote dataset
Expand All @@ -381,6 +382,7 @@ def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -
ValueError("Invalid upload strategy"): If upload strategy is invalid.
ValueError("Invalid archiving method"): If archiving method is invalid.
ValueError("Invalid archive name"): If archive name is invalid.
Warning("Remote dataset exists"): If remote dataset exists.
"""
# Set repository if required
if not repository:
Expand All @@ -394,6 +396,10 @@ def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -
else:
raise ValueError("Invalid repository")

# Prevent upload if a remote version exists and upload is not enforced
if client.id in self.remote_datasets and not force:
raise Warning("Remote dataset exists")

# Create dataset
dataset = client.create_dataset(self.metadata)

Expand All @@ -409,6 +415,10 @@ def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -

for file in files.values():

if strategy == "archive_all":
archives[self.get_archive_name()] = list(files.values())
break

if file.is_simple:
uploads.append(file)

Expand All @@ -418,11 +428,6 @@ def upload(self, repository=None, notify: Callable=None, strategy: str="auto") -
else:
raise ValueError("Invalid upload strategy")

elif strategy == "archive_all":
uploads = []
archives[self.get_archive_name()] = list(files.values())
break

elif strategy == "archive_folders":
name = os.path.normpath(file.path).split(os.sep)[0]
if name not in archives:
Expand Down

0 comments on commit 138a685

Please sign in to comment.