예제 #1
0
    def NextButton_clicked(self):
        p = self.StackedWidget.currentIndex()
        if p == PAGE_INTRO:
            self.showDevicesPage()

        elif p == PAGE_DEVICES:
            row = self.DevicesTableWidget.currentRow()
            if row != -1:
                self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri
                self.mq = device.queryModelByURI(self.device_uri)
                
                self.getWifiObject(self.mq['wifi-config'])               
                back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri)
                self.model = models.normalizeModelName(model).lower()

            self.showNetworkPage()

        elif p == PAGE_NETWORK:
            self.security = 'None'
            self.mode = 'Infrastructure'
            self.ss = 0
            row = self.NetworksTableWidget.currentRow()
            if row != -1:
                i = self.NetworksTableWidget.item(row, 0)
                if i is not None:
                    self.network = to_unicode(i.text())
                    log.debug("Selected network SSID: %s" % self.network)
                    self.n, ok = value_int(i.data(Qt.UserRole))
                    if ok:
                        self.security = self.networks['encryptiontype-%d' % self.n]
                        log.debug("Security: %s" % self.security)

                        self.mode = self.networks['communicationmode-%d' % self.n]
                        log.debug("Mode: %s" % self.mode)

                        self.ss = self.networks['signalstrength-%d' % self.n]
                        log.debug("Signal strength: %s" % self.ss)

            if self.security.lower() != 'none':
                self.showConfigWifiPage()
            else:
                # Skip config page if no security to setup
                self.associate()
                self.showAssociateProgressDialog()
                self.showExitPage()

        elif p == PAGE_CONFIGURE_WIFI:
            key = to_unicode(self.KeyLineEdit.text())
            self.associate(key)
            self.showAssociateProgressDialog()
            self.showExitPage()

        elif p == PAGE_EXIT:
            if self.dev is not None:
                self.dev.close()

            self.close()

        else:
            log.error("Invalid page!") # shouldn't happen!
예제 #2
0
    def NextButton_clicked(self):
        p = self.StackedWidget.currentIndex()
        if p == PAGE_INTRO:
            self.showDevicesPage()

        elif p == PAGE_DEVICES:
            row = self.DevicesTableWidget.currentRow()
            if row != -1:
                self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri
                self.mq = device.queryModelByURI(self.device_uri)
                
                self.getWifiObject(self.mq['wifi-config'])               
                back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri)
                self.model = models.normalizeModelName(model).lower()

            self.showNetworkPage()

        elif p == PAGE_NETWORK:
            self.security = 'None'
            self.mode = 'Infrastructure'
            self.ss = 0
            row = self.NetworksTableWidget.currentRow()
            if row != -1:
                i = self.NetworksTableWidget.item(row, 0)
                if i is not None:
                    self.network = to_unicode(i.text())
                    log.debug("Selected network SSID: %s" % self.network)
                    self.n, ok = value_int(i.data(Qt.UserRole))
                    if ok:
                        self.security = self.networks['encryptiontype-%d' % self.n]
                        log.debug("Security: %s" % self.security)

                        self.mode = self.networks['communicationmode-%d' % self.n]
                        log.debug("Mode: %s" % self.mode)

                        self.ss = self.networks['signalstrength-%d' % self.n]
                        log.debug("Signal strength: %s" % self.ss)

            if self.security.lower() != 'none':
                self.showConfigWifiPage()
            else:
                # Skip config page if no security to setup
                self.associate()
                self.showAssociateProgressDialog()
                self.showExitPage()

        elif p == PAGE_CONFIGURE_WIFI:
            key = to_unicode(self.KeyLineEdit.text())
            self.associate(key)
            self.showAssociateProgressDialog()
            self.showExitPage()

        elif p == PAGE_EXIT:
            if self.dev is not None:
                self.dev.close()

            self.close()

        else:
            log.error("Invalid page!") # shouldn't happen!
