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

Simplify history import to fix extra files and ObjectStore interactions. #7193

Merged
merged 1 commit into from Jan 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 16 additions & 30 deletions lib/galaxy/tools/imp_exp/__init__.py
Expand Up @@ -101,16 +101,6 @@ def get_tag_str(tag, value):
provenance_attrs = load(open(provenance_file_name))
datasets_attrs += provenance_attrs

# Get counts of how often each dataset file is used; a file can
# be linked to multiple dataset objects (HDAs).
datasets_usage_counts = {}
for dataset_attrs in datasets_attrs:
temp_dataset_file_name = \
os.path.realpath(os.path.join(archive_dir, dataset_attrs['file_name']))
if (temp_dataset_file_name not in datasets_usage_counts):
datasets_usage_counts[temp_dataset_file_name] = 0
datasets_usage_counts[temp_dataset_file_name] += 1

# Create datasets.
for dataset_attrs in datasets_attrs:
metadata = dataset_attrs['metadata']
Expand Down Expand Up @@ -150,26 +140,22 @@ def get_tag_str(tag, value):
os.path.realpath(os.path.abspath(os.path.join(archive_dir, dataset_attrs['file_name'])))
if not file_in_dir(temp_dataset_file_name, os.path.join(archive_dir, "datasets")):
raise MalformedContents("Invalid dataset path: %s" % temp_dataset_file_name)
if datasets_usage_counts[temp_dataset_file_name] == 1:
self.app.object_store.update_from_file(hda.dataset, file_name=temp_dataset_file_name, create=True)

# Import additional files if present. Histories exported previously might not have this attribute set.
dataset_extra_files_path = dataset_attrs.get('extra_files_path', None)
if dataset_extra_files_path:
try:
file_list = os.listdir(os.path.join(archive_dir, dataset_extra_files_path))
except OSError:
file_list = []

if file_list:
for extra_file in file_list:
self.app.object_store.update_from_file(
hda.dataset, extra_dir='dataset_%s_files' % hda.dataset.id,
alt_name=extra_file, file_name=os.path.join(archive_dir, dataset_extra_files_path, extra_file),
create=True)
else:
datasets_usage_counts[temp_dataset_file_name] -= 1
shutil.copyfile(temp_dataset_file_name, hda.file_name)
self.app.object_store.update_from_file(hda.dataset, file_name=temp_dataset_file_name, create=True)
mvdbeek marked this conversation as resolved.
Show resolved Hide resolved

# Import additional files if present. Histories exported previously might not have this attribute set.
dataset_extra_files_path = dataset_attrs.get('extra_files_path', None)
if dataset_extra_files_path:
try:
file_list = os.listdir(os.path.join(archive_dir, dataset_extra_files_path))
except OSError:
file_list = []

if file_list:
for extra_file in file_list:
self.app.object_store.update_from_file(
hda.dataset, extra_dir='dataset_%s_files' % hda.dataset.id,
alt_name=extra_file, file_name=os.path.join(archive_dir, dataset_extra_files_path, extra_file),
create=True)
hda.dataset.set_total_size() # update the filesize record in the database

# Set tags, annotations.
Expand Down