Ejemplo n.º 1
0
    def download(self, pluginPath='', callback=None):
        core = core_install.CoreInstall()

        if pluginPath:  #     and os.path.exists(pluginPath):
            src = pluginPath
            checksum = ""  # TBD: Local copy may have different checksum. So ignoring checksum
        else:
            sts, url, checksum = self.__getPluginInformation(callback)
            src = url
            if sts != ERROR_SUCCESS:
                return sts, "", queryString(ERROR_CHECKSUM_ERROR, 0, src)

        log.debug("Downloading %s plug-in file from '%s' to '%s'..." %
                  (self.__required_version, src, self.__plugin_path))
        plugin_file = os.path.join(self.__plugin_path, self.__plugin_name)
        try:
            os.umask(0)
            if not os.path.exists(self.__plugin_path):
                os.makedirs(self.__plugin_path, 0755)
            if os.path.exists(plugin_file):
                os.remove(plugin_file)
            if os.path.exists(plugin_file + '.asc'):
                os.remove(plugin_file + '.asc')

        except (OSError, IOError), e:
            log.error("Failed in OS operations:%s " % e.strerror)
            return ERROR_DIRECTORY_NOT_FOUND, "", self.__plugin_path + queryString(
                102)
Ejemplo n.º 2
0
def handle_plugin_install():

    child_process = os.fork()
    if child_process == 0:  # child process
        lockObj = utils.Sync_Lock("/tmp/pluginInstall.tmp")
        lockObj.acquire()
        child_pid = os.getpid()
        core = core_install.CoreInstall(core_install.MODE_CHECK)
        core.set_plugin_version()
        if core.check_for_plugin() != PLUGIN_INSTALLED:
            sts, out = utils.run('hp-diagnose_plugin', True, None, 1, False)
            if sts != 0:
                log.error("Failed to load hp-diagnose_plugin")
                #TBD FailureUI needs to add
        else:
            log.debug(
                "Device Plug-in was already installed. Not Invoking Plug-in installation wizard"
            )

        lockObj.release()
        os.kill(child_pid, signal.SIGKILL)
    else:  #parent process
        log.debug("Started Plug-in installation wizard")
Ejemplo n.º 3
0
    def download(self, pluginPath='', callback=None):

        core = core_install.CoreInstall()

        if pluginPath:  #     and os.path.exists(pluginPath):
            src = pluginPath
            checksum = ""  # TBD: Local copy may have different checksum. So ignoring checksum
        else:
            sts, url, checksum = self.__getPluginInformation(callback)
            src = url
            if sts != ERROR_SUCCESS:
                return sts, "", queryString(ERROR_CHECKSUM_ERROR, 0, src)

        log.debug("Downloading %s plug-in file from '%s' to '%s'..." %
                  (self.__required_version, src, self.__plugin_path))
        plugin_file = os.path.join(self.__plugin_path, self.__plugin_name)
        try:
            os.umask(0)
            if not os.path.exists(self.__plugin_path):
                os.makedirs(self.__plugin_path, 0o755)
            if os.path.exists(plugin_file):
                os.remove(plugin_file)
            if os.path.exists(plugin_file + '.asc'):
                os.remove(plugin_file + '.asc')

        except (OSError, IOError) as e:
            log.error("Failed in OS operations:%s " % e.strerror)
            return ERROR_DIRECTORY_NOT_FOUND, "", self.__plugin_path + queryString(
                102)

        try:
            if src.startswith('file://'):
                status, filename = utils.download_from_network(
                    src, plugin_file, True)
            else:
                wget = utils.which("wget", True)
                if wget:
                    cmd = "%s --cache=off -P %s %s" % (wget,
                                                       self.__plugin_path, src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)
                    log.debug("wget returned: %d" % status)

                #Check whether plugin is accessible in Openprinting.org website otherwise dowload plugin from alternate location.
                if status != 0 or os_utils.getFileSize(plugin_file) <= 0:
                    src = os.path.join(PLUGIN_FALLBACK_LOCATION,
                                       self.__plugin_name)
                    log.info(
                        "Plugin is not accessible. Trying to download it from fallback location: [%s]"
                        % src)
                    cmd = "%s --cache=off -P %s %s" % (wget,
                                                       self.__plugin_path, src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)

        except IOError as e:
            log.error("Plug-in download failed: %s" % e.strerror)
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if status != 0 or os_utils.getFileSize(plugin_file) <= 0:
            log.error("Plug-in download failed.")
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if core.isErrorPage(open(plugin_file, 'r').read(1024)):
            log.debug("open(plugin_file, 'r').read(1024)")
            os.remove(plugin_file)
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        # Try to download and check the GPG digital signature
        digsig_url = src + '.asc'
        digsig_file = plugin_file + '.asc'

        log.debug(
            "Downloading %s plug-in digital signature file from '%s' to '%s'..."
            % (self.__required_version, digsig_url, digsig_file))

        try:
            if digsig_url.startswith('file://'):
                status, filename = utils.download_from_network(
                    digsig_url, digsig_file, True)
            else:
                cmd = "%s --cache=off -P %s %s" % (wget, self.__plugin_path,
                                                   digsig_url)
                log.debug(cmd)
                status, output = utils.run(cmd)
        except IOError as e:
            log.error("Plug-in GPG file [%s] download failed: %s" %
                      (digsig_url, e.strerror))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if status != 0:
            log.error("Plug-in GPG file [%s] download failed." % (digsig_url))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if core.isErrorPage(open(digsig_file, 'r').read(1024)):
            log.debug(open(digsig_file, 'r').read())
            os.remove(digsig_file)
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        sts, error_str = self.__validatePlugin(plugin_file, digsig_file,
                                               checksum)
        return sts, plugin_file, error_str
