diff --git a/src/fairly/dataset/local.py b/src/fairly/dataset/local.py index 00ca3b7..b970f0e 100644 --- a/src/fairly/dataset/local.py +++ b/src/fairly/dataset/local.py @@ -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: @@ -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 @@ -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: @@ -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) @@ -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) @@ -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: