예제 #1
0
    def get(self, request, *args, **kwargs):
        filepath = request.query_params.get('path')
        if not filepath:
            raise ValidationError('Files view expect a path to the file.')

        job_outputs_path = stores.get_job_outputs_path(
            persistence=self.job.persistence_outputs,
            job_name=self.job.unique_name)

        download_filepath = archive_outputs_file(persistence_outputs=self.job.persistence_outputs,
                                                 outputs_path=job_outputs_path,
                                                 namepath=self.job.unique_name,
                                                 filepath=filepath)
        if not download_filepath:
            return Response(status=status.HTTP_404_NOT_FOUND,
                            data='Log file not found: log_path={}'.format(download_filepath))

        filename = os.path.basename(download_filepath)
        chunk_size = 8192
        try:
            wrapped_file = FileWrapper(open(download_filepath, 'rb'), chunk_size)
            response = StreamingHttpResponse(
                wrapped_file, content_type=mimetypes.guess_type(download_filepath)[0])
            response['Content-Length'] = os.path.getsize(download_filepath)
            response['Content-Disposition'] = "attachment; filename={}".format(filename)
            return response
        except FileNotFoundError:
            _logger.warning('Log file not found: log_path=%s', download_filepath)
            return Response(status=status.HTTP_404_NOT_FOUND,
                            data='Log file not found: log_path={}'.format(download_filepath))
예제 #2
0
파일: views.py 프로젝트: tomzhang/polyaxon
    def get(self, request, *args, **kwargs):
        filepath = request.query_params.get('path')
        if not filepath:
            raise ValidationError('Files view expect a path to the file.')

        job_outputs_path = stores.get_job_outputs_path(
            persistence=self.job.persistence_outputs,
            job_name=self.job.unique_name)

        download_filepath = archive_outputs_file(persistence_outputs=self.job.persistence_outputs,
                                                 outputs_path=job_outputs_path,
                                                 namepath=self.job.unique_name,
                                                 filepath=filepath)
        if not download_filepath:
            return Response(status=status.HTTP_404_NOT_FOUND,
                            data='Outputs file not found: log_path={}'.format(download_filepath))

        return stream_file(file_path=download_filepath, logger=_logger)