Exemplo n.º 1
0
 def setUp(self):
     self.gcode_id = gcodes.add_gcode(
         path="a/b/c",
         filename="file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
     )
     self.gcode_id2 = gcodes.add_gcode(
         path="a/b/c",
         filename="file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
     )
     self.printjob_ids = []
     for i in range(0, 3):
         self.printjob_ids.append(
             printjobs.add_printjob(
                 gcode_id=self.gcode_id,
                 gcode_data={"id": self.gcode_id},
                 printer_ip="172.16.236.11:8080",
                 printer_data={"ip": "172.16.236.11:8080"},
             ))
     for i in range(0, 3):
         self.printjob_ids.append(
             printjobs.add_printjob(
                 gcode_id=self.gcode_id2,
                 gcode_data={"id": self.gcode_id2},
                 printer_ip="172.16.236.12:8080",
                 printer_data={"ip": "172.16.236.12:8080"},
             ))
Exemplo n.º 2
0
 def test_delete(self):
     gcode_id = gcodes.add_gcode(
         path="delete-ab/c",
         filename="delete-gcode-specific-file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
         user_uuid=UUID_USER,
     )
     printjobs.add_printjob(
         gcode_id=gcode_id,
         gcode_data={"id": gcode_id},
         printer_uuid="20e91c14-c3e4-4fe9-a066-e69d53324a20",
         printer_data={"host": "172.16.236.11:8080"},
     )
     printjobs.add_printjob(
         gcode_id=gcode_id,
         gcode_data={"id": gcode_id},
         printer_uuid="20e91c14-c3e4-4fe9-a066-e69d53324a20",
         printer_data={"host": "172.16.236.11:8080"},
     )
     with app.test_client() as c:
         c.set_cookie("localhost", "access_token_cookie", TOKEN_USER)
         response = c.delete(
             "/gcodes/%s" % gcode_id, headers={"x-csrf-token": TOKEN_USER_CSRF},
         )
         self.assertEqual(response.status_code, 204)
     self.assertEqual(gcodes.get_gcode(gcode_id), None)
     pjs = [pj for pj in printjobs.get_printjobs() if pj["gcode_id"] == gcode_id]
     self.assertEqual(len(pjs), 2)
     for pj in pjs:
         self.assertFalse(pj["gcode_data"]["available"])
Exemplo n.º 3
0
def printjob_create():
    data = request.json
    if not data:
        return abort(make_response("", 400))
    gcode_id = data.get("gcode", None)
    printer_uuid = data.get("printer", None)
    if not gcode_id or not printer_uuid:
        return abort(make_response("", 400))
    printer = printers.get_printer(printer_uuid)
    if printer is None:
        return abort(make_response("", 404))
    gcode = gcodes.get_gcode(gcode_id)
    if gcode is None:
        return abort(make_response("", 404))
    try:
        printer_inst = clients.get_printer_instance(printer)
        uploaded = printer_inst.upload_and_start_job(gcode["absolute_path"],
                                                     gcode["path"])
        if not uploaded:
            return abort(
                make_response(
                    jsonify(message="Cannot upload the g-code to the printer"),
                    500))
        printjob_id = printjobs.add_printjob(
            gcode_id=gcode["id"],
            printer_uuid=printer["uuid"],
            user_uuid=get_current_user()["uuid"],
            gcode_data={
                "id": gcode["id"],
                "filename": gcode["filename"],
                "size": gcode["size"],
                "available": True,
            },
            printer_data={
                "ip": printer["ip"],
                "port": printer["port"],
                "hostname": printer["hostname"],
                "name": printer["name"],
                "client": printer["client"],
            },
        )
        return (
            jsonify({
                "id": printjob_id,
                "user_uuid": get_current_user()["uuid"]
            }),
            201,
        )
    except clients.utils.PrinterClientException:
        return abort(make_response("", 409))
Exemplo n.º 4
0
 def test_delete(self):
     gcode_id = gcodes.add_gcode(
         path="a/b/c",
         filename="file",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
     )
     printjob_id = printjobs.add_printjob(
         gcode_id=gcode_id,
         gcode_data={"id": gcode_id},
         printer_ip="172.16.236.11:8080",
         printer_data={"ip": "172.16.236.11:8080"},
     )
     with app.test_client() as c:
         response = c.delete("/printjobs/%s" % printjob_id)
         self.assertEqual(response.status_code, 204)
     self.assertEqual(printjobs.get_printjob(printjob_id), None)
