def get_already_added_queues(udev_MDL, udev_serial_no, udev_back_end,remove_non_hp_config): status, output = utils.run('lpstat -v') same_printer_queues = [] for p in output.splitlines(): try: match = LPSTAT_PAT.search(p) printer_name = match.group(1) device_uri = match.group(2) if device_uri.startswith("cups-pdf:/"): continue if not USB_PATTERN.search(device_uri): continue back_end = BACK_END_PATTERN.search(device_uri).group(1) serial = USB_PATTERN.search(device_uri).group(1) log.debug("udev_serial_no[%s] serial[%s] udev_back_end[%s] back_end[%s]"%(udev_serial_no, serial, udev_back_end, back_end)) if udev_serial_no == serial and (udev_back_end == back_end or back_end == 'usb'): if remove_non_hp_config and printer_name.find('_') == -1 and printer_name.find('-') != -1: log.debug("Removed %s Queue"%printer_name) # remove queues using cups API cups.delPrinter(printer_name) else: same_printer_queues.append(printer_name) except AttributeError: pass log.debug(same_printer_queues) return same_printer_queues
def get_already_added_queues(udev_MDL, udev_serial_no, udev_back_end, remove_non_hp_config): status, output = utils.run('lpstat -v') same_printer_queues = [] for p in output.splitlines(): try: match = LPSTAT_PAT.search(p) printer_name = match.group(1) device_uri = match.group(2) if device_uri.startswith("cups-pdf:/"): continue if not USB_PATTERN.search(device_uri): continue back_end = BACK_END_PATTERN.search(device_uri).group(1) serial = USB_PATTERN.search(device_uri).group(1) log.debug( "udev_serial_no[%s] serial[%s] udev_back_end[%s] back_end[%s]" % (udev_serial_no, serial, udev_back_end, back_end)) if udev_serial_no == serial and (udev_back_end == back_end or back_end == 'usb'): if remove_non_hp_config and printer_name.find( '_') == -1 and printer_name.find('-') != -1: log.debug("Removed %s Queue" % printer_name) # remove queues using cups API cups.delPrinter(printer_name) else: same_printer_queues.append(printer_name) except AttributeError: pass log.debug(same_printer_queues) return same_printer_queues
def reconfigure_Queue(que, mode, dialog= None,app=None): global Error_Found Error_msg =None if mode == INTERACTIVE_MODE: if 'hp' in que.DeviceType or 'hpfax' in que.DeviceType: if que.PPDFileError == False: log.debug("'%s' is configured correctly." %(que.PrinterName)) else: Error_msg = "PPD file for '%s' is not correct. Need to choose correct PPD file." %(que.PrinterName) else: Error_msg ="'%s' is not configured using HPLIP. Need to remove and re-cofigure using hp-setup." %(que.PrinterName) if Error_msg != None: Error_Found = True log.error(Error_msg) response, value = tui.enter_yes_no("Do you want to remove and re-configure?") if response == False: log.debug("User Exit") sys.exit(1) elif value == True: cups.delPrinter(que.PrinterName) log.info("' %s' removed successfully.\nRe-configuring this printer by hp-setup..."%que.PrinterName) path = utils.which('hp-setup') if path: log.debug("Starting hp-setup") os.system('hp-setup -i') elif que.IsEnabled == False: Error_Found = True responce, value =tui.enter_yes_no("'%s Queue is paused. Do you want to enable queue?"%(que.PrinterName)) if responce == False: log.debug("User Exit") sys.exit(1) elif value == True: cups.enablePrinter(que.PrinterName) log.info("'%s' is enabled successfully"%que.PrinterName) else: log.info("Manually enable '%s'."%que.PrinterName) else: if 'hp' in que.DeviceType or 'hpfax' in que.DeviceType: if que.PPDFileError == False: log.debug("'%s' is configured correctly." %(que.PrinterName)) else: log.error("PPD file for '%s' is not correct. Need to choose correct PPD file." %(que.PrinterName)) Error_msg = QUEUES_INCORRECT_PPD else: log.error("'%s' is not configured using HPLIP. Need to remove and re-cofigure using hp-setup." %(que.PrinterName)) Error_msg =QUEUES_CONFIG_ERROR if Error_msg == None and que.IsEnabled == False: Error_msg = QUEUES_PAUSED if Error_msg and dialog and app: Error_Found = True dialog.init(que.PrinterName, que.DeviceURI, Error_msg) dialog.show() log.debug("Starting GUI loop...") app.exec_()
def NextButton_clicked(self): try: if self.Error_msg != QUEUES_PAUSED: cups.delPrinter(self.printerName) msg = "' " + self.printerName + " ' removed successfully.\nRe-configuring this printer by hp-setup..." log.debug(msg) path = utils.which("hp-setup") if path: log.debug("Starting hp-setup") utils.run("hp-setup") else: cups.enablePrinter(self.printerName) msg = "'" + self.printerName + "' is enabled successfully" SuccessUI(self, self.__tr(msg)) finally: endWaitCursor() self.result = True self.close()
def NextButton_clicked(self): try: if self.Error_msg != QUEUES_PAUSED: cups.delPrinter(self.printerName) msg = "' " + self.printerName + " ' removed successfully.\nRe-configuring this printer by hp-setup..." log.debug(msg) path = utils.which('hp-setup') if path: log.debug("Starting hp-setup") utils.run('hp-setup') else: cups.enablePrinter(self.printerName) msg = "'" + self.printerName + "' is enabled successfully" SuccessUI(self, self.__tr(msg)) finally: endWaitCursor() self.result = True self.close()
def NextButton_clicked(self): p = self.StackedWidget.currentIndex() if p == PAGE_DISCOVERY: self.manual = self.ManualGroupBox.isChecked() self.param = unicode(self.ManualParamLineEdit.text()) self.jd_port = self.JetDirectSpinBox.value() self.search = unicode(self.SearchLineEdit.text()) self.device_desc = int(self.DeviceTypeComboBox.itemData(self.DeviceTypeComboBox.currentIndex()).toInt()[0]) self.discovery_method = self.NetworkDiscoveryMethodComboBox.currentIndex() if self.WirelessButton.isChecked(): dlg = WifiSetupDialog(self, device_uri=None, standalone=False) dlg.exec_() if dlg.success == SUCCESS_CONNECTED: self.manual = True self.param = dlg.hn self.bus = 'net' if not self.WirelessButton.isChecked(): self.showDevicesPage() elif p == PAGE_DEVICES: row = self.DevicesTableWidget.currentRow() self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri self.mq = device.queryModelByURI(self.device_uri) back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri) self.model = models.normalizeModelName(model).lower() self.showAddPrinterPage() elif p == PAGE_ADD_PRINTER: self.print_test_page = self.SendTestPageCheckBox.isChecked() self.print_desc = unicode(self.PrinterDescriptionLineEdit.text()).encode('utf8') self.print_location = unicode(self.PrinterLocationLineEdit.text()).encode('utf8') self.fax_setup = self.SetupFaxGroupBox.isChecked() self.fax_desc = unicode(self.FaxDescriptionLineEdit.text()).encode('utf8') self.fax_location = unicode(self.FaxLocationLineEdit.text()).encode('utf8') self.fax_name_company = unicode(self.NameCompanyLineEdit.text()).encode('utf8') self.fax_number = unicode(self.FaxNumberLineEdit.text()).encode('utf8') self.addPrinter() elif p == PAGE_REMOVE: for row in xrange(self.RemoveDevicesTableWidget.rowCount()): widget = self.RemoveDevicesTableWidget.cellWidget(row, 0) if widget.checkState() == Qt.Checked: item = self.RemoveDevicesTableWidget.item(row, 1) printer = unicode(item.data(Qt.UserRole).toString()).encode('utf-8') log.debug("Removing printer: %s" % printer) if cups.delPrinter(printer) == 0 and os.geteuid!=0 and utils.addgroup()!=[]: FailureUI(self, self.__tr("<b>Unable to delete printer queue. Could not connect to CUPS Server</b><p>Is user added to %s group(s)" %utils.list_to_string(utils.addgroup()))) self.close() else: log.error("Invalid page!") # shouldn't happen!
def reconfigure_Queue(que, mode, dialog=None, app=None): global Error_Found Error_msg = None if mode == INTERACTIVE_MODE: if 'hp' in que.DeviceType or 'hpfax' in que.DeviceType: if que.PPDFileError == False: log.debug("'%s' is configured correctly." % (que.PrinterName)) else: Error_msg = "PPD file for '%s' is not correct. Need to choose correct PPD file." % ( que.PrinterName) else: Error_msg = "'%s' is not configured using HPLIP. Need to remove and re-cofigure using hp-setup." % ( que.PrinterName) if Error_msg != None: Error_Found = True log.error(Error_msg) response, value = tui.enter_yes_no( "Do you want to remove and re-configure?") if response == False: log.debug("User Exit") sys.exit(1) elif value == True: cups.delPrinter(que.PrinterName) log.info( "' %s' removed successfully.\nRe-configuring this printer by hp-setup..." % que.PrinterName) path = utils.which('hp-setup') if path: log.debug("Starting hp-setup") os.system('hp-setup -i') elif que.IsEnabled == False: Error_Found = True responce, value = tui.enter_yes_no( "'%s Queue is paused. Do you want to enable queue?" % (que.PrinterName)) if responce == False: log.debug("User Exit") sys.exit(1) elif value == True: cups.enablePrinter(que.PrinterName) log.info("'%s' is enabled successfully" % que.PrinterName) else: log.info("Manually enable '%s'." % que.PrinterName) else: if 'hp' in que.DeviceType or 'hpfax' in que.DeviceType: if que.PPDFileError == False: log.debug("'%s' is configured correctly." % (que.PrinterName)) else: log.error( "PPD file for '%s' is not correct. Need to choose correct PPD file." % (que.PrinterName)) Error_msg = QUEUES_INCORRECT_PPD else: log.error( "'%s' is not configured using HPLIP. Need to remove and re-cofigure using hp-setup." % (que.PrinterName)) Error_msg = QUEUES_CONFIG_ERROR if Error_msg == None and que.IsEnabled == False: Error_msg = QUEUES_PAUSED if Error_msg and dialog and app: Error_Found = True dialog.init(que.PrinterName, que.DeviceURI, Error_msg) dialog.show() log.debug("Starting GUI loop...") app.exec_()