Skip to content

Commit

Permalink
Fixed + improved dv-dataset-destroy-migration-placeholder (#54)
Browse files Browse the repository at this point in the history
* Modified dv-dataset-destroy-migration-placeholder so that it also recognizes easy-migration.zip
as a placeholder file, and not only and easy-migration folder.

* - Implemented missing dry-run option for dv-dataset-destroy-migration-placeholder
- Refactored filtering on datasets with only 'easy-migration' files + also allowing easy-migration.zip as 'easy-migration' file (formerly, easy-migration
was expected to be a directory containing up to 4 files).
  • Loading branch information
janvanmansum authored Feb 14, 2024
1 parent 0b4debf commit cedc59f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
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
3 changes: 2 additions & 1 deletion src/datastation/dv_dataset_destroy_migration_placeholder.py
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

0 comments on commit cedc59f

Please sign in to comment.