Exemplo n.º 5
0
 def setUp(self):
     self.gcode_uuid = gcodes.add_gcode(
         uuid=guid.uuid4(),
         path="a/b/c",
         filename="file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
         user_uuid=UUID_USER,
         organization_uuid=UUID_ORG,
     )
     self.printjob_id = printjobs.add_printjob(
         gcode_uuid=self.gcode_uuid,
         gcode_data={"uuid": self.gcode_uuid},
         printer_uuid="20e91c14-c3e4-4fe9-a066-e69d53324a20",
         printer_data={
             "ip": "172.16.236.11",
             "port": 8080
         },
         user_uuid=UUID_USER,
         organization_uuid=UUID_ORG,
     )
Exemplo n.º 6
0
def printjob_create():
    data = request.json
    if not data:
        return abort(400)
    gcode_id = data.get("gcode", None)
    printer_ip = data.get("printer", None)
    if not gcode_id or not printer_ip:
        return abort(400)
    printer = printers.get_printer(printer_ip)
    if printer is None:
        return abort(404)
    gcode = gcodes.get_gcode(gcode_id)
    if gcode is None:
        return abort(404)
    try:
        printer_inst = drivers.get_printer_instance(printer)
        uploaded = printer_inst.upload_and_start_job(gcode["absolute_path"],
                                                     gcode["path"])
        if not uploaded:
            return abort(500, "Cannot upload the g-code to the printer")
        printjob_id = printjobs.add_printjob(
            gcode_id=gcode["id"],
            printer_ip=printer["ip"],
            gcode_data={
                "id": gcode["id"],
                "filename": gcode["filename"],
                "size": gcode["size"],
                "available": True,
            },
            printer_data={
                "ip": printer["ip"],
                "name": printer["name"],
                "client": printer["client"],
            },
        )
        return jsonify({"id": printjob_id}), 201
    except drivers.utils.PrinterDriverException:
        return abort(409)
Exemplo n.º 7
0
def printjob_create(org_uuid):
    data = request.json
    if not data:
        return abort(make_response(jsonify(message="Missing payload"), 400))
    gcode_uuid = data.get("gcode", None)
    printer_uuid = data.get("printer", None)
    if not gcode_uuid or not printer_uuid:
        return abort(
            make_response(jsonify(message="Missing gcode_uuid or printer_uuid"), 400)
        )
    validate_uuid(gcode_uuid)
    validate_uuid(printer_uuid)
    printer = printers.get_printer(printer_uuid)
    if printer is None or printer["organization_uuid"] != org_uuid:
        return abort(make_response(jsonify(message="Not found"), 404))
    gcode = gcodes.get_gcode(gcode_uuid)
    if gcode is None:
        return abort(make_response(jsonify(message="Not found"), 404))
    try:
        network_client = network_clients.get_network_client(
            printer["network_client_uuid"]
        )
        printer_data = dict(network_client)
        printer_data.update(dict(printer))
        printer_inst = clients.get_printer_instance(printer_data)
        uploaded = printer_inst.upload_and_start_job(
            gcode["absolute_path"], gcode["path"]
        )
        if not uploaded:
            return abort(
                make_response(
                    jsonify(message="Cannot upload the g-code to the printer"), 500
                )
            )
        printjob_uuid = guid.uuid4()
        printjobs.add_printjob(
            uuid=printjob_uuid,
            gcode_uuid=gcode["uuid"],
            organization_uuid=org_uuid,
            printer_uuid=printer["uuid"],
            user_uuid=get_current_user()["uuid"],
            gcode_data={
                "uuid": gcode["uuid"],
                "filename": gcode["filename"],
                "size": gcode["size"],
                "available": True,
            },
            printer_data={
                "ip": printer_inst.ip,
                "port": printer_inst.port,
                "hostname": printer_inst.hostname,
                "name": printer_inst.name,
                "client": printer_inst.client,
            },
        )
        return (
            jsonify({"uuid": printjob_uuid, "user_uuid": get_current_user()["uuid"]}),
            201,
        )
    except clients.utils.PrinterClientException as e:
        app.logger.error(e)
        return abort(
            make_response(
                jsonify(message="Cannot schedule a printjob: %s" % str(e)), 409
            )
        )
