Esempio n. 1
0
def disable(mode, ui_toolkit='qt4', dialog=None, app=None, passwordObj=None):

    dev_list = get_smartinstall_enabled_devices()
    if not dev_list:
        log.debug("No Smart Install Device found")
        return ERROR_NO_SI_DEVICE, queryString(ERROR_NO_SI_DEVICE)

    return_val = ERROR_FAILED_TO_DISABLE_SI
    return_error_str = queryString(ERROR_FAILED_TO_DISABLE_SI)
    url, file_name = get_SmartInstall_tool_info()
    printer_names = utils.list_to_string(dev_list)

    try:
        if mode == GUI_MODE:
            if ui_toolkit == 'qt3':
                try:
                    from ui.setupform import FailureMessageUI
                except ImportError:
                    log.error(
                        "Smart Install is enabled in %s device(s).\nAuto Smart Install disable is not supported in QT3.\nPlease refer link \'%s\' to disable manually"
                        % (printer_names, url))
                else:
                    FailureMessageUI(
                        "Smart Install is enabled in %s device(s).\n\nAuto Smart Install disable is not supported in QT3.\nPlease refer link \'%s\' to disable manually"
                        % (printer_names, url))

            else:  #qt4
                if not utils.canEnterGUIMode4():
                    log.error("%s requires GUI support . Is Qt4 installed?" %
                              __mod__)
                    return ERROR_FAILED_TO_DISABLE_SI, queryString(
                        ERROR_FAILED_TO_DISABLE_SI)

                if dialog and app:  # If QT app already opened, re-using same object
                    dialog.init(printer_names, "",
                                QUEUES_SMART_INSTALL_ENABLED)
                else:  # If QT object is not created, creating QT app
                    try:
                        from ui4.queuesconf import QueuesDiagnose
                    except ImportError:
                        log.error(
                            "Unable to load Qt4 support. Is it installed?")
                    else:  #  app = QApplication(sys.argv)   # caller needs to inoke this, if already QApplication object is not created.
                        dialog = QueuesDiagnose(None, printer_names, "",
                                                QUEUES_SMART_INSTALL_ENABLED)

                log.debug("Starting GUI loop...")
                dialog.exec_()

                if check_SmartInstall():
                    dialog.showMessage(
                        "Failed to disable smart install.\nPlease refer link \'%s\' for more information"
                        % url)
                else:
                    dialog.showSuccessMessage(
                        "Smart install disabled successfully.")

        #Interaction mode
        else:
            log.error("Smart Install is enabled in %s device(s). " %
                      printer_names)
            response, value = tui.enter_choice(
                "Do you want to download and disable smart install?(y=yes*, n=no):",
                ['y', 'n'], 'y')

            if not response or value != 'y':  #User exit
                return_val = ERROR_FAILED_TO_DISABLE_SI
                return_error_str = queryString(ERROR_FAILED_TO_DISABLE_SI)

            else:
                sts, smart_install_run, smart_install_asc, error_str = download(
                    mode, passwordObj)

                disable_si = False
                return_val = sts

                if sts == ERROR_SUCCESS:
                    disable_si = True

                elif sts in (ERROR_UNABLE_TO_RECV_KEYS,
                             ERROR_DIGITAL_SIGN_NOT_FOUND):
                    response, value = tui.enter_yes_no(
                        "Digital Sign verification failed, Do you want to continue?"
                    )
                    if not response or not value:
                        sys.exit(0)
                    else:  # Continue without validation succes.
                        disable_si = True
                else:
                    return_error_str = queryString(sts)

                if disable_si:
                    sts, out = utils.run("sh %s" % smart_install_run)

                    # Once smart install disabler installation completed, cross verifying to ensure no smart install devices found
                    if sts or check_SmartInstall():
                        log.error("Failed to disable smart install .")
                        log.error(
                            "Please refer link \'%s\' to disable manually" %
                            url)
                        return_val = ERROR_FAILED_TO_DISABLE_SI
                        return_error_str = queryString(
                            ERROR_FAILED_TO_DISABLE_SI)
                    else:
                        log.info("Smart install disabled successfully.")
                        return_val = ERROR_SUCCESS
                        return_error_str = ""

    except KeyboardInterrupt:
        log.error("User exit")
        sys.exit(0)

    return return_val, return_error_str