예제 #3
0
    def setupFax(self):
        QApplication.setOverrideCursor(QApplication.waitCursor)
        back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
                device.parseDeviceURI(self.device_uri)
        norm_model = models.normalizeModelName(model).lower()
        fax_ppd,fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, norm_model)
        # Fax ppd not found
        if not fax_ppd:
            QApplication.restoreOverrideCursor()
            log.error("Fax PPD file not found.")

            if QMessageBox.warning(self, self.__tr("Unable to find HP fax PPD file."),
                self.__tr("The PPD file (%1.ppd) needed to setup the fax queue was not found.").arg(fax_ppd_name),
                self.__tr("Browse to file..."), # button 0
                self.__tr("Quit") # button 1
                ) == 0: # Browse

                while True:
                    ppd_dir = sys_conf.get('dirs', 'ppd')
                    fax_ppd = unicode(QFileDialog.getOpenFileName(ppd_dir,
                        "HP Fax PPD Files (*.ppd *.ppd.gz);;All Files (*)", self,
                        "open file dialog", "Choose the fax PPD file"))

                    if not fax_ppd: # user hit cancel
                        return

                    if os.path.exists(fax_ppd):
                        n = cups.getPPDDescription(fax_ppd)
                        if n == nick:
                            break
                        else:
                            self.FailureUI(self.__tr("<b>Incorrect fax PPD file.</b><p>The fax PPD file must have a nickname of '%1', not '%1'.").arg(nick).arg(n))
                    else:
                        self.FailureUI(self.__tr("<b>File not found.</b><p>hp-setup cannot find the file %1").arg(fax_ppd))

            else: # Quit
                return

        cups.setPasswordPrompt("You do not have permission to add a fax device.")
        if not os.path.exists(fax_ppd):
            status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                self.fax_uri, self.fax_location, '', fax_ppd,  self.fax_desc)
        else:
            status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                self.fax_uri, self.fax_location, fax_ppd, '', self.fax_desc)

        log.debug("addPrinter() returned (%d, %s)" % (status, status_str))
        self.installed_fax_devices = device.getSupportedCUPSDevices(['hpfax'])

        log.debug(self.installed_fax_devices)

        if self.fax_uri not in self.installed_fax_devices or \
            self.fax_name not in self.installed_fax_devices[self.fax_uri]:

            self.FailureUI(self.__tr("<b>Fax queue setup failed.</b><p>Please restart CUPS and try again."))
        else:
            # sending Event to add this device in hp-systray
            utils.sendEvent(EVENT_CUPS_QUEUES_CHANGED,self.fax_uri, self.fax_name)

        QApplication.restoreOverrideCursor()
예제 #4
0
    def setupFax(self):
        status = cups.IPP_BAD_REQUEST
        QApplication.setOverrideCursor(QApplication.waitCursor)
        back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
                device.parseDeviceURI(self.device_uri)
        norm_model = models.normalizeModelName(model).lower()
        fax_ppd,fax_ppd_name, nick = cups.getFaxPPDFile(self.mq, norm_model)
        # Fax ppd not found
        if not fax_ppd:
            QApplication.restoreOverrideCursor()
            log.error("Fax PPD file not found.")

            if QMessageBox.warning(self, self.__tr("Unable to find HP fax PPD file."),
                self.__tr("The PPD file (%1.ppd) needed to setup the fax queue was not found.").arg(fax_ppd_name),
                self.__tr("Browse to file..."), # button 0
                self.__tr("Quit") # button 1
                ) == 0: # Browse

                while True:
                    ppd_dir = sys_conf.get('dirs', 'ppd')
                    fax_ppd = to_unicode(QFileDialog.getOpenFileName(ppd_dir,
                        "HP Fax PPD Files (*.ppd *.ppd.gz);;All Files (*)", self,
                        "open file dialog", "Choose the fax PPD file"))

                    if not fax_ppd: # user hit cancel
                        return

                    if os.path.exists(fax_ppd):
                        n = cups.getPPDDescription(fax_ppd)
                        if n == nick:
                            break
                        else:
                            self.FailureUI(self.__tr("<b>Incorrect fax PPD file.</b><p>The fax PPD file must have a nickname of '%1', not '%1'.").arg(nick).arg(n))
                    else:
                        self.FailureUI(self.__tr("<b>File not found.</b><p>hp-setup cannot find the file %1").arg(fax_ppd))

            else: # Quit
                return

        if not os.path.exists(fax_ppd):
            status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                self.fax_uri, self.fax_location, '', fax_ppd,  self.fax_desc)
        else:
            status, status_str = cups.addPrinter(self.fax_name.encode('utf8'),
                self.fax_uri, self.fax_location, fax_ppd, '', self.fax_desc)

        log.debug("addPrinter() returned (%d, %s)" % (status, status_str))
        log.debug(device.getSupportedCUPSDevices(['hpfax']))

        if status != cups.IPP_OK:
            self.FailureUI(self.__tr("<b>Fax queue setup failed.</b><p>Error : %s "%status_str))
        else:
            # sending Event to add this device in hp-systray
            utils.sendEvent(EVENT_CUPS_QUEUES_ADDED,self.fax_uri, self.fax_name)

        QApplication.restoreOverrideCursor()
        return status
