Skip to content

Commit

Permalink
Add confirmation before archiving datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 4, 2024
1 parent 41d3c80 commit 9e03534
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions isimip_publisher/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,29 @@ def archive_datasets():
# apply include and exclude lists on the datasets from the database
datasets = patterns.filter_datasets(db_datasets, include=settings.INCLUDE, exclude=settings.EXCLUDE)

for dataset in tqdm(datasets, desc='archive_datasets'.ljust(18)):
for link in dataset.links:
link_version = database.archive_dataset(session, link.path)
if link_version:
archive_path = settings.ARCHIVE_PATH / link_version
for file in link.files:
print(f'Archiving {len(datasets)} datasets. Please type "yes" to confirm.')
string = input()

if string.lower() == 'yes':
for dataset in tqdm(datasets, desc='archive_datasets'.ljust(18)):
for link in dataset.links:
link_version = database.archive_dataset(session, link.path)
if link_version:
archive_path = settings.ARCHIVE_PATH / link_version
for file in link.files:
source_path = settings.PUBLIC_PATH / file.path
target_path = archive_path / Path(source_path).relative_to(settings.PUBLIC_PATH)

if source_path.is_file():
files.move_file(source_path, target_path)

if source_path.with_suffix('.json').is_file():
files.move_file(source_path.with_suffix('.json'), target_path.with_suffix('.json'))

dataset_version = database.archive_dataset(session, dataset.path)
if dataset_version:
archive_path = settings.ARCHIVE_PATH / dataset_version
for file in dataset.files:
source_path = settings.PUBLIC_PATH / file.path
target_path = archive_path / Path(source_path).relative_to(settings.PUBLIC_PATH)

Expand All @@ -305,26 +322,13 @@ def archive_datasets():
if source_path.with_suffix('.json').is_file():
files.move_file(source_path.with_suffix('.json'), target_path.with_suffix('.json'))

dataset_version = database.archive_dataset(session, dataset.path)
if dataset_version:
archive_path = settings.ARCHIVE_PATH / dataset_version
for file in dataset.files:
source_path = settings.PUBLIC_PATH / file.path
target_path = archive_path / Path(source_path).relative_to(settings.PUBLIC_PATH)

if source_path.is_file():
files.move_file(source_path, target_path)

if source_path.with_suffix('.json').is_file():
files.move_file(source_path.with_suffix('.json'), target_path.with_suffix('.json'))
session.commit()

database.update_tree(session, settings.PATH, settings.TREE)
session.commit()

database.update_tree(session, settings.PATH, settings.TREE)
session.commit()

database.clean_tree(session)
session.commit()
database.clean_tree(session)
session.commit()


def check():
Expand Down

0 comments on commit 9e03534

Please sign in to comment.