Esempio n. 2
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()
Esempio n. 3
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)
Esempio n. 4
0
def disable(mode, ui_toolkit='qt4', dialog=None, app=None, passwordObj = None):

    dev_list = get_smartinstall_enabled_devices()
    if not dev_list:
        log.debug("No Smart Install Device found")
        return ERROR_NO_SI_DEVICE, queryString(ERROR_NO_SI_DEVICE)

    return_val = ERROR_FAILED_TO_DISABLE_SI
    return_error_str = queryString(ERROR_FAILED_TO_DISABLE_SI)
    url, file_name = get_SmartInstall_tool_info()
    printer_names  = utils.list_to_string(dev_list)

    try:
        if mode == GUI_MODE:
            if ui_toolkit == 'qt3':
                try:
                    from ui.setupform import FailureMessageUI
                except ImportError:
                    log.error("Smart Install is enabled in %s device(s).\nAuto Smart Install disable is not supported in QT3.\nPlease refer link \'%s\' to disable manually"%(printer_names,url))
                else:
                    FailureMessageUI("Smart Install is enabled in %s device(s).\n\nAuto Smart Install disable is not supported in QT3.\nPlease refer link \'%s\' to disable manually"%(printer_names,url))

            else: #qt4
                if not utils.canEnterGUIMode4():
                    log.error("%s requires GUI support . Is Qt4 installed?" % __mod__)
                    return ERROR_FAILED_TO_DISABLE_SI, queryString(ERROR_FAILED_TO_DISABLE_SI)

                if dialog and app:  # If QT app already opened, re-using same object
                    dialog.init(printer_names, "", QUEUES_SMART_INSTALL_ENABLED)
                else:   # If QT object is not created, creating QT app
                    try:
                        from ui4.queuesconf import QueuesDiagnose
                    except ImportError:
                        log.error("Unable to load Qt4 support. Is it installed?")
                    else:       #  app = QApplication(sys.argv)   # caller needs to inoke this, if already QApplication object is not created.
                        dialog = QueuesDiagnose(None, printer_names ,"",QUEUES_SMART_INSTALL_ENABLED)

                log.debug("Starting GUI loop...")
                dialog.exec_()

                if check_SmartInstall():
                    dialog.showMessage("Failed to disable smart install.\nPlease refer link \'%s\' for more information" %url)
                else:
                    dialog.showSuccessMessage("Smart install disabled successfully.")


        #Interaction mode
        else: 
            log.error("Smart Install is enabled in %s device(s). "%printer_names)
            response, value = tui.enter_choice("Do you want to download and disable smart install?(y=yes*, n=no):",['y', 'n'], 'y')

            if not response or value != 'y':   #User exit
                return_val = ERROR_FAILED_TO_DISABLE_SI
                return_error_str = queryString(ERROR_FAILED_TO_DISABLE_SI)

            else:
                sts, smart_install_run, smart_install_asc, error_str = download(mode, passwordObj)

                disable_si = False
                return_val = sts

                if sts == ERROR_SUCCESS:
                    disable_si = True

                elif sts in (ERROR_UNABLE_TO_RECV_KEYS, ERROR_DIGITAL_SIGN_NOT_FOUND):
                    response, value = tui.enter_yes_no("Digital Sign verification failed, Do you want to continue?")
                    if not response or not value:
                        sys.exit(0)
                    else:   # Continue without validation succes.
                        disable_si = True
                else:
                    return_error_str = queryString(sts)

                if disable_si: 
                    sts, out = utils.run("sh %s"%smart_install_run)

                    # Once smart install disabler installation completed, cross verifying to ensure no smart install devices found
                    if sts or check_SmartInstall():
                        log.error("Failed to disable smart install .")
                        log.error("Please refer link \'%s\' to disable manually"%url)
                        return_val = ERROR_FAILED_TO_DISABLE_SI
                        return_error_str = queryString(ERROR_FAILED_TO_DISABLE_SI)
                    else:
                        log.info("Smart install disabled successfully.")
                        return_val = ERROR_SUCCESS
                        return_error_str = ""

    except KeyboardInterrupt:
        log.error("User exit")
        sys.exit(0)

    return return_val ,return_error_str
Esempio n. 5
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 . 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 . import password
        except ImportError:
            log.warn("Failed to import password object")
        else:
            cups.setPasswordCallback(password.showPasswordPrompt)

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

            for key,val in list(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.")
        else:
            log.warn("Could not complete Queue(s) configuration check")

        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,status = parseQueues(mode)
        if status:
            if list(mapofDevices.items()) == 0:
                log.debug("No queues found.")

            for key,val in list(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)
        else:
            log.warn("Could not complete Queue(s) configuration check")

        cups.releaseCupsInstance()
Esempio n. 6
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)
Esempio n. 7
0
        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)
    Error_Found = False
    if check_user_groups() is False:
        dialog = QueuesDiagnose(None, "","",QUEUES_MSG_SENDING)
        core = core_install.CoreInstall()
        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"%prop.username)
            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.")


    is_hpcups_installed = to_bool(sys_conf.get('configure', 'hpcups-install', '0'))
    is_hpijs_installed = to_bool(sys_conf.get('configure', 'hpijs-install', '0'))
#    tui.header("INSTALLED CUPS PRINTER QUEUES")

    
    status, output = utils.run('lpstat -v')

    cups_printers = []
    for p in output.splitlines():
        try:
            match = LPSTAT_PATTERN.search(p)