예제 #5
0
 def __init__(self, model=''):
     self.history = utils.RingBuffer(prop.history_size) # circular buffer of device.Event
     self.model = models.normalizeModelName(model)
     self.cache = {} # variable name : value
     self.faxes = {} # (username, jobid): FaxEvent
     self.dq = {} # last device query results
     #self.backoff = False
     self.backoff_counter = 0  # polling backoff: 0 = none, x = backed off by x intervals
     self.backoff_countdown = 0
     self.polling = False # indicates whether its in the device polling list
예제 #6
0
파일: hpssd.py 프로젝트: super11/hplip
 def __init__(self, model=''):
     self.history = utils.RingBuffer(prop.history_size) # circular buffer of device.Event
     self.model = models.normalizeModelName(model)
     self.cache = {} # variable name : value
     self.faxes = {} # (username, jobid): FaxEvent
     self.dq = {} # last device query results
     #self.backoff = False
     self.backoff_counter = 0  # polling backoff: 0 = none, x = backed off by x intervals
     self.backoff_countdown = 0
     self.polling = False # indicates whether its in the device polling list
예제 #7
0
    def updatePPDPage(self, ppds=None):
        QApplication.setOverrideCursor(QApplication.waitCursor)
        try:
            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(
                self.device_uri)
        except Error:
            self.FailureUI(
                self.__tr(
                    "<b>Device not found or invalid HPLIP device.</b><p>If you specified a USB ID, IP address, or other parameter, please re-check it and try again."
                ))
            self.close()
            sys.exit()

        if ppds is None or not ppds:
            ppds = cups.getSystemPPDs()

        #print ppds

        default_model = utils.xstrip(
            model.replace('series', '').replace('Series', ''), '_')
        stripped_model = cups.stripModel2(
            models.normalizeModelName(model).lower())

        #Check if common ppd name is already given in models.dat(This is needed because in case of devices having more than one derivatives
        #will have diffrent model name strings in device ID, because of which we don't get the common ppd name for search)

        ppd_name = self.mq.get('ppd-name', 0)

        if ppd_name == 0:
            self.ppd = cups.getPPDFile2(stripped_model, ppds)
        else:
            self.ppd = cups.getPPDFile2(ppd_name, ppds)

        log.debug(self.ppd)
        self.ppdListView.clear()

        if self.ppd is not None:
            #for ppd in self.ppd_dict:
            PPDListViewItem(self.ppdListView, self.ppd[0], self.ppd[1])

            #            i = self.ppdListView.firstChild()
            #            self.ppdListView.setCurrentItem(i)
            #            self.ppdListView.setSelected(i, True)
            #            self.ppd_file = self.ppdListView.currentItem().ppd_file
            self.ppd_file = self.ppd[0]
            log.debug(self.ppd_file)

        else:
            self.FailureUI(
                self.__tr(
                    '<b>PPD not file found.</b><p>An appropriate PPD file could not be found. Please check your HPLIP install, use <i>Select Other...</i>, or download one from linuxprinting.org.'
                ))

        QApplication.restoreOverrideCursor()
예제 #8
0
    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!
예제 #9
0
    def updatePPDPage(self, ppds=None):
        QApplication.setOverrideCursor(QApplication.waitCursor)
        try:
            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = device.parseDeviceURI(self.device_uri)
        except Error:
            self.FailureUI(self.__tr("<b>Device not found or invalid HPLIP device.</b><p>If you specified a USB ID, IP address, or other parameter, please re-check it and try again."))
            self.close()
            sys.exit()

        if ppds is None or not ppds:
            ppds = cups.getSystemPPDs()

        #print ppds

        default_model = utils.xstrip(model.replace('series', '').replace('Series', ''), '_')
        stripped_model = cups.stripModel2(models.normalizeModelName(model).lower())
        
        
        #Check if common ppd name is already given in models.dat(This is needed because in case of devices having more than one derivatives
        #will have diffrent model name strings in device ID, because of which we don't get the common ppd name for search)
       
        ppd_name = self.mq.get('ppd-name',0)
        
        if ppd_name == 0:
        	self.ppd = cups.getPPDFile2(stripped_model, ppds)
        else:
            self.ppd = cups.getPPDFile2(ppd_name, ppds)
        
        log.debug(self.ppd)
        self.ppdListView.clear()

        if self.ppd is not None:
            #for ppd in self.ppd_dict:
            PPDListViewItem(self.ppdListView, self.ppd[0], self.ppd[1])