Exemplo n.º 8
0
def printjob_create(org_uuid):
    data = request.json
    if not data:
        return abort(make_response(jsonify(message="Missing payload"), 400))
    gcode_uuid = data.get("gcode", None)
    printer_uuid = data.get("printer",
                            None)  # FIXME: this should be part of the path
    if not gcode_uuid or not printer_uuid:
        return abort(
            make_response(
                jsonify(message="Missing gcode_uuid or printer_uuid"), 400))

    printer = printers.get_printer(printer_uuid)
    if not printer or printer['organization_uuid'] != org_uuid:
        raise http_exceptions.UnprocessableEntity(
            f"Invalid printer {printer_uuid} - does not exist.")

    gcode = gcodes.get_gcode(gcode_uuid)
    if not gcode:
        raise http_exceptions.UnprocessableEntity(
            "Invalid gcode {gcode_uuid} - does not exist.")

    network_client = network_clients.get_network_client(
        printer["network_client_uuid"])
    printer_data = dict(network_client)
    printer_data.update(dict(printer))
    printer_inst = clients.get_printer_instance(printer_data)
    try:
        printer_inst.upload_and_start_job(gcode["absolute_path"],
                                          gcode["path"])
    except DeviceInvalidState as e:
        raise http_exceptions.Conflict(*e.args)
    except DeviceCommunicationError as e:
        raise http_exceptions.GatewayTimeout(*e.args)
    # TODO: robin - add_printjob should be method of printer and printer a
    #               method of organization
    printjob_uuid = printjobs.add_printjob(
        gcode_uuid=gcode["uuid"],
        organization_uuid=org_uuid,
        printer_uuid=printer["uuid"],
        user_uuid=get_current_user()["uuid"],
        gcode_data={
            "uuid": gcode["uuid"],
            "filename": gcode["filename"],
            "size": gcode["size"],
            "available": True,
        },
        # FIXME: printer data should be kept in printer object only
        printer_data={
            "ip": printer_inst.ip,
            "port": printer_inst.port,
            "hostname": printer_inst.hostname,
            "name": printer_inst.name,
            "client": printer_inst.client,
        },
    )
    return (
        jsonify({
            "uuid": printjob_uuid,
            "user_uuid": get_current_user()["uuid"]
        }),
        201,
    )
Exemplo n.º 9
0
 def setUp(self):
     self.gcode_uuid = gcodes.add_gcode(
         uuid=guid.uuid4(),
         path="a/b/c",
         filename="file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
         user_uuid=UUID_USER,
         organization_uuid=UUID_ORG,
     )
     self.gcode_uuid2 = gcodes.add_gcode(
         uuid=guid.uuid4(),
         path="a/b/c",
         filename="file1",
         display="file-display",
         absolute_path="/ab/a/b/c",
         size=123,
         user_uuid=UUID_USER,
         organization_uuid=UUID_ORG,
     )
     uuids = []
     for i in range(0, 7):
         uuids.append(guid.uuid4())
     uuids.sort(reverse=True)
     self.printjob_ids = []
     for i in range(0, 3):
         self.printjob_ids.append(
             printjobs.add_printjob(
                 uuid=uuids.pop(),
                 gcode_uuid=self.gcode_uuid,
                 gcode_data={"uuid": self.gcode_uuid},
                 printer_uuid="20e91c14-c3e4-4fe9-a066-e69d53324a20",
                 printer_data={
                     "ip": "172.16.236.11",
                     "port": 8080
                 },
                 user_uuid=UUID_USER,
                 organization_uuid=UUID_ORG,
             ))
     for i in range(0, 3):
         self.printjob_ids.append(
             printjobs.add_printjob(
                 uuid=uuids.pop(),
                 gcode_uuid=self.gcode_uuid2,
                 gcode_data={"uuid": self.gcode_uuid2},
                 printer_uuid="e24a9711-aabc-48f0-b790-eac056c43f07",
                 printer_data={
                     "ip": "172.16.236.12",
                     "port": 8080
                 },
                 user_uuid=UUID_USER,
                 organization_uuid=UUID_ORG,
             ))
     printjobs.add_printjob(
         uuid=uuids.pop(),
         gcode_uuid=self.gcode_uuid2,
         gcode_data={"uuid": self.gcode_uuid2},
         printer_uuid="7e5129ad-08d0-42d1-b65c-847d3c636157",
         printer_data={
             "ip": "172.16.236.12",
             "port": 8080
         },
         user_uuid=UUID_USER,
         organization_uuid=UUID_ORG2,
     )