def clean_exit(code = 0): cups.releaseCupsInstance() sys.exit(code)
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) QApplication, ui_package = utils.import_dialog(ui_toolkit) ui = import_module(ui_package + ".queuesconf") setupdialog = import_module(ui_package + ".setupdialog") app = QApplication(sys.argv) dialog = ui.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()
try: locale.setlocale(locale.LC_ALL, locale.normalize(loc)) except locale.Error: pass try: w = setupform.SetupForm(bus, param, jd_port) except Error: log.error("Unable to connect to HPLIP I/O. Please (re)start HPLIP and try again.") clean_exit(1) app.setMainWidget(w) w.show() app.exec_loop() cups.releaseCupsInstance() else: # qt4 # if utils.ui_status[1] == "PyQt4": # try: # from PyQt4.QtGui import QApplication, QMessageBox # from ui4.setupdialog import SetupDialog # except ImportError as e: # log.error(e) # clean_exit(1) # elif utils.ui_status[1] == "PyQt5": # try: # from PyQt5.QtWidgets import QApplication, QMessageBox # from ui5.setupdialog import SetupDialog # except ImportError as e: # log.error(e)
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()