(self, data, sendResponse)
| 164 | return filename in availableFiles |
| 165 | |
| 166 | def printFile(self, data, sendResponse): |
| 167 | fileDestination = fileName = None |
| 168 | |
| 169 | if 'location' in data: |
| 170 | fileDestination = data['location'] |
| 171 | |
| 172 | if 'fileName' in data: |
| 173 | fileName = data['fileName'] |
| 174 | |
| 175 | if not fileDestination in [FileDestinations.LOCAL, FileDestinations.SDCARD]: |
| 176 | self._logger.error('Unknown file location') |
| 177 | sendResponse('unknown_file_location',True) |
| 178 | |
| 179 | if not fileName or not self._verifyFileExists(fileDestination, fileName): |
| 180 | self._logger.error('File not found') |
| 181 | sendResponse('file_not_found',True) |
| 182 | |
| 183 | printer = printerManager() |
| 184 | |
| 185 | # selects/loads a file |
| 186 | if not printer.isOperational(): |
| 187 | #We try at least once |
| 188 | printer.connect() |
| 189 | |
| 190 | start = time.time() |
| 191 | connect_timeout = 5 #5 secs |
| 192 | |
| 193 | while not printer.isOperational() and not printer.isClosedOrError() and time.time() - start < connect_timeout: |
| 194 | time.sleep(1) |
| 195 | |
| 196 | if not printer.isOperational(): |
| 197 | self._logger.error("The printer is not responding, can't start printing") |
| 198 | sendResponse('printer_not_responding',True) |
| 199 | return |
| 200 | |
| 201 | sd = False |
| 202 | if fileDestination == FileDestinations.SDCARD: |
| 203 | filenameToSelect = fileName |
| 204 | sd = True |
| 205 | else: |
| 206 | filenameToSelect = printer.fileManager.getAbsolutePath(fileName) |
| 207 | |
| 208 | if filenameToSelect: |
| 209 | startPrintingStatus = printer.selectFile(filenameToSelect, sd, True) |
| 210 | |
| 211 | if startPrintingStatus: |
| 212 | sendResponse({'success': 'no error', 'printjob_id': printer.currentPrintJobId}) |
| 213 | else: |
| 214 | sendResponse('printer_not_responding',True) |
| 215 | |
| 216 | else: |
| 217 | sendResponse('invalid_filename', True) |
| 218 | |
| 219 | def deletePrintFile(self, data, sendResponse): |
| 220 |
nothing calls this directly
no test coverage detected