Ejemplo n.º 1
0
def task_post():
    if "file" not in request.files:
        return json_error(404, "No file has been provided")

    args = dict(
        package=request.form.get("package"),
        timeout=request.form.get("timeout"),
        priority=request.form.get("priority", 1),
        options=request.form.get("options"),
        machine=request.form.get("machine"),
        platform=request.form.get("platform"),
        tags=request.form.get("tags"),
        custom=request.form.get("custom"),
        owner=request.form.get("owner"),
        memory=request.form.get("memory"),
        clock=request.form.get("clock"),
        enforce_timeout=request.form.get("enforce_timeout"),
    )

    f = request.files["file"]

    fd, path = tempfile.mkstemp(dir=settings.samples_directory)
    f.save(path)
    os.close(fd)

    task = Task(path=path, filename=os.path.basename(f.filename), **args)
    db.session.add(task)
    db.session.commit()
    return jsonify(success=True, task_id=task.id)
Ejemplo n.º 2
0
def task_post():
    if "file" not in request.files:
        return json_error(404, "No file has been provided")

    kwargs = dict(
        package=request.form.get("package"),
        timeout=request.form.get("timeout"),
        priority=request.form.get("priority", 1),
        options=request.form.get("options"),
        machine=request.form.get("machine"),
        platform=request.form.get("platform"),
        tags=request.form.get("tags"),
        custom=request.form.get("custom"),
        owner=request.form.get("owner"),
        memory=request.form.get("memory"),
        clock=request.form.get("clock"),
        enforce_timeout=request.form.get("enforce_timeout"),
    )

    f = request.files["file"]

    fd, path = tempfile.mkstemp(dir=settings.samples_directory)
    f.save(path)
    os.close(fd)

    if not os.path.getsize(path):
        os.remove(path)
        return json_error(404, "Provided file is empty")

    task = Task(path=path, filename=os.path.basename(f.filename), **kwargs)

    node = request.form.get("node")
    if node:
        node = Node.query.filter_by(name=node, enabled=True).first()
        if not node:
            return json_error(404, "Node not found")
        task.assign_node(node.id)

    db.session.add(task)
    db.session.commit()
    return jsonify(success=True, task_id=task.id)
Ejemplo n.º 3
0
def task_post():
    if "file" not in request.files:
        return json_error(404, "No file has been provided")

    kwargs = dict(
        package=request.form.get("package"),
        timeout=request.form.get("timeout"),
        priority=request.form.get("priority", 1),
        options=request.form.get("options"),
        machine=request.form.get("machine"),
        platform=request.form.get("platform"),
        tags=request.form.get("tags"),
        custom=request.form.get("custom"),
        owner=request.form.get("owner"),
        memory=request.form.get("memory"),
        clock=request.form.get("clock"),
        enforce_timeout=request.form.get("enforce_timeout"),
    )

    f = request.files["file"]

    fd, path = tempfile.mkstemp(dir=settings.samples_directory)
    f.save(path)
    os.close(fd)

    if not os.path.getsize(path):
        os.remove(path)
        return json_error(404, "Provided file is empty")

    task = Task(path=path, filename=os.path.basename(f.filename), **kwargs)

    node = request.form.get("node")
    if node:
        node = Node.query.filter_by(name=node, enabled=True).first()
        if not node:
            return json_error(404, "Node not found")
        task.assign_node(node.id)

    db.session.add(task)
    db.session.commit()
    return jsonify(success=True, task_id=task.id)