Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed + improved dv-dataset-destroy-migration-placeholder #54

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dans-datastation-tools"
version = "0.38.0"
version = "0.39.0"
description = "Command line utilities for Data Station application management"
authors = ["DANS-KNAW"]
packages = [
Expand Down
9 changes: 5 additions & 4 deletions src/datastation/dataverse/destroy_placeholder_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def matches(description):
return matches


def has_directory_label_different_from(file_metadata, dir_label):
return 'directoryLabel' not in file_metadata or file_metadata['directoryLabel'] != dir_label
def is_migration_file(file_metadata):
return ('directoryLabel' in file_metadata and file_metadata['directoryLabel'] == 'easy-migration') or \
('directoryLabel' not in file_metadata and file_metadata['label'] == 'easy-migration.zip')


def destroy_placeholder_dataset(dataset_api: DatasetApi, description_text_pattern, csv_report: CsvReport,
Expand Down Expand Up @@ -45,12 +46,12 @@ def destroy_placeholder_dataset(dataset_api: DatasetApi, description_text_patter
messages.append(f"Found {len(files)} files <= 4: OK")

non_easy_migration_files = list(
filter(lambda m: has_directory_label_different_from(m, 'easy-migration'), files))
filter(lambda m: not is_migration_file(m), files))
logging.debug(f"Non easy-migration files: {non_easy_migration_files}")

if len(non_easy_migration_files) > 0:
blocker = True
messages.append(f"Files other than 'easy-migration' found: {len(non_easy_migration_files)}: BLOCKER")
messages.append(f"Files other than 'easy-migration/*' or 'easy-migration.zip' found: {len(non_easy_migration_files)}: BLOCKER")
else:
messages.append("Only found easy-migration files: OK")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def main():
batch_processor.process_pids(pids,
callback=lambda pid, csv_report: destroy_placeholder_dataset(dataverse.dataset(pid),
description_text_pattern,
csv_report))
csv_report,
dry_run=args.dry_run))


if __name__ == '__main__':
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_destroy_placeholder_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import datastation.dataverse.destroy_placeholder_dataset


def test_is_migration_file_returns_true_for_file_with_label_easy_migration_dot_zip():
file_metadata = {'label': 'easy-migration.zip'}
assert datastation.dataverse.destroy_placeholder_dataset.is_migration_file(file_metadata) == True


def test_is_migration_file_returns_true_for_file_with_directory_label_easy_migration():
file_metadata = {'directoryLabel': 'easy-migration'}
assert datastation.dataverse.destroy_placeholder_dataset.is_migration_file(file_metadata) == True


def test_is_migration_file_returns_false_for_file_with_label_not_easy_migration_dot_zip():
file_metadata = {'label': 'not-easy-migration.zip'}
assert datastation.dataverse.destroy_placeholder_dataset.is_migration_file(file_metadata) == False


def test_is_migration_file_returns_false_for_file_with_directory_label_not_easy_migration():
file_metadata = {'directoryLabel': 'not-easy-migration'}
assert datastation.dataverse.destroy_placeholder_dataset.is_migration_file(file_metadata) == False

Loading