Skip to content

Commit

Permalink
Add additional checks for installed repository handler, open files us…
Browse files Browse the repository at this point in the history
…ing with-block
  • Loading branch information
guerler committed Mar 29, 2018
1 parent 8a51d02 commit e5a564e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/galaxy/webapps/galaxy/api/workflows.py
Expand Up @@ -283,10 +283,15 @@ def create(self, trans, payload, **kwd):

if 'installed_repository_file' in payload:
installed_repository_file = payload.get('installed_repository_file', '')
workflow_file = open(installed_repository_file, 'rb')
workflow_data = workflow_file.read()
workflow_file.close()
return self.__api_import_from_archive(trans, workflow_data)
if not os.path.exists(installed_repository_file):
raise exceptions.MessageException("Repository file '%s' not found.")
elif os.path.getsize(os.path.abspath(installed_repository_file)) > 0:
workflow_data = None
with open(installed_repository_file, 'rb') as f:
workflow_data = f.read()
return self.__api_import_from_archive(trans, workflow_data)
else:
raise exceptions.MessageException("You attempted to open an empty file.")

if 'archive_source' in payload:
archive_source = payload['archive_source']
Expand All @@ -305,7 +310,7 @@ def create(self, trans, payload, **kwd):
else:
raise exceptions.MessageException("You attempted to upload an empty file.")
else:
raise exceptions.MessageException("Please provide a url or file.")
raise exceptions.MessageException("Please provide a URL or file.")
return self.__api_import_from_archive(trans, archive_data)

if 'from_history_id' in payload:
Expand Down

0 comments on commit e5a564e

Please sign in to comment.