def setPrinterOption(self, option, value): cups.openPPD(self.cur_printer) try: cups.addOption("%s=%s" % (option, value)) cups.setOptions() finally: cups.closePPD()
def render_file(self, path, title, mime_type, force_single_page=False): all_pages = True page_range = '' page_set = 0 nup = 1 cups.resetOptions() if mime_type in ["application/x-cshell", "application/x-perl", "application/x-python", "application/x-shell", "application/x-sh", "text/plain",]: cups.addOption('prettyprint') if nup > 1: cups.addOption('number-up=%d' % nup) if force_single_page: cups.addOption('page-ranges=1') # Force coverpage to 1 page sent_job_id = cups.printFile(self.current_printer, path, title) cups.resetOptions() log.debug("Job ID=%d" % sent_job_id) job_id = 0 time.sleep(1) fax_file = '' complete = False end_time = time.time() + 300.0 # wait for 5 min. max while time.time() < end_time: log.debug("Waiting for fax...") result = list(self.service.CheckForWaitingFax(self.dev.device_uri, prop.username, sent_job_id)) fax_file = str(result[7]) log.debug("Fax file=%s" % fax_file) if fax_file: break if self.check_for_cancel(): log.error("Render canceled. Canceling job #%d..." % sent_job_id) cups.cancelJob(sent_job_id) return '', True time.sleep(1) else: log.error("Timeout waiting for rendering. Canceling job #%d..." % sent_job_id) cups.cancelJob(sent_job_id) return '', False return fax_file, False
def render_file(self, path, title, mime_type, force_single_page=False): all_pages = True page_range = '' page_set = 0 nup = 1 cups.resetOptions() if mime_type in ["application/x-cshell", "application/x-perl", "application/x-python", "application/x-shell", "application/x-sh", "text/plain",]: cups.addOption('prettyprint') if nup > 1: cups.addOption('number-up=%d' % nup) if force_single_page: cups.addOption('page-ranges=1') # Force coverpage to 1 page sent_job_id = cups.printFile(self.current_printer, path, title) cups.resetOptions() log.debug("Job ID=%d" % sent_job_id) job_id = 0 time.sleep(1) fax_file = '' complete = False end_time = time.time() + 300.0 # wait for 5 min. max while time.time() < end_time: log.debug("Waiting for fax... type =%s"%type(self.dev.device_uri)) result = list(self.service.CheckForWaitingFax(self.dev.device_uri, prop.username, sent_job_id)) fax_file = str(result[7]) log.debug("Fax file=%s" % fax_file) if fax_file: break if self.check_for_cancel(): log.error("Render canceled. Canceling job #%d..." % sent_job_id) cups.cancelJob(sent_job_id) return '', True time.sleep(1) else: log.error("Timeout waiting for rendering. Canceling job #%d..." % sent_job_id) cups.cancelJob(sent_job_id) return '', False return fax_file, False
else: all_pages = True page_range = '' page_set = 0 nup = 1 cups.resetOptions() if mime_type in ["application/x-cshell", "application/x-perl", "application/x-python", "application/x-shell", "text/plain",] and prettyprint: cups.addOption('prettyprint') if nup > 1: cups.addOption('number-up=%d' % nup) while True: cups_printers = cups.getPrinters() printer_state = cups.IPP_PRINTER_STATE_STOPPED for p in cups_printers: if p.name == printer_name: printer_state = p.state log.debug("Printer state = %d" % printer_state) if printer_state == cups.IPP_PRINTER_STATE_IDLE: