Exemplo n.º 1
0
    def showDevicesPage(self):
        self.BackButton.setEnabled(True)
        self.setNextButton(BUTTON_NEXT)

        beginWaitCursor()
        try:
            if not self.devices:
                log.info("Searching on USB bus...")
                filter_dict = {'wifi-config': (operator.gt, WIFI_CONFIG_NONE)}

                try:
                    from base import smart_install
                except ImportError:
                    log.error("Failed to Import smart_install.py from base")
                else:
                    endWaitCursor()
                    smart_install.disable(GUI_MODE, 'qt4')
                    beginWaitCursor()

                self.devices = device.probeDevices([self.bus], 0, 0,
                                                   filter_dict, self.search)

        finally:
            endWaitCursor()

        self.clearDevicesTable()

        if self.devices:
            self.NextButton.setEnabled(True)
            self.DevicesFoundIcon.setPixmap(load_pixmap('info', '16x16'))

            if len(self.devices) == 1:
                self.DevicesFoundLabel.setText(
                    self.__tr(
                        "<b>1 wireless capable device found.</b> Click <i>Next</i> to continue."
                    ))
            else:
                self.DevicesFoundLabel.setText(
                    self.__tr(
                        "<b>%s wireless capable devices found.</b> Select the device to install and click <i>Next</i> to continue."
                        % len(self.devices)))

            self.loadDevicesTable()

        else:
            self.NextButton.setEnabled(False)
            self.DevicesFoundIcon.setPixmap(load_pixmap('error', '16x16'))
            log.error("No devices found on bus: %s" % self.bus)
            self.DevicesFoundLabel.setText(
                self.__tr(
                    "<b>No wireless capable devices found.</b><br>Plug in your printer with a USB cable and click <i>Refresh</i> to search again."
                ))

        self.displayPage(PAGE_DEVICES)
Exemplo n.º 2
0
    def showDevicesPage(self):
        self.BackButton.setEnabled(True)
        self.setNextButton(BUTTON_NEXT)

        beginWaitCursor()
        try:
            if not self.devices:
                log.info("Searching on USB bus...")
                filter_dict = {'wifi-config' : (operator.gt, WIFI_CONFIG_NONE)}

                try:
                    from base import smart_install
                except ImportError:
                    log.error("Failed to Import smart_install.py from base")
                else:
                    endWaitCursor()
                    smart_install.disable(GUI_MODE, 'qt4')
                    beginWaitCursor()

                self.devices = device.probeDevices([self.bus], 0, 0, filter_dict, self.search)

        finally:
            endWaitCursor()

        self.clearDevicesTable()

        if self.devices:
            self.NextButton.setEnabled(True)
            self.DevicesFoundIcon.setPixmap(load_pixmap('info', '16x16'))

            if len(self.devices) == 1:
                self.DevicesFoundLabel.setText(self.__tr("<b>1 wireless capable device found.</b> Click <i>Next</i> to continue."))
            else:
                self.DevicesFoundLabel.setText(self.__tr("<b>%s wireless capable devices found.</b> Select the device to install and click <i>Next</i> to continue." % len(self.devices)))

            self.loadDevicesTable()

        else:
            self.NextButton.setEnabled(False)
            self.DevicesFoundIcon.setPixmap(load_pixmap('error', '16x16'))
            log.error("No devices found on bus: %s" % self.bus)
            self.DevicesFoundLabel.setText(self.__tr("<b>No wireless capable devices found.</b><br>Plug in your printer with a USB cable and click <i>Refresh</i> to search again."))

        self.displayPage(PAGE_DEVICES)
