job_handlers.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:encore 作者: statgen 项目源码 文件源码
def get_job_output(job_id, filename, as_attach=False, mimetype=None, tail=None, head=None, job=None):
    try:
        output_file = job.relative_path(filename)
        if tail or head:
            if tail and head:
                return "Cannot specify tail AND head", 500
            cmd = "head" if head else "tail"
            count = tail or head
            p = subprocess.Popen([cmd, "-n", count, output_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            tail_data, tail_error = p.communicate()
            resp = make_response(tail_data)
            if as_attach:
                resp.headers["Content-Disposition"] = "attachment; filename={}".format(filename)
            if mimetype:
                resp.headers["Content-Type"] = mimetype
            return resp
        else:
            return send_file(output_file, as_attachment=as_attach, mimetype=mimetype)
    except Exception as e:
        print e
        return "File Not Found", 404
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号