(filename, target)
| 218 | @api.route("/files/<string:target>/<path:filename>", methods=["POST"]) |
| 219 | @restricted_access |
| 220 | def printFileCommand(filename, target): |
| 221 | if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: |
| 222 | return make_response("Unknown target: %s" % target, 404) |
| 223 | |
| 224 | if not _verifyFileExists(target, filename): |
| 225 | return make_response("File not found on '%s': %s" % (target, filename), 404) |
| 226 | |
| 227 | # valid file commands, dict mapping command name to mandatory parameters |
| 228 | valid_commands = { |
| 229 | "select": [] |
| 230 | } |
| 231 | |
| 232 | command, data, response = util.getJsonCommandFromRequest(request, valid_commands) |
| 233 | if response is not None: |
| 234 | return response |
| 235 | |
| 236 | printer = printerManager() |
| 237 | |
| 238 | if command == "select": |
| 239 | # selects/loads a file |
| 240 | printAfterLoading = False |
| 241 | if data.get('print'): |
| 242 | if not printer.isOperational(): |
| 243 | #We try at least once |
| 244 | printer.connect() |
| 245 | |
| 246 | start = time.time() |
| 247 | connect_timeout = 5 #5 secs |
| 248 | |
| 249 | while not printer.isOperational() and not printer.isClosedOrError() and time.time() - start < connect_timeout: |
| 250 | time.sleep(1) |
| 251 | |
| 252 | if not printer.isOperational(): |
| 253 | return make_response("The printer is not responding, can't start printing", 409) |
| 254 | |
| 255 | printAfterLoading = True |
| 256 | |
| 257 | sd = False |
| 258 | if target == FileDestinations.SDCARD: |
| 259 | filenameToSelect = filename |
| 260 | sd = True |
| 261 | else: |
| 262 | filenameToSelect = printer.fileManager.getAbsolutePath(filename) |
| 263 | printer.selectFile(filenameToSelect, sd, printAfterLoading) |
| 264 | |
| 265 | return NO_CONTENT |
| 266 | |
| 267 | @api.route("/files/<string:target>/<path:filename>", methods=["DELETE"]) |
| 268 | @restricted_access |
nothing calls this directly
no test coverage detected