#            i = self.ppdListView.firstChild()
#            self.ppdListView.setCurrentItem(i)
#            self.ppdListView.setSelected(i, True)
#            self.ppd_file = self.ppdListView.currentItem().ppd_file
            self.ppd_file = self.ppd[0]
            log.debug(self.ppd_file)

        else:
            self.FailureUI(self.__tr('<b>PPD not file found.</b><p>An appropriate PPD file could not be found. Please check your HPLIP install, use <i>Select Other...</i>, or download one from linuxprinting.org.'))

        QApplication.restoreOverrideCursor()
예제 #10
0
            device.parseDeviceURI(device_uri)

        log.debug("Model=%s" % model)
        mq = device.queryModelByURI(device_uri)

        if not mq or mq.get('support-type', SUPPORT_TYPE_NONE) == SUPPORT_TYPE_NONE:
            log.error("Unsupported printer model.")
            clean_exit(1)

        if mq.get('fax-type', FAX_TYPE_NONE) in (FAX_TYPE_NONE, FAX_TYPE_NOT_SUPPORTED) and setup_fax:
            #log.warning("Cannot setup fax - device does not have fax feature.")
            setup_fax = False

        # ******************************* PLUGIN

        norm_model = models.normalizeModelName(model).lower()
        plugin = mq.get('plugin', PLUGIN_NONE)

        if ignore_plugin_check is False and plugin > PLUGIN_NONE:
            from installer import pluginhandler
            pluginObj = pluginhandler.PluginHandle() 
            plugin_sts = pluginObj.getStatus()
            if plugin_sts != pluginhandler.PLUGIN_INSTALLED:
                if plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH:
                    tui.header("UPDATING PLUGIN")
                else:
                    tui.header("PLUG-IN INSTALLATION")

                hp_plugin = utils.which('hp-plugin')
                if hp_plugin:
                    cmd = "hp-plugin -i"