Exemplo n.º 3
0
def main_function(passwordObj = None, mode = GUI_MODE, ui_toolkit= UI_TOOLKIT_QT4, quiet_mode = False, DEVICE_URI=None):
    global Error_Found
    try:
        from base import device, pml
        # This can fail due to hpmudext not being present
    except ImportError:
        log.error("Device library is not avail.")
        sys.exit(1)

    if mode == INTERACTIVE_MODE:
        try:
            from base import password
        except ImportError:
            log.warn("Failed to import password object")
        else:
            cups.setPasswordCallback(password.showPasswordPrompt)

        mapofDevices = parseQueues(mode)
        if mapofDevices.items() == 0:
            log.debug("No queues found.")

        for key,val in mapofDevices.items():
            if len(val) >1:
                if not quiet_mode:
                    Error_Found = True
                    log.warn("%d queues of same device %s is configured.\nRemove unwanted queues."%(len(val),val[0].PrinterName))

                for que in val:
                    reconfigure_Queue(que, mode)
            else:
                log.debug("")
                log.debug("Single print queue is configured for '%s'. " %val[0].PrinterName)
                reconfigure_Queue(val[0], mode)

        SI_sts, error_str = smart_install.disable(mode, '', None, None, passwordObj)
        if SI_sts != ERROR_NO_SI_DEVICE:
            Error_Found = True

        if Error_Found is False:
            if not quiet_mode:
                if len(mapofDevices) == 0:
                    log.warn("No Queue(s) configured.")
                else:
                    log.info("Queue(s) configured correctly using HPLIP.")

        cups.releaseCupsInstance()

    elif mode == GUI_MODE:
        # Only Qt4 is supported.
        if ui_toolkit == 'qt3':
            log.error("This is not supported in Qt3, requires GUI support (try running with --qt4). Also, try using interactive (-i) mode.")
            sys.exit(1)

        try:
            from PyQt4.QtGui import QApplication, QMessageBox
            from ui4.queuesconf import QueuesDiagnose
            from ui4 import setupdialog
        except ImportError:
            log.error("Unable to load Qt4 support. Is it installed?")
            sys.exit(1)
        app = QApplication(sys.argv)
        dialog = QueuesDiagnose(None, "","",QUEUES_MSG_SENDING,passwordObj)

        cups.setPasswordCallback(setupdialog.showPasswordUI)
        mapofDevices = parseQueues(mode)
        if mapofDevices.items() == 0:
            log.debug("No queues found.")

        for key,val in mapofDevices.items():
            if len(val) >1:
                log.warn('%d queues of same device %s is configured.  Remove unwanted queues.' %(len(val),val[0].PrinterName))
                if not quiet_mode:
                    Error_Found = True
                    dialog.showMessage("%d queues of same device %s is configured.\nRemove unwanted queues."%(len(val),val[0].PrinterName))
                for que in val:
                    reconfigure_Queue(que, mode, dialog,app)

            else:
                log.debug("")
                log.debug("Single print queue is configured for '%s'. " %val[0].PrinterName)
                reconfigure_Queue(val[0], mode, dialog, app)

        SI_sts, error_str = smart_install.disable(mode, ui_toolkit, dialog, app, passwordObj)
        if SI_sts != ERROR_NO_SI_DEVICE:
            Error_Found = True

        if Error_Found is False:
            if not quiet_mode:
                if len(mapofDevices) == 0:
                    msg= "No Queue(s) configured."
                else:
                    msg= "Queue(s) configured correctly using HPLIP."
                dialog.showSuccessMessage(msg)

        cups.releaseCupsInstance()
