Пример #1
0
    def post(self):
        """Creates or validates printer"""
        args = newPrinterParser.parse_args()
        if args["validate"]:  # validation of printers access data
            args = validateParser.parse_args()
            url = "http://{0}".format(args['ip'])
            auth = OctoprintService.auth(args['apikey'], url)
            if auth is not None:
                return auth, 400
            return "", 200

        else:  # creates multiple printers
            body = request.json
            config = Config.query.first()
            for args in body:
                url = "http://{0}".format(args['ip'])
                auth = OctoprintService.auth(args['apikey'], url)
                if auth is not None:
                    continue
                printer = Printer(args["name"], args["apikey"], url)
                db.session.add(printer)
                db.session.commit()
                scheduler.add_printer_status_job(
                    printer, config.server_refresh
                )  # register printer status for background tasks
            return "", 201
Пример #2
0
    def post(self):
        """Creates or validates printer"""
        args = newPrinterParser.parse_args()
        if args["validate"]:  # validation of printers access data
            args = validateParser.parse_args()
            url = "http://{0}".format(args['ip'])
            auth = OctoprintService.auth(args['apikey'], url)
            if auth is not None:
                return auth, 400
            return "", 200

        else:  # creates multiple printers
            from octoprint_dashboard.app import octoprint_status
            body = request.json
            for args in body:
                url = "http://{0}".format(args['ip'])
                auth = OctoprintService.auth(args['apikey'], url)
                if auth is not None:
                    continue
                printer = Printer(args["name"], args["apikey"], url)
                db.session.add(printer)
                db.session.commit()
                octoprint_status.add_listener(printer)

            socketio.emit("rejoin", broadcast=True, skip_sid=None)
            return "", 201
    def post(self):
        """Saves OctoPrint settings to printers"""
        args = printerIdParser.parse_args()
        printers = g.user.get_accessible_printers_id(args["printerId"])

        for printer in printers:
            try:
                OctoprintService.save_settings(printer, request.json)
            except (requests.ConnectionError, RuntimeError):
                pass

        return "", 200
Пример #4
0
    def post(self):
        """Saves OctoPrint settings to printers"""
        args = printerIdParser.parse_args()
        printers = g.user.get_accessible_printers_id(args["printerId"])

        for printer in printers:
            try:
                OctoprintService.save_settings(printer, request.json)
            except (requests.ConnectionError, RuntimeError):
                pass

        socketio.emit("rejoin", broadcast=True, skip_sid=None)
        return "", 200
Пример #5
0
 def post(self):
     if not request.files["file"]:
         return "", 400
     args = uploadParser.parse_args()
     filename = args["file"].filename
     contents = args["file"].read()
     printers = g.user.get_accessible_printers_id(args["printerId"])
     for printer in printers:
         try:
             OctoprintService.send_file(printer, filename, contents, args['print'])
         except (RuntimeError, requests.ConnectionError):
             pass
     return "", 200
Пример #6
0
    def delete(self, printer_id):
        """Deletes given file on printer"""
        args = deleteParser.parse_args()
        printer = g.user.get_printer_id(printer_id)
        if not printer:
            return "", 403
        if OctoprintService.delete_file(printer, args["origin"], args["name"]):
            return "", 204

        return "", 409
Пример #7
0
 def get(self, printer_id):
     """Gets all files present on given printer"""
     printer = g.user.get_printer_id(printer_id)
     if not printer:
         return "", 403
     try:
         files = OctoprintService.get_files(printer)
     except (RuntimeError, requests.ConnectionError):
         return [], 200
     return files["files"], 200
Пример #8
0
    def post(self, printer_id):
        """Send file from on printer to defined printers or prints given file"""
        args = deleteParser.parse_args()
        printer = g.user.get_printer_id(printer_id)
        if not printer:
            return "", 403
        if args["send"]:  # send file from one printer to defined printers
            printer_ids = sendParser.parse_args()
            printers = g.user.get_accessible_printers_id(printer_ids["printerId"])
            content = OctoprintService.get_file_contents(printer, args["origin"], args["name"])
            for dest_printer in printers:
                try:
                    OctoprintService.send_file(dest_printer, args["name"], content, False)
                except (RuntimeError, requests.ConnectionError):
                    pass
            return "", 200
        else:  # print file
            if OctoprintService.print(printer, args["origin"], args["name"]):
                return "", 200

            return "", 409
Пример #9
0
    def put(self, printer_id):
        """Changes printer access data or name"""
        args = validateParser.parse_args()
        url = "http://{0}".format(args['ip'])
        auth = OctoprintService.auth(args['apikey'], url)
        if auth is not None:
            return "", 400
        printer = Printer.query.get(printer_id)
        printer.name = args['name']
        printer.apikey = args['apikey']
        printer.url = url
        db.session.commit()

        socketio.emit("rejoin", broadcast=True, skip_sid=None)
        return "", 200
Пример #10
0
 def get(self):
     """
     Gets settings of printer.
     If user is superadmin, printer access data are included
     """
     args = printerIdParser.parse_args()
     printers = g.user.get_accessible_printers_id(args["printerId"])
     for printer in printers:
         try:
             ret = OctoprintService.get_settings(printer)
             ret["printerId"] = printer.id
             printer.settings = ret
         except (requests.ConnectionError, RuntimeError):
             pass
     return printers, 200
Пример #11
0
 def put(self, printer_id):
     """Changes printer access data or name"""
     args = validateParser.parse_args()
     url = "http://{0}".format(args['ip'])
     auth = OctoprintService.auth(args['apikey'], url)
     if auth is not None:
         return "", 400
     printer = Printer.query.get(printer_id)
     printer.name = args['name']
     printer.apikey = args['apikey']
     printer.url = url
     db.session.commit()
     config = Config.query.first()
     scheduler.remove_printer_status_job(
         [printer_id])  # reschedule printer job with new access data
     scheduler.add_printer_status_job(printer, config.server_refresh)
     return "", 200
Пример #12
0
 def post(self):
     """
     Issues command to printers.
     Possible action are settings temperature of bed and extruder, pausing and cancelling print
     """
     args = printerControlParser.parse_args()
     printers = g.user.get_accessible_printers_id(args["printerId"])
     for printer in printers:
         try:
             if args["bed"] is not None:
                 OctoprintService.set_bed_temperature(printer, args["bed"])
             if args["tool"] is not None:
                 OctoprintService.set_tool_temperature(
                     printer, args["tool"])
             if args["pause"] is not None:
                 OctoprintService.pause(printer)
             if args["cancel"] is not None:
                 OctoprintService.cancel(printer)
         except (requests.ConnectionError, RuntimeError):
             pass
     return "", 200