예제 #11
0
    def showPage(self, page):
        orig_page = page

        if self.first_page:
            page = self.start_page
            self.first_page = False

        log.debug("%s %s %s" % ("*"*20, "showPage(%s)" % page.name(), "*"*20))

        try:
            log.debug("%s --> %s" % (self.prev_page.name(), page.name()))
        except AttributeError:
            log.debug("--> %s" % page.name())

        if page is self.ConnectionPage: # start --> ConnectionPage
            pass

        elif page is self.ProbedDevicesPage:
            # ConnectionPage --> ProbedDevicesPage/EnterIPPage/DeviceNotFoundPage
            devices_found = self.updateProbedDevicesPage()


        elif page is self.PPDPage: # ProbedDevicesPage --> PPDPage
            if self.param:
                device_uri, sane_uri, fax_uri = device.makeURI(self.param, self.jd_port)

                if device_uri:
                    self.device_uri = device_uri

            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
                device.parseDeviceURI(self.device_uri)

            self.bus = bus
            self.mq = device.queryModelByURI(self.device_uri)

            norm_model = models.normalizeModelName(model).lower()

            core = core_install.CoreInstall()
            core.set_plugin_version()
            plugin = self.mq.get('plugin', PLUGIN_NONE)
            plugin_reason = self.mq.get('plugin-reason', PLUGIN_REASON_NONE)
            if plugin > PLUGIN_NONE and not core.check_for_plugin():
                ok, sudo_ok = pkit.run_plugin_command(plugin == PLUGIN_REQUIRED, plugin_reason)
                if not sudo_ok:
                    self.FailureUI(self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"))
                    return
                if not ok or not core.check_for_plugin():
                    if plugin == PLUGIN_REQUIRED:
                        self.FailureUI(self.__tr("<b>The printer you are trying to setup requires a binary driver plug-in and it failed to install.</b><p>Please check your internet connection and try again.</p><p>Visit <u>http://hplipopensource.com</u> for more information.</p>"))
                        return
                    else:
                        self.WarningUI(self.__tr("Either you have chosen to skip the installation of the optional plug-in or that installation has failed.  Your printer may not function at optimal performance."))

            self.updatePPDPage()

        elif page is self.PrinterNamePage:
            self.setDefaultPrinterName()

            if fax_import_ok and prop.fax_build and \
                self.mq.get('fax-type', FAX_TYPE_NONE) not in (FAX_TYPE_NONE, FAX_TYPE_NOT_SUPPORTED):

                self.faxCheckBox.setEnabled(True)
                self.faxCheckBox.setEnabled(True)
                self.faxNameLineEdit.setEnabled(True)
                self.faxNumberLineEdit.setEnabled(True)
                self.faxNameCoLineEdit.setEnabled(True)
                self.faxLocationLineEdit.setEnabled(True)
                self.faxDescriptionLineEdit.setEnabled(True)
                self.faxInfoGroupBox.setEnabled(True)
                self.setup_fax = True
                self.setDefaultFaxName()
                self.readwriteFaxInformation(True)

            else:
                self.setup_fax = False
                self.fax_name_ok = True
                self.defaultFaxNamePushButton.setEnabled(False)
                self.faxCheckBox.setEnabled(False)
                self.faxNameLineEdit.setEnabled(False)
                self.faxNumberLineEdit.setEnabled(False)
                self.faxNameCoLineEdit.setEnabled(False)
                self.faxLocationLineEdit.setEnabled(False)
                self.faxDescriptionLineEdit.setEnabled(False)
                self.faxInfoGroupBox.setEnabled(False)

        elif page is self.FinishedPage:
            self.lineEdit1.setText(self.printer_name)
            self.lineEdit2.setText(self.location)
            self.lineEdit3.setText(self.desc)
            self.lineEdit4.setText(self.ppd_file)

            #log.debug("Restarting CUPS...")
            #status, output = utils.run(restart_cups())
            #log.debug("Restart CUPS returned: exit=%d output=%s" % (status, output))

            self.setupPrinter()

            if self.setup_fax:
                self.setupFax()
                self.readwriteFaxInformation(False)

                self.lineEdit5.setText(self.fax_number)
                self.lineEdit6.setText(self.fax_name)
                self.lineEdit7.setText(self.fax_name_company)
                self.lineEdit8.setText(self.fax_location)
                self.lineEdit9.setText(self.fax_desc)

                self.faxGroupBox.setEnabled(True)

            else:
                self.faxGroupBox.setEnabled(False)

            self.setFinishEnabled(self.FinishedPage, True)

        if orig_page != page:
            try:
                log.debug("%s --> %s" % (self.prev_page.name(), page.name()))
            except AttributeError:
                log.debug("--> %s" % page.name())

        self.prev_page = page
        QWizard.showPage(self, page)

        if page is self.ProbedDevicesPage: # ConnectionPage --> ProbedDevicesPage/EnterIPPage/DeviceNotFoundPage
            if not devices_found:
                self.FailureUI(self.__tr("<b>No devices found.</b><p>Please make sure your printer is properly connected and powered-on."))
예제 #12
0
def getPPDFile2(mq, model, ppds):  # New PPD find
    # This routine is for the new PPD naming scheme begun in 2.8.10
    # and beginning with implementation in 2.8.12 (Qt4 hp-setup)
    # hp-<model name from models.dat w/o beginning hp_>[-<pdl>][-<pdl>][...].ppd[.gz]
    # 3.9.6: Added handling for hpijs vs. hpcups PPDs/DRVs

    #Check if common ppd name is already given in models.dat(This is needed because in case of devices having more than one derivatives
    #will have diffrent model name strings in device ID, because of which we don't get the common ppd name for search)
    family_check = isfamilydrv(ppds)
    family_class = getFamilyClassName(model)
    model = models.normalizeModelName(model)
    if family_check == 0:
        ppd_name = mq.get('ppd-name', 0)
    else:
        ppd_name = mq.get('family-ppd', 0)

    if ppd_name == 0:
        stripped_model = stripModel2(model)
    else:
        stripped_model = stripModel2(ppd_name)

    log.debug("Matching PPD list to model  %s..." % stripped_model)

    matches = []
    if family_check == 0:
        for f in ppds:
            match = ppd_pat.match(f)
            if match is not None:
                if match.group(1) == stripped_model:
                    log.debug("Found match: %s" % f)
                    try:
                        pdls = match.group(2).split('-')
                    except AttributeError:
                        pdls = []
                    if (prop.hpcups_build and 'hpijs' not in f) or \
                        ((prop.hpijs_build and 'hpijs' in pdls) or (prop.hpcups_build and 'hpijs' not in pdls)) or \
                         ('ps' in pdls) or ('pdf' in pdls):
                        matches.append(
                            (f, [p for p in pdls if p and p != 'hpijs']))
    else:
        for f in ppds:
            match = ppd_pat1.match(f)
            if match is not None:
                if match.group(1) == family_class:
                    log.debug("Found match: %s" % f)
                    try:
                        pdls = match.group(2).split('-')
                    except AttributeError:
                        pdls = []
                    if (prop.hpcups_build and 'hpijs' not in f) or \
                        ((prop.hpijs_build and 'hpijs' in pdls) or (prop.hpcups_build and 'hpijs' not in pdls)) or \
                         ('ps' in pdls) or ('pdf' in pdls):
                        matches.append(
                            (f, [p for p in pdls if p and p != 'hpijs']))
    log.debug(matches)
    num_matches = len(matches)

    if num_matches == 0:
        log.debug(
            "No PPD found for model %s using new algorithm. Trying old algorithm..."
            % stripped_model)
        #Using Old algo, ignores the series keyword in ppd searching.
        matches2 = list(getPPDFile(stripModel(stripped_model), ppds).items())
        log.debug(matches2)
        num_matches2 = len(matches2)
        if num_matches2:
            for f, d in matches2:
                match = ppd_pat.match(f)
                if match is not None:
                    log.debug("Found match: %s" % f)
                    try:
                        pdls = match.group(2).split('-')
                    except AttributeError:
                        pdls = []

                    if (prop.hpcups_build and 'hpijs' not in f) or \
                       ((prop.hpijs_build and 'hpijs' in pdls) or (prop.hpcups_build and 'hpijs' not in pdls)) or \
                       ('ps' in pdls) or ('pdf' in pdls):
                        matches.append(
                            (f, [p for p in pdls if p and p != 'hpijs']))

        log.debug(matches)
        num_matches = len(matches)

    if num_matches == 0:
        log.error("No PPD found for model %s using old algorithm." %
                  stripModel(stripped_model))
        return None

    elif num_matches == 1:
        log.debug("One match found.")
        return (matches[0][0], '')

    # > 1
    log.debug(
        "%d matches found. Searching based on PDL: Host > PS,PDF > PCL/Other" %
        num_matches)
    for p in [
            models.PDL_TYPE_HOST, models.PDL_TYPE_PS, models.PDL_TYPE_PDF,
            models.PDL_TYPE_PCL
    ]:
        for f, pdl_list in matches:
            for x in pdl_list:
                # default to HOST-based PDLs, as newly supported PDLs will most likely be of this type
                if models.PDL_TYPES.get(x, models.PDL_TYPE_HOST) == p:
                    log.debug("Selecting '-%s' PPD: %s" % (x, f))
                    return (f, '')

    log.debug("%d matches found. Searching based on Filters: HPCUPS > HPIJS" %
              num_matches)
    for p in ["hpcups", "hpijs"]:
        for f, pdl_list in matches:
            if p in f:
                log.debug("Selecting PPD: %s" % (f))
                return (f, '')

    # No specific PDL or Filter found, so just return 1st found PPD file
    log.debug("No specific PDL located. Defaulting to first found PPD file.")
    return (matches[0][0], '')
예제 #13
0
파일: cups.py 프로젝트: incrazyboyy/RPiTC-X
def getPPDFile2(mq,model, ppds): # New PPD find
    # This routine is for the new PPD naming scheme begun in 2.8.10
    # and beginning with implementation in 2.8.12 (Qt4 hp-setup)
    # hp-<model name from models.dat w/o beginning hp_>[-<pdl>][-<pdl>][...].ppd[.gz]
    # 3.9.6: Added handling for hpijs vs. hpcups PPDs/DRVs


    #Check if common ppd name is already given in models.dat(This is needed because in case of devices having more than one derivatives
    #will have diffrent model name strings in device ID, because of which we don't get the common ppd name for search)
    model = models.normalizeModelName(model)
    ppd_name = mq.get('ppd-name',0)
    if ppd_name == 0:
        stripped_model = stripModel2(model)
    else:
        stripped_model = stripModel2(ppd_name)

    log.debug("Matching PPD list to model  %s..." % stripped_model)

    matches = []
    for f in ppds:
        match = ppd_pat.match(f)
        if match is not None:
            if match.group(1) == stripped_model:
                log.debug("Found match: %s" % f)
                try:
                    pdls = match.group(2).split('-')
                except AttributeError:
                    pdls = []

                if (prop.hpcups_build and 'hpijs' not in f) or \
                    ((prop.hpijs_build and 'hpijs' in pdls) or (prop.hpcups_build and 'hpijs' not in pdls)) or \
                    ('ps' in pdls):
                    matches.append((f, [p for p in pdls if p and p != 'hpijs']))

    log.debug(matches)
    num_matches = len(matches)

    if num_matches == 0:
        log.debug("No PPD found for model %s using new algorithm. Trying old algorithm..." % stripped_model)
        #Using Old algo, ignores the series keyword in ppd searching.
        matches2 = getPPDFile(stripModel(stripped_model), ppds).items()
        log.debug(matches2)
        num_matches2 = len(matches2)
        if num_matches2:
            for f, d in matches2:
                match = ppd_pat.match(f)
                if match is not None:
                    log.debug("Found match: %s" % f)
                    try:
                        pdls = match.group(2).split('-')
                    except AttributeError:
                        pdls = []

                    if (prop.hpcups_build and 'hpijs' not in f) or \
                       ((prop.hpijs_build and 'hpijs' in pdls) or (prop.hpcups_build and 'hpijs' not in pdls)) or \
                       ('ps' in pdls):
                        matches.append((f, [p for p in pdls if p and p != 'hpijs']))

        log.debug(matches)
        num_matches = len(matches)

    if num_matches == 0:
        log.error("No PPD found for model %s using old algorithm." % stripModel(stripped_model))
        return None

    elif num_matches == 1:
        log.debug("One match found.")
        return (matches[0][0], '')

    # > 1
    log.debug("%d matches found. Searching based on PDL: Host > PS > PCL/Other" % num_matches)
    for p in [models.PDL_TYPE_HOST, models.PDL_TYPE_PS, models.PDL_TYPE_PCL]:
        for f, pdl_list in matches:
            for x in pdl_list:
                # default to HOST-based PDLs, as newly supported PDLs will most likely be of this type
                if models.PDL_TYPES.get(x, models.PDL_TYPE_HOST) == p:
                    log.debug("Selecting '-%s' PPD: %s" % (x, f))
                    return (f, '')

    log.debug("%d matches found. Searching based on Filters: HPCUPS > HPIJS" % num_matches)
    for p in ["hpcups","hpijs"]:
        for f, pdl_list in matches:
            if p in f:
                log.debug("Selecting PPD: %s" % (f))
                return (f, '')

    # No specific PDL or Filter found, so just return 1st found PPD file
    log.debug("No specific PDL located. Defaulting to first found PPD file.")
    return (matches[0][0], '')
예제 #14
0
    def showPage(self, page):
        orig_page = page

        if self.first_page:
            page = self.start_page
            self.first_page = False

        log.debug("%s %s %s" % ("*"*20, "showPage(%s)" % page.name(), "*"*20))

        try:
            log.debug("%s --> %s" % (self.prev_page.name(), page.name()))
        except AttributeError:
            log.debug("--> %s" % page.name())

        if page is self.ConnectionPage: # start --> ConnectionPage
            pass

        elif page is self.ProbedDevicesPage:
            # ConnectionPage --> ProbedDevicesPage/EnterIPPage/DeviceNotFoundPage
            devices_found = self.updateProbedDevicesPage()


        elif page is self.PPDPage: # ProbedDevicesPage --> PPDPage
            if self.param:
                device_uri, sane_uri, fax_uri = device.makeURI(self.param, self.jd_port)

                if device_uri:
                    self.device_uri = device_uri

            back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \
                device.parseDeviceURI(self.device_uri)

            self.bus = bus
            self.mq = device.queryModelByURI(self.device_uri)

            norm_model = models.normalizeModelName(model).lower()

            core = core_install.CoreInstall(core_install.MODE_CHECK)
            core.set_plugin_version()
            plugin = self.mq.get('plugin', PLUGIN_NONE)
            plugin_reason = self.mq.get('plugin-reason', PLUGIN_REASON_NONE)
            if plugin > PLUGIN_NONE and core.check_for_plugin() != PLUGIN_INSTALLED:
                ok, sudo_ok = pkit.run_plugin_command(plugin == PLUGIN_REQUIRED, plugin_reason)
                if not sudo_ok:
                    self.FailureUI(self.__tr("<b>Unable to find an appropriate su/sudo utility to run hp-plugin.</b><p>Install kdesu, gnomesu, or gksu.</p>"))
                    return
                if not ok or core.check_for_plugin() != PLUGIN_INSTALLED:
                    if plugin == PLUGIN_REQUIRED:
                        self.FailureUI(self.__tr("<b>The printer you are trying to setup requires a binary driver plug-in and it failed to install.</b><p>Please check your internet connection and try again.</p><p>Visit <u>http://hplipopensource.com</u> for more information.</p>"))
                        return
                    else:
                        self.WarningUI(self.__tr("Either you have chosen to skip the installation of the optional plug-in or that installation has failed.  Your printer may not function at optimal performance."))

            self.updatePPDPage()

        elif page is self.PrinterNamePage:
            self.setDefaultPrinterName()

            if fax_import_ok and prop.fax_build and \
                self.mq.get('fax-type', FAX_TYPE_NONE) not in (FAX_TYPE_NONE, FAX_TYPE_NOT_SUPPORTED):

                self.faxCheckBox.setEnabled(True)
                self.faxCheckBox.setEnabled(True)
                self.faxNameLineEdit.setEnabled(True)
                self.faxNumberLineEdit.setEnabled(True)
                self.faxNameCoLineEdit.setEnabled(True)
                self.faxLocationLineEdit.setEnabled(True)
                self.faxDescriptionLineEdit.setEnabled(True)
                self.faxInfoGroupBox.setEnabled(True)
                self.setup_fax = True
                self.setDefaultFaxName()
                self.readwriteFaxInformation(True)

            else:
                self.setup_fax = False
                self.fax_name_ok = True
                self.defaultFaxNamePushButton.setEnabled(False)
                self.faxCheckBox.setEnabled(False)
                self.faxNameLineEdit.setEnabled(False)
                self.faxNumberLineEdit.setEnabled(False)
                self.faxNameCoLineEdit.setEnabled(False)
                self.faxLocationLineEdit.setEnabled(False)
                self.faxDescriptionLineEdit.setEnabled(False)
                self.faxInfoGroupBox.setEnabled(False)

        elif page is self.FinishedPage:
            self.lineEdit1.setText(self.printer_name)
            self.lineEdit2.setText(self.location)
            self.lineEdit3.setText(self.desc)
            self.lineEdit4.setText(self.ppd_file)

            #log.debug("Restarting CUPS...")
            #status, output = utils.run(restart_cups())
            #log.debug("Restart CUPS returned: exit=%d output=%s" % (status, output))

            self.setupPrinter()

            if self.setup_fax:
                self.setupFax()
                self.readwriteFaxInformation(False)

                self.lineEdit5.setText(self.fax_number)
                self.lineEdit6.setText(self.fax_name)
                self.lineEdit7.setText(self.fax_name_company)
                self.lineEdit8.setText(self.fax_location)
                self.lineEdit9.setText(self.fax_desc)

                self.faxGroupBox.setEnabled(True)

            else:
                self.faxGroupBox.setEnabled(False)

            self.setFinishEnabled(self.FinishedPage, True)

        if orig_page != page:
            try:
                log.debug("%s --> %s" % (self.prev_page.name(), page.name()))
            except AttributeError:
                log.debug("--> %s" % page.name())

        self.prev_page = page
        QWizard.showPage(self, page)

        if page is self.ProbedDevicesPage: # ConnectionPage --> ProbedDevicesPage/EnterIPPage/DeviceNotFoundPage
            if not devices_found:
                self.FailureUI(self.__tr("<b>No devices found.</b><p>Please make sure your printer is properly connected and powered-on."))
예제 #15
0
    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())
            self.fax_location = unicode(self.FaxLocationLineEdit.text())
            self.fax_name_company = unicode(self.NameCompanyLineEdit.text())
            self.fax_number = unicode(self.FaxNumberLineEdit.text())
            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')
                    uri = device.getDeviceURIByPrinterName(printer)
                    log.debug("Removing printer: %s" % printer)
                    status, status_str = cups.cups_operation(cups.delPrinter, GUI_MODE, 'qt4', self, printer)

                    if  status != cups.IPP_OK:
                        FailureUI(self, self.__tr("<b>Unable to delete '%s' queue. </b><p>Error : %s"%(printer,status_str)))
                        if status == cups.IPP_FORBIDDEN or status == cups.IPP_NOT_AUTHENTICATED or status == cups.IPP_NOT_AUTHORIZED:
                            break
                    else:
                        # sending Event to add this device in hp-systray
                        utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED, uri, printer)

            self.close()

        else:
            log.error("Invalid page!") # shouldn't happen!