Exemplo n.º 4
0
    def updateProbedDevicesPage(self, devices=None, param=""):
        QApplication.setOverrideCursor(QApplication.waitCursor)

        if self.bus == "net":
            io_str = self.__tr("network")

        elif self.bus == "usb":
            io_str = self.__tr("USB bus")

        elif self.bus == "par":
            io_str = self.__tr("parallel port")

        QToolTip.add(
            self.searchFiltersPushButton,
            self.__tr('Current Settings: Filter: [%2]  Search: "%3"  TTL: %4  Timeout: %5s')
            .arg(",".join(self.filter))
            .arg(self.search or "")
            .arg(self.ttl)
            .arg(self.timeout),
        )

        log.debug("Updating probed devices list...")
        log.debug(self.bus)

        self.probedDevicesListView.clear()

        while self.probedDevicesListView.columns():
            self.probedDevicesListView.removeColumn(0)

        self.probedDevicesListView.addColumn(self.__tr("Model"))

        if self.bus == "usb":
            self.probedDevicesListView.addColumn(self.__tr("Serial No."))

        elif self.bus == "net":
            self.probedDevicesListView.addColumn(self.__tr("IP Address"))
            self.probedDevicesListView.addColumn(self.__tr("Host Name"))

        elif self.bus == "par":
            self.probedDevicesListView.addColumn(self.__tr("Device"))

        self.probedDevicesListView.addColumn(self.__tr("Device URI"))

        if devices is None:
            FILTER_MAP = {
                "print": None,
                "none": None,
                "scan": "scan-type",
                "copy": "copy-type",
                "pcard": "pcard-type",
                "fax": "fax-type",
            }

            filter_dict = {}

            if prop.fax_build and prop.scan_build:
                for f in self.filter:
                    if f in FILTER_MAP:
                        filter_dict[FILTER_MAP[f]] = (operator.gt, 0)
                    else:
                        filter_dict[f] = (operator.gt, 0)
            else:
                filter_dict["scan-type"] = (operator.ge, SCAN_TYPE_NONE)

            if self.bus == "usb":
                try:
                    from base import smart_install
                except ImportError:
                    log.error("Failed to Import smart_install.py")
                else:  # check if any SmartInstall devices and disables (if not, ignores)
                    smart_install.disable(GUI_MODE, "qt3")

            devices = device.probeDevices(
                [self.bus], self.timeout, self.ttl, filter_dict, self.search, net_search="slp"
            )

            self.probeHeadingTextLabel.setText(self.__tr("%1 device(s) found on the %1:").arg(len(devices)).arg(io_str))

        else:
            if self.bus == "net":
                self.probeHeadingTextLabel.setText(
                    self.__tr("%1 device(s) found on the %1 at address %2:").arg(len(devices)).arg(io_str).arg(param)
                )

            elif self.bus == "usb":
                self.probeHeadingTextLabel.setText(
                    self.__tr("%1 device(s) found on the %1 at ID %2:").arg(len(devices)).arg(io_str).arg(param)
                )

            elif self.bus == "par":
                self.probeHeadingTextLabel.setText(
                    self.__tr("%1 device(s) found on the %1 device node ID %2:")
                    .arg(len(devices))
                    .arg(io_str)
                    .arg(param)
                )

        log.debug(devices)

        if devices:
            row = 0
            for d in devices:
                back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(d)

                mq = {}
                model_ui = models.normalizeModelUIName(model)

                if self.bus == "usb":
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq, model_ui, serial, d)

                elif self.bus == "net":
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq, model_ui, host, devices[d][2], d)

                elif self.bus == "par":
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq, model_ui, dev_file, d)

                row += 1

            i = self.probedDevicesListView.firstChild()
            self.probedDevicesListView.setCurrentItem(i)
            self.probedDevicesListView.setSelected(i, True)
            item = self.probedDevicesListView.currentItem()
            self.device_uri = item.device_uri
            self.updateModelQuery(item)
            self.setNextEnabled(self.ProbedDevicesPage, True)
            log.debug(self.device_uri)

        else:
            self.setNextEnabled(self.ProbedDevicesPage, False)
            QApplication.restoreOverrideCursor()
            return False

        QApplication.restoreOverrideCursor()
        return True
