Skip to content

Commit

Permalink
WID-70. Send final filename from client-side and add suffix only for …
Browse files Browse the repository at this point in the history
…the basic unicore files.
  • Loading branch information
popaula937 committed May 17, 2022
1 parent e0079a4 commit 6c1e1eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
14 changes: 11 additions & 3 deletions src/components/JobOutputFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ export const JobOutput = (props: Types.JobOutputProps): JSX.Element => {
* @param file - name of the file to be downloaded from this jobs working dir
*/
async function downloadToCurrentPath(file: string): Promise<void> {
const downloadedFileName = `${file}_${jobId}`;
let downloadedFileName = file;
if (
['stdout', 'stderr', 'UNICORE_SCRIPT_EXIT_CODE'].includes(
downloadedFileName
)
) {
downloadedFileName = `${file}_${jobId}`;
}
if (
fileExists(downloadedFileName) &&
!(await confirmReDownload(downloadedFileName))
Expand All @@ -131,8 +138,9 @@ export const JobOutput = (props: Types.JobOutputProps): JSX.Element => {
console.log('File browser path: ', path);
const dataToSend = {
job_url: jobUrl,
file: file,
path: path
in_file: file,
path: path,
out_file: downloadedFileName
};
try {
setDownloading(true);
Expand Down
6 changes: 4 additions & 2 deletions tvbextunicore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def post(self, *args):
post_params = self.get_json_body()
try:
path = post_params['path']
file = post_params['file']
unicore_file = post_params['in_file']
job_url = post_params['job_url']
drive_file = post_params['out_file']
except KeyError as e:
LOGGER.error(e)
self.set_status(400, 'Request body missing required params!')
Expand All @@ -116,7 +117,8 @@ def post(self, *args):

try:
unicore_wrapper = UnicoreWrapper()
message = unicore_wrapper.download_file(job_url, file, path)
drive_file_path = os.path.join(path, drive_file)
message = unicore_wrapper.download_file(job_url, unicore_file, drive_file_path)
response = build_response(DownloadStatus.SUCCESS, message)
except FileNotExistsException as e:
LOGGER.error(e)
Expand Down
7 changes: 0 additions & 7 deletions tvbextunicore/tests/test_unicore_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ def get_jobs(self, offset, num):
return self.__generate_list_of_jobs()


def test_ensure_format_is_respected():
job = MockPyUnicoreResource('10', None, None, None)
file_name = UnicoreWrapper._prepare_output_filename('test_file', job)
assert file_name == 'test_file_10', 'Changing this filename format affects functionality on the client-side! ' \
'Please check they are kept in sync!'


def test_get_jobs(mocker):
os.environ['CLB_AUTH'] = "test_auth_token"

Expand Down
13 changes: 2 additions & 11 deletions tvbextunicore/unicore_wrapper/unicore_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ def get_job_output(self, job_url):
outputs[k] = {'is_file': v.isfile()}
return outputs

@staticmethod
def _prepare_output_filename(file_name, job):
# TODO: take file extension into consideration?
return f'{file_name}_{job.job_id}'

def download_file(self, job_url, file_name, path=None):
# type: (str, str, str) -> str
"""
Expand All @@ -154,15 +149,11 @@ def download_file(self, job_url, file_name, path=None):
if not wd.get(file_name, False):
raise FileNotExistsException(f'{file_name} does not exist as output of {job_url}!')

final_name = self._prepare_output_filename(file_name, job)

# We need the 'if' below to support download from cell
if path is None:
file_path = final_name
else:
file_path = os.path.join(path, final_name)
path = file_name

wd[file_name].download(file_path)
wd[file_name].download(path)
return 'Downloaded successfully!'

def stream_file(self, job_url, file, offset=0, size=-1):
Expand Down

0 comments on commit 6c1e1eb

Please sign in to comment.