Beispiel #1
0
def mfold_task_result(task_id):
    """Handler for getting mfold result from just a task id

    Args:
        task_id: Id of task generated via RESTful API

    Returns:
        Json object of status or sends zipped file
    """
    status = get_async_result(delegate, task_id)
    if status['status'] == 'fail':
        return jsonify({
            'status': 'error',
            'error': 'Task is not ready or has failed'
        }), 400
    elif status['status'] == 'error':
        return jsonify(status), 400

    zip_file = get_zip_path(task_id)
    try:
        return send_file(zip_file)
    except IOError:
        return jsonify({
            'status': 'error',
            'error': 'File does not exist'
        }), 400
Beispiel #2
0
def zip_files_from_sirna(struct):
    """Function which generates email msg from siRNA

    Args:
        struct: sh-miR struct

    Returns:
        zip message
    """
    for element in struct:
        task_id = element[-1]
        with app.app_context():
            path = get_zip_path(task_id, task_id)

        zip_msg = MIMEBase('application', 'zip')
        with open(path) as zip_file:
            zip_msg.set_payload(zip_file.read())
        encoders.encode_base64(zip_msg)
        zip_msg.add_header('Content-Disposition', 'attachment',
                           filename=os.path.basename(path))

        yield zip_msg