Exemplo n.º 5
0
    def updateProbedDevicesPage(self, devices=None, param=''):
        QApplication.setOverrideCursor(QApplication.waitCursor)

        if self.bus == 'net':
            io_str = self.__tr("network")

        elif self.bus == 'usb':
            io_str = self.__tr("USB bus")

        elif self.bus == 'par':
            io_str = self.__tr("parallel port")

        QToolTip.add(
            self.searchFiltersPushButton,
            self.__tr(
                'Current Settings: Filter: [%2]  Search: "%3"  TTL: %4  Timeout: %5s'
            ).arg(','.join(self.filter)).arg(self.search or '').arg(
                self.ttl).arg(self.timeout))

        log.debug("Updating probed devices list...")
        log.debug(self.bus)

        self.probedDevicesListView.clear()

        while self.probedDevicesListView.columns():
            self.probedDevicesListView.removeColumn(0)

        self.probedDevicesListView.addColumn(self.__tr("Model"))

        if self.bus == 'usb':
            self.probedDevicesListView.addColumn(self.__tr("Serial No."))

        elif self.bus == 'net':
            self.probedDevicesListView.addColumn(self.__tr("IP Address"))
            self.probedDevicesListView.addColumn(self.__tr("Host Name"))

        elif self.bus == 'par':
            self.probedDevicesListView.addColumn(self.__tr("Device"))

        self.probedDevicesListView.addColumn(self.__tr("Device URI"))

        if devices is None:
            FILTER_MAP = {
                'print': None,
                'none': None,
                'scan': 'scan-type',
                'copy': 'copy-type',
                'pcard': 'pcard-type',
                'fax': 'fax-type',
            }

            filter_dict = {}

            if prop.fax_build and prop.scan_build:
                for f in self.filter:
                    if f in FILTER_MAP:
                        filter_dict[FILTER_MAP[f]] = (operator.gt, 0)
                    else:
                        filter_dict[f] = (operator.gt, 0)
            else:
                filter_dict['scan-type'] = (operator.ge, SCAN_TYPE_NONE)

            if self.bus == 'usb':
                try:
                    from base import smart_install
                except ImportError:
                    log.error("Failed to Import smart_install.py")
                else:  # check if any SmartInstall devices and disables (if not, ignores)
                    smart_install.disable(GUI_MODE, 'qt3')

            devices = device.probeDevices([self.bus],
                                          self.timeout,
                                          self.ttl,
                                          filter_dict,
                                          self.search,
                                          net_search='slp')

            self.probeHeadingTextLabel.setText(
                self.__tr("%1 device(s) found on the %1:").arg(
                    len(devices)).arg(io_str))

        else:
            if self.bus == 'net':
                self.probeHeadingTextLabel.setText(
                    self.__tr(
                        "%1 device(s) found on the %1 at address %2:").arg(
                            len(devices)).arg(io_str).arg(param))

            elif self.bus == 'usb':
                self.probeHeadingTextLabel.setText(
                    self.__tr("%1 device(s) found on the %1 at ID %2:").arg(
                        len(devices)).arg(io_str).arg(param))

            elif self.bus == 'par':
                self.probeHeadingTextLabel.setText(
                    self.__tr(
                        "%1 device(s) found on the %1 device node ID %2:").arg(
                            len(devices)).arg(io_str).arg(param))

        log.debug(devices)

        if devices:
            row = 0
            for d in devices:
                back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(
                    d)

                mq = {}
                model_ui = models.normalizeModelUIName(model)

                if self.bus == 'usb':
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq,
                                           model_ui, serial, d)

                elif self.bus == 'net':
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq,
                                           model_ui, host, devices[d][2], d)

                elif self.bus == 'par':
                    i = DeviceListViewItem(self.probedDevicesListView, d, mq,
                                           model_ui, dev_file, d)

                row += 1

            i = self.probedDevicesListView.firstChild()
            self.probedDevicesListView.setCurrentItem(i)
            self.probedDevicesListView.setSelected(i, True)
            item = self.probedDevicesListView.currentItem()
            self.device_uri = item.device_uri
            self.updateModelQuery(item)
            self.setNextEnabled(self.ProbedDevicesPage, True)
            log.debug(self.device_uri)

        else:
            self.setNextEnabled(self.ProbedDevicesPage, False)
            QApplication.restoreOverrideCursor()
            return False

        QApplication.restoreOverrideCursor()
        return True
Exemplo n.º 6
0
def main_function(passwordObj=None,
                  mode=GUI_MODE,
                  ui_toolkit=UI_TOOLKIT_QT4,
                  quiet_mode=False,
                  DEVICE_URI=None):
    global Error_Found
    try:
        from base import device, pml
        # This can fail due to hpmudext not being present
    except ImportError:
        log.error("Device library is not avail.")
        sys.exit(1)

    if mode == INTERACTIVE_MODE:
        try:
            from base import password
        except ImportError:
            log.warn("Failed to import password object")
        else:
            cups.setPasswordCallback(password.showPasswordPrompt)

        mapofDevices = parseQueues(mode)
        if mapofDevices.items() == 0:
            log.debug("No queues found.")

        for key, val in mapofDevices.items():
            if len(val) > 1:
                if not quiet_mode:
                    Error_Found = True
                    log.warn(
                        "%d queues of same device %s is configured.\nRemove unwanted queues."
                        % (len(val), val[0].PrinterName))

                for que in val:
                    reconfigure_Queue(que, mode)
            else:
                log.debug("")
                log.debug("Single print queue is configured for '%s'. " %
                          val[0].PrinterName)
                reconfigure_Queue(val[0], mode)

        SI_sts, error_str = smart_install.disable(mode, '', None, None,
                                                  passwordObj)
        if SI_sts != ERROR_NO_SI_DEVICE:
            Error_Found = True

        if Error_Found is False:
            if not quiet_mode:
                if len(mapofDevices) == 0:
                    log.warn("No Queue(s) configured.")
                else:
                    log.info("Queue(s) configured correctly using HPLIP.")

        cups.releaseCupsInstance()

    elif mode == GUI_MODE:
        # Only Qt4 is supported.
        if ui_toolkit == 'qt3':
            log.error(
                "This is not supported in Qt3, requires GUI support (try running with --qt4). Also, try using interactive (-i) mode."
            )
            sys.exit(1)

        try:
            from PyQt4.QtGui import QApplication, QMessageBox
            from ui4.queuesconf import QueuesDiagnose
            from ui4 import setupdialog
        except ImportError:
            log.error("Unable to load Qt4 support. Is it installed?")
            sys.exit(1)
        app = QApplication(sys.argv)
        dialog = QueuesDiagnose(None, "", "", QUEUES_MSG_SENDING, passwordObj)

        cups.setPasswordCallback(setupdialog.showPasswordUI)
        mapofDevices = parseQueues(mode)
        if mapofDevices.items() == 0:
            log.debug("No queues found.")

        for key, val in mapofDevices.items():
            if len(val) > 1:
                log.warn(
                    '%d queues of same device %s is configured.  Remove unwanted queues.'
                    % (len(val), val[0].PrinterName))
                if not quiet_mode:
                    Error_Found = True
                    dialog.showMessage(
                        "%d queues of same device %s is configured.\nRemove unwanted queues."
                        % (len(val), val[0].PrinterName))
                for que in val:
                    reconfigure_Queue(que, mode, dialog, app)

            else:
                log.debug("")
                log.debug("Single print queue is configured for '%s'. " %
                          val[0].PrinterName)
                reconfigure_Queue(val[0], mode, dialog, app)

        SI_sts, error_str = smart_install.disable(mode, ui_toolkit, dialog,
                                                  app, passwordObj)
        if SI_sts != ERROR_NO_SI_DEVICE:
            Error_Found = True

        if Error_Found is False:
            if not quiet_mode:
                if len(mapofDevices) == 0:
                    msg = "No Queue(s) configured."
                else:
                    msg = "Queue(s) configured correctly using HPLIP."
                dialog.showSuccessMessage(msg)

        cups.releaseCupsInstance()