Ejemplo n.º 4
0
    else:  #qt4
        if not utils.canEnterGUIMode4():
            log.error("%s requires GUI support . Is Qt4 installed?" % __mod__)
            sys.exit(1)

        try:
            from PyQt4.QtGui import QApplication, QMessageBox
            from ui4.plugindiagnose import PluginDiagnose
            from installer import core_install
        except ImportError:
            log.error("Unable to load Qt4 support. Is it installed?")
            sys.exit(1)

        app = QApplication(sys.argv)
        core = core_install.CoreInstall(core_install.MODE_CHECK)
        plugin_sts = core.check_for_plugin()
        if plugin_sts == PLUGIN_INSTALLED:
            log.info("Device Plugin is already installed")
            sys.exit(0)
        elif plugin_sts == PLUGIN_VERSION_MISMATCH:
            dialog = PluginDiagnose(None, install_mode, plugin_reason, True)
        else:
            dialog = PluginDiagnose(None, install_mode, plugin_reason)

        dialog.show()
        try:
            log.debug("Starting GUI loop...")
            app.exec_()
        except KeyboardInterrupt:
            log.error("User exit")
Ejemplo n.º 5
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."))
Ejemplo n.º 6
0
            log.error("User exit")
            sys.exit(0)

else:  # INTERACTIVE_MODE
    try:
        if not os.geteuid() == 0:
            log.error("You must be root to run this utility.")
            sys.exit(1)

        log.info(
            "(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)"
        )
        log.info("")

        from installer import core_install
        core = core_install.CoreInstall()

        core.set_plugin_version()

        tui.header("PLUG-IN INSTALLATION FOR HPLIP %s" % version)

        if core.check_for_plugin() and plugin_path is None:
            log.info(
                "The driver plugin for HPLIP %s appears to already be installed."
                % version)

            cont, ans = tui.enter_yes_no(
                "Do you wish to download and re-install the plug-in?")

            if not cont or not ans:
                sys.exit(0)
    def actionPushButton_clicked(self):
        core = core_install.CoreInstall()
        core.set_plugin_version()  #self.version)

        if self.path is None:  # download
            # read plugin.conf (local or on sf.net) to get plugin_path (http://)
            plugin_conf_url = core.get_plugin_conf_url()

            if plugin_conf_url.startswith('file://'):
                pass
            else:
                pass

                log.info("Checking for network connection...")
                ok = core.check_network_connection()

                if not ok:
                    log.error("Network connection not detected.")
                    self.FailureUI(
                        self.__tr("Network connection not detected."))
                    self.close()
                    return

            log.info("Downloading configuration file from: %s" %
                     plugin_conf_url)

            self.path, size, checksum, timestamp, ok = core.get_plugin_info(
                plugin_conf_url, self.plugin_download_callback)

            log.debug("path=%s, size=%d, checksum=%s, timestamp=%f, ok=%s" %
                      (self.path, size, checksum, timestamp, ok))

            if not self.path.startswith(
                    'http://') and not self.path.startswith('file://'):
                self.path = 'file://' + self.path

        else:  # path
            if not self.path.startswith('http://'):
                self.path = 'file://' + self.path

            size, checksum, timestamp = 0, '', 0

        if self.path.startswith('file://'):
            pass
        else:

            log.info("Checking for network connection...")
            ok = core.check_network_connection()

            if not ok:
                log.error("Network connection not detected.")
                self.FailureUI(self.__tr("Network connection not detected."))
                self.close()
                return

        log.info("Downloading plug-in from: %s" % self.path)

        status, ret = core.download_plugin(self.path, size, checksum,
                                           timestamp,
                                           self.plugin_download_callback)

        if status != PLUGIN_INSTALL_ERROR_NONE:

            if status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND:
                desc = self.__tr(
                    "<b>ERROR: Plug-in file not found (server returned 404 or similar error).</b><p>Error code: %1</p>"
                ).arg(str(ret))

            elif status == PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND:
                desc = self.__tr(
                    "<b>ERROR: Plug-in digital signature file not found (server returned 404 or similar error).</b><p>Error code: %1</p>"
                ).arg(str(ret))

            elif status == PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD:
                desc = self.__tr(
                    "<b>ERROR: Plug-in file does not match its digital signature.</b><p>File may have been corrupted or altered.</p><p>Error code: %1</p>"
                ).arg(str(ret))

            elif status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR:
                desc = self.__tr(
                    "<b>ERROR: Plug-in file does not match its checksum. File may have been corrupted or altered."
                )

            elif status == PLUGIN_INSTALL_ERROR_NO_NETWORK:
                desc = self.__tr(
                    "<b>ERROR: Unable to connect to network to download the plug-in.</b><p>Please check your network connection and try again.</p>"
                )

            elif status == PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR:
                desc = self.__tr(
                    "<b>ERROR: Unable to create the plug-in directory.</b><p>Please check your permissions and try again.</p>"
                )

            elif status == PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS:
                desc = self.__tr(
                    "<b>ERROR: Unable to download the public HPLIP keys from the keyserver.</b><p>Error code: %1</p>"
                ).arg(str(ret))

            core.delete_plugin()
            self.FailureUI(desc)
            self.close()
            return

        local_plugin = ret

        if not core.run_plugin(GUI_MODE, self.plugin_install_callback):
            core.delete_plugin()
            self.FailureUI(self.__tr("Plug-in install failed."))
            self.close()
            return

        cups_devices = device.getSupportedCUPSDevices(['hp'])  #, 'hpfax'])

        for dev in cups_devices:
            mq = device.queryModelByURI(dev)

            if mq.get('fw-download', False):

                # Download firmware if needed
                log.info(
                    log.bold("\nDownloading firmware to device %s..." % dev))
                try:
                    d = device.Device(dev)
                except Error:
                    log.error("Error opening device.")
                    continue

                if d.downloadFirmware():
                    log.info("Firmware download successful.\n")

                d.close()

        core.delete_plugin()
        self.SuccessUI("Plug-in install successful.")
        self.close()
Ejemplo n.º 8
0
def main_function(mode=GUI_MODE,
                  ui_toolkit=UI_TOOLKIT_QT4,
                  quiet_mode=False,
                  check_grps=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:
        if check_grps and check_user_groups() is False:
            core = core_install.CoreInstall(core_install.MODE_CHECK)
            core.init()
            if add_group(core) is False:
                Error_Found = True
                log.error(
                    "Failed to add lp group to user[%s]. Manually add 'lp' group to usergroups. And reboot system."
                    % prop.username)
            else:
                log.info(
                    "Groups added successfully and reboot is required. Please reboot system to take effect."
                )
        mapofDevices = parseQueues()
        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)

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

    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
        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)
        if check_grps and check_user_groups() is False:
            core = core_install.CoreInstall(core_install.MODE_CHECK)
            core.init()
            if add_group(core) is False:
                Error_Found = True
                dialog.showMessage(
                    "User must be part of 'lp' group.\nManually add 'lp' group to '%s' user. "
                    % prop.username)
            else:
                dialog.showSuccessMessage(
                    "Groups added successfully and reboot is required. Please reboot system to take effect."
                )

        mapofDevices = parseQueues()
        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)

        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)