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

Remove rename() task and unnecessary code from rename_results() #2725

Merged
merged 1 commit into from
Apr 23, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 22 additions & 31 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
add_annotated_nodes_selection, index_annotated_nodes_selection
)
from file_store.models import FileStoreItem, FileType
from file_store.tasks import rename
from galaxy_connector.models import Instance
import tool_manager

Expand Down Expand Up @@ -1314,42 +1313,34 @@ def rename_results(self):
logger.debug("Renaming analysis results")
# rename file_store items to new name updated from galaxy file_ids
for result in AnalysisResult.objects.filter(analysis_uuid=self.uuid):
# new name to load
new_file_name = result.file_name
# workaround for FastQC reports downloaded from Galaxy as zip
# archives
(root, ext) = os.path.splitext(new_file_name)
try:
item = FileStoreItem.objects.get(uuid=result.file_store_uuid)
except (FileStoreItem.DoesNotExist,
FileStoreItem.MultipleObjectsReturned) as exc:
logger.error("Error renaming HTML file '%s' to zip: %s",
result.file_store_uuid, exc)
logger.error("Error renaming analysis result '%s': %s",
result, exc)
break

# workaround for FastQC reports downloaded from Galaxy as zip
# archives
(root, ext) = os.path.splitext(result.file_name)
if ext == '.html':
try:
zipfile = FileType.objects.get(name='ZIP')
except (FileType.DoesNotExist,
FileType.MultipleObjectsReturned) as exc:
logger.error("Error renaming HTML to zip: %s", exc)
else:
if item.filetype == zipfile:
item.rename_datafile(''.join([root, '.zip']))
else:
if ext == '.html':
try:
zipfile = FileType.objects.get(name='ZIP')
except (FileType.DoesNotExist,
FileType.MultipleObjectsReturned) as exc:
logger.error("Error renaming HTML to zip: %s", exc)
else:
if item.filetype == zipfile:
new_file_name = ''.join([root, '.zip'])
renamed_file_store_item_uuid = rename(result.file_store_uuid,
new_file_name)

# Try to generate an auxiliary node for visualization purposes
# NOTE: We have to do this after renaming happens because before
# renaming, said FileStoreItems's datafile field does not point
# to an actual file
file_store_item_uuid = (
renamed_file_store_item_uuid if
renamed_file_store_item_uuid else result.file_store_uuid
)
item.rename_datafile(result.file_name)

try:
node = Node.objects.get(file_uuid=file_store_item_uuid)
except (Node.DoesNotExist, Node.MultipleObjectsReturned) as e:
logger.error("Error Fetching Node: %s", e)
node = Node.objects.get(file_uuid=item.uuid)
except (Node.DoesNotExist, Node.MultipleObjectsReturned) as exc:
logger.error("Error retrieving Node with file UUID '%s': %s",
exc)
else:
if node.is_derived():
node.run_generate_auxiliary_node_task()
Expand Down
24 changes: 0 additions & 24 deletions refinery/file_store/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,30 +302,6 @@ def begin_auxiliary_node_generation(**kwargs):
node.run_generate_auxiliary_node_task()


@task()
def rename(uuid, name):
"""Change name of the file on disk and return the updated FileStoreItem
UUID.
:param uuid: UUID of a FileStoreItem.
:type uuid: str.
:param name: New name of the FileStoreItem specified by the UUID.
:type name: str.
:returns: FileStoreItem UUID or None if there was an error.
"""
try:
item = FileStoreItem.objects.get(uuid=uuid)
except (FileStoreItem.DoesNotExist,
FileStoreItem.MultipleObjectsReturned) as exc:
logger.error("Failed to rename FileStoreItem with UUID '%s': %s",
uuid, exc)
return None

if item.rename_datafile(name):
return item.uuid
else:
return None


@task()
def download_file(url, target_path, file_size=1):
'''Download file to target_path from specified URL.
Expand Down