Exemplo n.º 7
0
    def showDevicesPage(self):
        self.BackButton.setEnabled(True)
        self.setNextButton(BUTTON_NEXT)
        search = ""

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:
            if not self.devices:
                if self.manual and self.param: # manual, but not passed-in on command line
                    self.manualDiscovery()

                else: # probe
                    net_search_type = ''

                    if self.bus == 'net':
                        if self.discovery_method == 0:
                            net_search_type = "slp"
                        elif self.discovery_method == 1:
                            net_search_type = "mdns"
                        else:
                            net_search_type = "avahi"

                        log.info("Searching... (bus=%s, timeout=%d, ttl=%d, search=%s desc=%d, method=%s)" %
                                 (self.bus,  self.timeout, self.ttl, self.search or "(None)",
                                  self.device_desc, net_search_type))
                    else:
                        log.info("Searching... (bus=%s, search=%s, desc=%d)" %
                                 (self.bus,  self.search or "(None)", self.device_desc))

                    if self.device_desc == DEVICE_DESC_SINGLE_FUNC:
                        filter_dict = {'scan-type' : (operator.le, SCAN_TYPE_NONE)}

                    elif self.device_desc == DEVICE_DESC_MULTI_FUNC:
                        filter_dict = {'scan-type': (operator.gt, SCAN_TYPE_NONE)}

                    else: # DEVICE_DESC_ALL
                        filter_dict = {}

                    if self.bus == 'usb':
                        try:
                            from base import smart_install
                        except ImportError:
                            log.error("Failed to Import smart_install.py from base")
                        else:   #if no Smart Install device found, ignores.
                            QApplication.restoreOverrideCursor()
                            smart_install.disable(GUI_MODE, 'qt4')
                            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

                    self.devices = device.probeDevices([self.bus], self.timeout, self.ttl,
                                                       filter_dict, self.search, net_search=net_search_type)

        finally:
            QApplication.restoreOverrideCursor()

        self.clearDevicesTable()

        if self.devices:
            self.NextButton.setEnabled(True)
            self.DevicesFoundIcon.setPixmap(load_pixmap('info', '16x16'))

            if len(self.devices) == 1:
                self.DevicesFoundLabel.setText(self.__tr("<b>1 device found.</b> Click <i>Next</i> to continue."))
            else:
                self.DevicesFoundLabel.setText(self.__tr("<b>%1 devices found.</b> Select the device to install and click <i>Next</i> to continue.").arg(len(self.devices)))

            self.loadDevicesTable()

        else:
            self.NextButton.setEnabled(False)
            self.DevicesFoundIcon.setPixmap(load_pixmap('error', '16x16'))
            log.error("No devices found on bus: %s" % self.bus)
            self.DevicesFoundLabel.setText(self.__tr("<b>No devices found.</b><br>Click <i>Back</i> to change discovery options, or <i>Refresh</i> to search again."))

        self.displayPage(PAGE_DEVICES)