def get(self, request, *args, **kwargs): auditor.record(event_type=BUILD_JOB_LOGS_VIEWED, instance=self.build, actor_id=request.user.id, actor_name=request.user.username) job_name = self.build.unique_name if self.build.is_done: log_path = stores.get_job_logs_path(job_name=job_name, temp=False) log_path = archive_logs_file(log_path=log_path, namepath=job_name) else: process_logs(build=self.build, temp=True) log_path = stores.get_job_logs_path(job_name=job_name, temp=True) filename = os.path.basename(log_path) chunk_size = 8192 try: wrapped_file = FileWrapper(open(log_path, 'rb'), chunk_size) response = StreamingHttpResponse( wrapped_file, content_type=mimetypes.guess_type(log_path)[0]) response['Content-Length'] = os.path.getsize(log_path) response['Content-Disposition'] = "attachment; filename={}".format( filename) return response except FileNotFoundError: _logger.warning('Log file not found: log_path=%s', log_path) return Response( status=status.HTTP_404_NOT_FOUND, data='Log file not found: log_path={}'.format(log_path))
def get(self, request, *args, **kwargs): auditor.record(event_type=BUILD_JOB_LOGS_VIEWED, instance=self.build, actor_id=request.user.id, actor_name=request.user.username) job_name = self.build.unique_name if self.build.is_done: log_path = stores.get_job_logs_path(job_name=job_name, temp=False) log_path = archive_logs_file(log_path=log_path, namepath=job_name) else: process_logs(build=self.build, temp=True) log_path = stores.get_job_logs_path(job_name=job_name, temp=True) return stream_file(file_path=log_path, logger=_logger)