def display_summary(self): tui.header("SUMMARY") log.info(log.bold("Missing Required Dependencies")) log.info(log.bold('-'*len("Missing Required Dependencies"))) if len(self.req_deps_to_be_installed) == 0: log.info("None") else: for packages_to_install in self.req_deps_to_be_installed: if packages_to_install == 'cups': log.error("'%s' package is missing or '%s' service is not running."%(packages_to_install,packages_to_install)) else: log.error("'%s' package is missing/incompatible "%packages_to_install) log.info("") log.info(log.bold("Missing Optional Dependencies")) log.info(log.bold('-'*len("Missing Optional Dependencies"))) if len(self.opt_deps_to_be_installed) == 0: log.info("None\n") else: for packages_to_install in self.opt_deps_to_be_installed: log.error("'%s' package is missing/incompatible "%packages_to_install) if self.plugin_status == PLUGIN_NOT_INSTALLED or self.plugin_status == PLUGIN_VERSION_MISMATCH: log.info("") log.info(log.bold("Plug-in Status")) log.info(log.bold('-'*len("Plug-in Status"))) log.error("Plug-ins need to be installed") if self.disable_selinux == True: log.info("") log.info(log.bold("SELINUX")) log.info(log.bold('-'*len("SELINUX"))) log.error("SELINUX need to be disabled") # if self.missing_user_grps: # log.info("") # log.info(log.bold("USER GROUPS")) # log.info(log.bold('-'*len("USER GROUPS"))) # log.error("%s groups need to be added for %s user"%(self.missing_user_grps,prop.username)) if self.smart_install_devices: log.info("") log.info(log.bold("SMART INSTALL/CD_ROM ENABLED DEVICES")) log.info(log.bold('-'*len("SMART INSTALL/CD_ROM ENABLED DEVICES"))) for dev in self.smart_install_devices: log.error("%s"%dev) url, tool_name = smart_install.get_SmartInstall_tool_info() log.info(log.bold("Smart Install is enabled for these devices. Please disable Smart Install to enable device functionalities.\n\nRefer link '%s' to disable Smart Install.\n"%(url))) log.info("") log.info("Total Errors: %d" % self.num_errors) log.info("Total Warnings: %d" % self.num_warns) log.info() # if self.disable_selinux or self.missing_user_grps or (self.plugin_status == PLUGIN_VERSION_MISMATCH) or (self.plugin_status == PLUGIN_NOT_INSTALLED) or len(self.req_deps_to_be_installed) or len(self.opt_deps_to_be_installed): if self.disable_selinux or (self.plugin_status == PLUGIN_VERSION_MISMATCH) or (self.plugin_status == PLUGIN_NOT_INSTALLED) or len(self.req_deps_to_be_installed) or len(self.opt_deps_to_be_installed): log.info("Run 'hp-doctor' command to prompt and fix the issues. ")
def display_summary(self): tui.header("SUMMARY") log.info(log.bold("Missing Required Dependencies")) log.info(log.bold('-'*len("Missing Required Dependencies"))) if len(self.req_deps_to_be_installed) == 0: log.info("None") else: for packages_to_install in self.req_deps_to_be_installed: if packages_to_install == 'cups': log.error("'%s' package is missing or '%s' service is not running."%(packages_to_install,packages_to_install)) else: log.error("'%s' package is missing/incompatible "%packages_to_install) log.info("") log.info(log.bold("Missing Optional Dependencies")) log.info(log.bold('-'*len("Missing Optional Dependencies"))) if len(self.opt_deps_to_be_installed) == 0: log.info("None\n") else: for packages_to_install in self.opt_deps_to_be_installed: log.error("'%s' package is missing/incompatible "%packages_to_install) if self.plugin_status == PLUGIN_NOT_INSTALLED or self.plugin_status == PLUGIN_VERSION_MISMATCH: log.info("") log.info(log.bold("Plug-in Status")) log.info(log.bold('-'*len("Plug-in Status"))) log.error("Plug-ins need to be installed") # if self.disable_selinux == True: # log.info("") # log.info(log.bold("SELINUX")) # log.info(log.bold('-'*len("SELINUX"))) # log.error("SELINUX need to be disabled") # if self.missing_user_grps: # log.info("") # log.info(log.bold("USER GROUPS")) # log.info(log.bold('-'*len("USER GROUPS"))) # log.error("%s groups need to be added for %s user"%(self.missing_user_grps,prop.username)) if self.smart_install_devices: log.info("") log.info(log.bold("SMART INSTALL/CD_ROM ENABLED DEVICES")) log.info(log.bold('-'*len("SMART INSTALL/CD_ROM ENABLED DEVICES"))) for dev in self.smart_install_devices: log.error("%s"%dev) url, tool_name = smart_install.get_SmartInstall_tool_info() log.info(log.bold("Smart Install is enabled for these devices. Please disable Smart Install to enable device functionalities.\n\nRefer link '%s' to disable Smart Install.\n"%(url))) log.info("") log.info("Total Errors: %d" % self.num_errors) log.info("Total Warnings: %d" % self.num_warns) log.info()
def validate(self,time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode= False): ############ Variables ####################### cups_ddk_not_req = False hpmudext_avail = False ui_toolkit = sys_conf.get('configure','ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs =self.get_distro_data('versions_list') supported_distro_vrs= self.distro_version if self.distro_version not in vrs and len(vrs): supported_distro_vrs= vrs[len(vrs)-1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.distro_name, self.distro_version, self.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info =utils.run("uname -r -v -o") Sts, Host_info =utils.run("uname -n") Sts, Proc_info =utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.distro_name, self.distro_version)) log.info(" Bitness: %s bit\n"%utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" %v) log.info("HPLIP-Home: %s" %home) if self.is_auto_installer_support(): log.info("HPLIP-Installation: Auto installation is supported for %s distro %s version " %(self.distro_name, self.distro_version)) else: log.warn("HPLIP-Installation: Auto installation is not supported for %s distro %s version " %(self.distro_name, self.distro_version)) log.info() log.info(log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = file('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError), e: log.error("Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info(log.bold("Current contents of '/var/lib/hp/hplip.state' file:")) try: output = file(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError), e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror)
def validate(self, time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode=False): ############ Variables ####################### cups_ddk_not_req = False hpmudext_avail = False ui_toolkit = sys_conf.get('configure', 'ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs = self.get_distro_data('versions_list') supported_distro_vrs = self.distro_version if self.distro_version not in vrs and len(vrs): supported_distro_vrs = vrs[len(vrs) - 1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.distro_name, self.distro_version, self.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info = utils.run("uname -r -v -o") Sts, Host_info = utils.run("uname -n") Sts, Proc_info = utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.distro_name, self.distro_version)) log.info(" Bitness: %s bit\n" % utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" % v) log.info("HPLIP-Home: %s" % home) if self.is_auto_installer_support(): log.info( "HPLIP-Installation: Auto installation is supported for %s distro %s version " % (self.distro_name, self.distro_version)) else: log.warn( "HPLIP-Installation: Auto installation is not supported for %s distro %s version " % (self.distro_name, self.distro_version)) log.info() log.info( log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = file('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError), e: log.error( "Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info( log.bold( "Current contents of '/var/lib/hp/hplip.state' file:")) try: output = file(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError), e: log.info( "Plugins are not installed. Could not access file: %s" % e.strerror)
except (IOError, OSError), e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) scanning_enabled = utils.to_bool( sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s" % ("<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>", "<Installed-Version>", "<Status>", "<Comment>")) for s in self.hplip_dependencies: if s == EXTERNALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") else: continue elif s == GENERALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" General Dependencies") else: continue elif s == COMPILEDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_COMPILE_TIME: tui.header(" Compile Time Dependencies") else: continue elif s == PYEXT: tui.header(" Python Extentions") elif s == SCANCONF:
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) plugin_installed = utils.to_bool( sys_state.get('plugin', 'installed', '0')) if ignore_plugin_check is False and plugin > PLUGIN_NONE and not plugin_installed: tui.header("PLUG-IN INSTALLATION") hp_plugin = utils.which('hp-plugin') if hp_plugin: if prop.gui_build: os.system("hp-plugin -i") else: os.system("hp-plugin") ppds = cups.getSystemPPDs() default_model = utils.xstrip( model.replace('series', '').replace('Series', ''), '_') installed_print_devices = device.getSupportedCUPSDevices(['hp'])
for sc in models_dict[m]['tech-subclass']: sects.append(sc) errors.append("(%s) Model '%s' did not have a matching section. Needed section: <%%%s:%s%%>" % (basename, m, tc, ':'.join(sects))) if len(tc) == 1 and 'Postscript' in tc: notes.append("(%s) Postscript-only model %s was not included in DRV file." % (basename, m)) tui.cleanup_spinner() # end for if not quiet or verbose: if notes: tui.header("NOTES") for n in notes: log.note(n) if warns: tui.header("WARNINGS") for w in warns: log.warn(w) if errors: tui.header("ERRORS") for e in errors: log.error(e) else: if warns:
def validate(self,time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode= False): ############ Variables ####################### self.cups_ddk_not_req = False self.hpmudext_avail = False self.ui_toolkit = sys_conf.get('configure','ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs =self.get_distro_data('versions_list') supported_distro_vrs= self.distro_version if self.distro_version not in vrs and len(vrs): supported_distro_vrs= vrs[len(vrs)-1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.distro_name, self.distro_version, self.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info =utils.run("uname -r -v -o") Sts, Host_info =utils.run("uname -n") Sts, Proc_info =utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.distro_name, self.distro_version)) log.info(" Bitness: %s bit\n"%utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" %v) log.info("HPLIP-Home: %s" %home) if self.is_auto_installer_support(): log.info("HPLIP-Installation: Auto installation is supported for %s distro %s version " %(self.distro_name, self.distro_version)) else: log.warn("HPLIP-Installation: Auto installation is not supported for %s distro %s version " %(self.distro_name, self.distro_version)) log.info() log.info(log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = open('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError) as e: log.error("Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info(log.bold("Current contents of '/var/lib/hp/hplip.state' file:")) try: output = open(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError) as e: log.info("Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = open(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError) as e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) self.scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s"%( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>","<Installed-Version>", "<Status>", "<Comment>")) self.dependencies.update(self.hplip_dependencies) if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" General Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == GENERALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" COMPILEDEP") for dep in self.dependencies: if self.dependencies[dep][7] == COMPILEDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Python Extentions") for dep in self.dependencies: if self.dependencies[dep][7] == PYEXT: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Scan Configuration") for dep in self.dependencies: if self.dependencies[dep][7] == SCANCONF: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Other Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] != SCANCONF and \ self.dependencies[dep][7] != PYEXT and \ self.dependencies[dep][7] != COMPILEDEP and \ self.dependencies[dep][7] != GENERALDEP and \ self.dependencies[dep][7] != EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) if self.scanning_enabled: tui.header("DISCOVERED SCANNER DEVICES") if utils.which('scanimage'): status, output = utils.run("scanimage -L") if status != 0 : log.error("Failed to get Scanners information.") elif 'No scanners were identified' in output: log.info("No Scanner found.") else: log.info(output) if device_avail: #if prop.par_build: #tui.header("DISCOVERED PARALLEL DEVICES") #devices = device.probeDevices(['par']) #if devices: #f = tui.Formatter() #f.header = ("Device URI", "Model") #for d, dd in devices.items(): #f.add((d, dd[0])) #f.output() #else: #log.info("No devices found.") #if not core.have_dependencies['ppdev']: #log.error("'ppdecmds_to_be_runv' kernel module not loaded.") if prop.usb_build: tui.header("DISCOVERED USB DEVICES") devices = device.probeDevices(['usb']) if devices: f = tui.Formatter() f.header = ("Device URI", "Model") for d, dd in list(devices.items()): f.add((d, dd[0])) f.output() else: log.info("No devices found.") tui.header("INSTALLED CUPS PRINTER QUEUES") lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE) status, output = utils.run('lpstat -v') log.info() cups_printers = [] plugin_sts = None for p in output.splitlines(): try: match = lpstat_pat.search(p) printer_name = match.group(1) device_uri = match.group(2) cups_printers.append((printer_name, device_uri)) except AttributeError: pass log.debug(cups_printers) if cups_printers: #non_hp = False for p in cups_printers: printer_name, device_uri = p if device_uri.startswith("cups-pdf:/") or \ device_uri.startswith('ipp://'): continue try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(device_uri) except Error: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ '', False, '', '', '', '', '', '', 1 #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port log.info(log.bold(printer_name)) log.info(log.bold('-'*len(printer_name))) x = "Unknown" if back_end == 'hpfax': x = "Fax" elif back_end == 'hp': x = "Printer" log.info("Type: %s" % x) #if is_hp: # x = 'Yes, using the %s: CUPS backend.' % back_end #else: # x = 'No, not using the hp: or hpfax: CUPS backend.' # non_hp = True #log.info("Installed in HPLIP?: %s" % x) log.info("Device URI: %s" % device_uri) ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd') if os.path.exists(ppd): log.info("PPD: %s" % ppd) nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE) try: f = to_string_utf8(open(ppd, 'rb').read()) except IOError: log.warn("Failed to read %s ppd file"%ppd) desc = '' else: try: desc = nickname_pat.search(f).group(1) except AttributeError: desc = '' log.info("PPD Description: %s" % desc) status, output = utils.run('lpstat -p%s' % printer_name) log.info("Printer status: %s" % output.replace("\n", "")) if back_end == 'hpfax' and not 'HP Fax' in desc and desc != '': self.num_errors += 1 log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax(n)-hpcups.ppd'." % printer_name) elif back_end == 'hp' and 'HP Fax' in desc and desc != '': self.num_errors += 1 log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax(n)-hpcups.ppd'." % printer_name) elif back_end not in ('hp', 'hpfax'): log.warn("Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices.") self.num_warns += 1 if device_avail and is_hp: d = None try: try: d = device.Device(device_uri,None, None, None, True) except Error: log.error("Device initialization failed.") continue plugin = d.mq.get('plugin', PLUGIN_NONE) if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL): if not plugin_sts: from installer import pluginhandler pluginObj = pluginhandler.PluginHandle() plugin_sts = pluginObj.getStatus() if plugin_sts == pluginhandler.PLUGIN_INSTALLED: self.plugin_status = PLUGIN_INSTALLED if plugin == pluginhandler.PLUGIN_REQUIRED: log.info("Required plug-in status: Installed") else: log.info("Optional plug-in status: Installed") elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED: self.plugin_status = PLUGIN_NOT_INSTALLED if plugin == PLUGIN_REQUIRED: self.num_errors += 1 log.error("Required plug-in status: Not installed") else: self.num_warns +=1 log.warn("Optional plug-in status: Not installed") elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH: self.num_warns += 1 self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH log.warn("plug-in status: Version mismatch") if bus in ('par', 'usb'): try: d.open() except Error as e: log.error(e.msg) deviceid = '' else: deviceid = d.getDeviceID() log.debug(deviceid) #print deviceid if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") elif bus == 'net': try: error_code, deviceid = d.getPML(pml.OID_DEVICE_ID) except Error: pass #print error_code if not deviceid: log.error("Communication status: Failed") self.comm_error_devices[printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") finally: if d is not None: d.close() log.info() else: log.warn("No queues found.") tui.header("PERMISSION") # sts,avl_grps_out =utils.run('groups') # sts, out = utils.check_user_groups(self.user_grps_cmd, avl_grps_out) # if sts: # log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups","Required", "-","-", "OK",avl_grps_out)) # else: # log.info(log.red("error: %-8s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups", "Required","-", "-", "MISSING", out))) # self.num_errors += 1 # self.missing_user_grps = out if self.hpmudext_avail: lsusb = utils.which('lsusb') if lsusb: lsusb = os.path.join(lsusb, 'lsusb') status, output = utils.run("%s -d03f0:" % lsusb) if output: lsusb_pat = re.compile("""^Bus\s([0-9a-fA-F]{3,3})\sDevice\s([0-9a-fA-F]{3,3}):\sID\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)""", re.IGNORECASE) log.debug(output) try: import hpmudext except ImportError: log.error("NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext.") self.num_errors += 1 for o in output.splitlines(): ok = True match = lsusb_pat.search(o) if match is not None: bus, dev, vid, pid, mfg = match.groups() #log.info("\nHP Device 0x%x at %s:%s: " % (int(pid, 16), bus, dev)) result_code, deviceuri = hpmudext.make_usb_uri(bus, dev) if result_code == hpmudext.HPMUD_R_OK: deviceuri = to_string_utf8(deviceuri) # log.info(" Device URI: %s" % deviceuri) d = None try: d = device.Device(deviceuri,None, None, None, True) except Error: continue if not d.supported: continue else: log.debug(" Device URI: (Makeuri FAILED)") continue printers = cups.getPrinters() printer_name=None for p in printers: if p.device_uri == deviceuri: printer_name=p.name break devnode = os.path.join("/", "dev", "bus", "usb", bus, dev) if not os.path.exists(devnode): devnode = os.path.join("/", "proc", "bus", "usb", bus, dev) if os.path.exists(devnode): # log.debug(" Device node: %s" % devnode) st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, \ st_size, st_atime, st_mtime, st_ctime = os.stat(devnode) getfacl = utils.which('getfacl',True) if getfacl: # log.debug("%s %s" % (getfacl, devnode)) status, output = utils.run("%s %s" % (getfacl, devnode)) getfacl_out_list = output.split('\r\n') out ='' for g in getfacl_out_list: if 'getfacl' not in g and '' is not g and 'file' not in g: pat = re.compile('''.*:(.*)''') if pat.search(g): out = out +' '+ pat.search(g).group(1) log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required", "-", "-", "OK", "Node:'%s' Perm:'%s'"%(devnode,out))) else: log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("USB", printer_name, "Required","-","-","OK", "Node:'%s' Mode:'%s'"%(devnode,st_mode&0o777))) # selinux_file = '/etc/selinux/config' # if os.path.exists(selinux_file): # tui.header("SELINUX") # try: # selinux_fp = open(selinux_file, 'r') # except IOError: # log.error("Failed to open %s file."%selinux_file) # else: # for line in selinux_fp: # line=re.sub(r'\s','',line) # if line == "SELINUX=enforcing": # self.num_warns += 1 # log.warn("%-12s %-12s %-10s %-3s %-3s %-8s %s" \ # %("SELinux", "enabled", "Optional", "-", "-", "INCOMPAT", "'SELinux needs to be disabled for Plugin printers and Fax functionality.'")) # self.disable_selinux = True # break # if self.disable_selinux == False: # log.info("%-15s %-15s %-10s %-3s %-3s %-8s %s"\ # %("SELinux", "disabled", "Optional", "-", "-", "OK", "-")) self.smart_install_devices = smart_install.get_smartinstall_enabled_devices() if len(self.smart_install_devices): tui.header("'CD-ROM'/'Smart Install' Detected Devices") self.num_errors += 1 for d in self.smart_install_devices: log.error("%-30s %-20s %s "%(d, "CD_ROM_Enabled", "Needs to disable Smart Install")) else: log.error("HPLIP not found.") self.num_errors += 1 if is_quiet_mode: log.set_where(org_log_location) return self.num_errors, self.num_warns
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) if plugin_path is None: table = tui.Formatter(header=('Option', 'Description'), min_widths=(10, 50)) table.add(('d', 'Download plug-in from HP (recomended)')) table.add(('p', 'Specify a path to the plug-in (advanced)')) table.add(('q', 'Quit hp-plugin (skip installation)'))
errors.append( "(%s) Model '%s' did not have a matching section. Needed section: <%%%s:%s%%>" % (basename, m, tc, ':'.join(sects))) if len(tc) == 1 and 'Postscript' in tc: notes.append( "(%s) Postscript-only model %s was not included in DRV file." % (basename, m)) tui.cleanup_spinner() # end for if not quiet or verbose: if notes: tui.header("NOTES") for n in notes: log.note(n) if warns: tui.header("WARNINGS") for w in warns: log.warn(w) if errors: tui.header("ERRORS") for e in errors: log.error(e) else: if warns:
log.info() log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = file(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError), e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s"%( "<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>","<Installed-Version>", "<Status>", "<Comment>")) for s in self.hplip_dependencies: if s == EXTERNALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") else: continue elif s == GENERALDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" General Dependencies") else: continue elif s == COMPILEDEP: if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_COMPILE_TIME: tui.header(" Compile Time Dependencies") else: continue elif s == PYEXT: tui.header(" Python Extentions") elif s == SCANCONF: tui.header(" Scan Configuration") else: tui.header(" Other Dependencies") for d in self.hplip_dependencies[s]: if d == 'cups-ddk' and cups_ddk_not_req == True: continue
if not mq or mq.get('support-type', SUPPORT_TYPE_NONE) == SUPPORT_TYPE_NONE: log.error("Unsupported printer model.") sys.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) plugin_installed = utils.to_bool(sys_state.get('plugin', 'installed', '0')) if ignore_plugin_check is False and plugin > PLUGIN_NONE and not plugin_installed: tui.header("PLUG-IN INSTALLATION") hp_plugin = utils.which('hp-plugin') if hp_plugin: if prop.gui_build: os.system("hp-plugin -i") else: os.system("hp-plugin") ppds = cups.getSystemPPDs() default_model = utils.xstrip(model.replace('series', '').replace('Series', ''), '_') installed_print_devices = device.getSupportedCUPSDevices(['hp']) for d in installed_print_devices.keys():
mod.usage(error_msg=["Invalid term in filter"]) elif o in ('-s', '--search', '--find'): search = a.lower().strip() if bus is None: bus = tui.connection_table() if bus is None: sys.exit(0) log.info("\nUsing connection type: %s" % bus[0]) log.info("") tui.header("DEVICE DISCOVERY") for b in bus: if b == 'net': log.info(log.bold("Probing network for printers. Please wait, this will take approx. %d seconds...\n" % timeout)) FILTER_MAP = {'print' : None, 'none' : None, 'scan': 'scan-type', 'copy': 'copy-type', 'pcard': 'pcard-type', 'fax': 'fax-type', } filter_dict = {} for f in filter:
def validate(self, time_flag=DEPENDENCY_RUN_AND_COMPILE_TIME, is_quiet_mode=False): ############ Variables ####################### self.cups_ddk_not_req = False self.hpmudext_avail = False self.ui_toolkit = sys_conf.get('configure', 'ui-toolkit') org_log_location = log.get_where() if is_quiet_mode: log.set_where(log.LOG_TO_FILE) IS_LIBUSB01_ENABLED = sys_conf.get('configure', 'libusb01-build', 'no') vrs = self.get_distro_data('versions_list') supported_distro_vrs = self.distro_version if self.distro_version not in vrs and len(vrs): supported_distro_vrs = vrs[len(vrs) - 1] log.warn(log.bold("%s-%s version is not supported. Using %s-%s versions dependencies to verify and install..." \ %(self.distro_name, self.distro_version, self.distro_name, supported_distro_vrs))) tui.header("SYSTEM INFO") Sts, Kernel_info = utils.run("uname -r -v -o") Sts, Host_info = utils.run("uname -n") Sts, Proc_info = utils.run("uname -r -v -o") log.info(" Kernel: %s Host: %s Proc: %s Distribution: %s %s"\ %(Kernel_info,Host_info,Proc_info,self.distro_name, self.distro_version)) log.info(" Bitness: %s bit\n" % utils.getBitness()) tui.header("HPLIP CONFIGURATION") v = sys_conf.get('hplip', 'version') if v: home = sys_conf.get('dirs', 'home') log.info("HPLIP-Version: HPLIP %s" % v) log.info("HPLIP-Home: %s" % home) if self.is_auto_installer_support(): log.info( "HPLIP-Installation: Auto installation is supported for %s distro %s version " % (self.distro_name, self.distro_version)) else: log.warn( "HPLIP-Installation: Auto installation is not supported for %s distro %s version " % (self.distro_name, self.distro_version)) log.info() log.info( log.bold("Current contents of '/etc/hp/hplip.conf' file:")) try: output = open('/etc/hp/hplip.conf', 'r').read() except (IOError, OSError) as e: log.error( "Could not access file: %s. Check HPLIP installation." % e.strerror) self.num_errors += 1 else: log.info(output) log.info() log.info( log.bold( "Current contents of '/var/lib/hp/hplip.state' file:")) try: output = open(os.path.expanduser('/var/lib/hp/hplip.state'), 'r').read() except (IOError, OSError) as e: log.info( "Plugins are not installed. Could not access file: %s" % e.strerror) else: log.info(output) log.info() log.info( log.bold("Current contents of '~/.hplip/hplip.conf' file:")) try: output = open(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read() except (IOError, OSError) as e: log.warn("Could not access file: %s" % e.strerror) self.num_warns += 1 else: log.info(output) self.scanning_enabled = utils.to_bool( sys_conf.get('configure', 'scanner-build', '0')) log.info(" %-20s %-20s %-10s %-10s %-10s %-10s %s" % ("<Package-name>", " <Package-Desc>", "<Required/Optional>", "<Min-Version>", "<Installed-Version>", "<Status>", "<Comment>")) self.dependencies.update(self.hplip_dependencies) if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == DEPENDENCY_RUN_TIME: tui.header(" External Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" General Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] == GENERALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" COMPILEDEP") for dep in self.dependencies: if self.dependencies[dep][7] == COMPILEDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Python Extentions") for dep in self.dependencies: if self.dependencies[dep][7] == PYEXT: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Scan Configuration") for dep in self.dependencies: if self.dependencies[dep][7] == SCANCONF: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) tui.header(" Other Dependencies") for dep in self.dependencies: if self.dependencies[dep][7] != SCANCONF and \ self.dependencies[dep][7] != PYEXT and \ self.dependencies[dep][7] != COMPILEDEP and \ self.dependencies[dep][7] != GENERALDEP and \ self.dependencies[dep][7] != EXTERNALDEP: self.__update_deps_info(supported_distro_vrs, dep, self.dependencies[dep]) if self.scanning_enabled: tui.header("DISCOVERED SCANNER DEVICES") if utils.which('scanimage'): status, output = utils.run("scanimage -L") if status != 0: log.error("Failed to get Scanners information.") elif 'No scanners were identified' in output: log.info("No Scanner found.") else: log.info(output) if device_avail: #if prop.par_build: #tui.header("DISCOVERED PARALLEL DEVICES") #devices = device.probeDevices(['par']) #if devices: #f = tui.Formatter() #f.header = ("Device URI", "Model") #for d, dd in devices.items(): #f.add((d, dd[0])) #f.output() #else: #log.info("No devices found.") #if not core.have_dependencies['ppdev']: #log.error("'ppdecmds_to_be_runv' kernel module not loaded.") if prop.usb_build: tui.header("DISCOVERED USB DEVICES") devices = device.probeDevices(['usb']) if devices: f = tui.Formatter() f.header = ("Device URI", "Model") for d, dd in list(devices.items()): f.add((d, dd[0])) f.output() else: log.info("No devices found.") tui.header("INSTALLED CUPS PRINTER QUEUES") lpstat_pat = re.compile(r"""(\S*): (.*)""", re.IGNORECASE) status, output = utils.run('lpstat -v') log.info() cups_printers = [] plugin_sts = None for p in output.splitlines(): try: match = lpstat_pat.search(p) printer_name = match.group(1) device_uri = match.group(2) cups_printers.append((printer_name, device_uri)) except AttributeError: pass log.debug(cups_printers) if cups_printers: #non_hp = False for p in cups_printers: printer_name, device_uri = p if device_uri.startswith("cups-pdf:/") or \ device_uri.startswith('ipp://'): continue try: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ device.parseDeviceURI(device_uri) except Error: back_end, is_hp, bus, model, serial, dev_file, host, zc, port = \ '', False, '', '', '', '', '', '', 1 #print back_end, is_hp, bus, model, serial, dev_file, host, zc, port log.info(log.bold(printer_name)) log.info(log.bold('-' * len(printer_name))) x = "Unknown" if back_end == 'hpfax': x = "Fax" elif back_end == 'hp': x = "Printer" log.info("Type: %s" % x) #if is_hp: # x = 'Yes, using the %s: CUPS backend.' % back_end #else: # x = 'No, not using the hp: or hpfax: CUPS backend.' # non_hp = True #log.info("Installed in HPLIP?: %s" % x) log.info("Device URI: %s" % device_uri) ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd') if os.path.exists(ppd): log.info("PPD: %s" % ppd) nickname_pat = re.compile( r'''\*NickName:\s*\"(.*)"''', re.MULTILINE) try: f = to_string_utf8(open(ppd, 'rb').read()) except IOError: log.warn("Failed to read %s ppd file" % ppd) desc = '' else: try: desc = nickname_pat.search(f).group(1) except AttributeError: desc = '' log.info("PPD Description: %s" % desc) status, output = utils.run('lpstat -p%s' % printer_name) log.info("Printer status: %s" % output.replace("\n", "")) if back_end == 'hpfax' and not 'HP Fax' in desc: self.num_errors += 1 log.error( "Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'." % printer_name) elif back_end == 'hp' and 'HP Fax' in desc: self.num_errors += 1 log.error( "Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'." % printer_name) elif back_end not in ('hp', 'hpfax'): log.warn( "Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend for HP-Devices." ) self.num_warns += 1 if device_avail and is_hp: d = None try: try: d = device.Device(device_uri, None, None, None, True) except Error: log.error("Device initialization failed.") continue plugin = d.mq.get('plugin', PLUGIN_NONE) if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL): if not plugin_sts: from installer import pluginhandler pluginObj = pluginhandler.PluginHandle( ) plugin_sts = pluginObj.getStatus() if plugin_sts == pluginhandler.PLUGIN_INSTALLED: self.plugin_status = PLUGIN_INSTALLED if plugin == pluginhandler.PLUGIN_REQUIRED: log.info( "Required plug-in status: Installed" ) else: log.info( "Optional plug-in status: Installed" ) elif plugin_sts == pluginhandler.PLUGIN_NOT_INSTALLED: self.plugin_status = PLUGIN_NOT_INSTALLED if plugin == PLUGIN_REQUIRED: self.num_errors += 1 log.error( "Required plug-in status: Not installed" ) else: self.num_warns += 1 log.warn( "Optional plug-in status: Not installed" ) elif plugin_sts == pluginhandler.PLUGIN_VERSION_MISMATCH: self.num_warns += 1 self.plugin_status = pluginhandler.PLUGIN_VERSION_MISMATCH log.warn( "plug-in status: Version mismatch") if bus in ('par', 'usb'): try: d.open() except Error as e: log.error(e.msg) deviceid = '' else: deviceid = d.getDeviceID() log.debug(deviceid) #print deviceid if not deviceid: log.error( "Communication status: Failed") self.comm_error_devices[ printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") elif bus == 'net': try: error_code, deviceid = d.getPML( pml.OID_DEVICE_ID) except Error: pass #print error_code if not deviceid: log.error( "Communication status: Failed") self.comm_error_devices[ printer_name] = device_uri self.num_errors += 1 else: log.info("Communication status: Good") finally: if d is not None: d.close() log.info() else: log.warn("No queues found.") tui.header("PERMISSION") # sts,avl_grps_out =utils.run('groups') # sts, out = utils.check_user_groups(self.user_grps_cmd, avl_grps_out) # if sts: # log.info("%-15s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups","Required", "-","-", "OK",avl_grps_out)) # else: # log.info(log.red("error: %-8s %-30s %-15s %-8s %-8s %-8s %s"%("groups", "user-groups", "Required","-", "-", "MISSING", out))) # self.num_errors += 1 # self.missing_user_grps = out if self.hpmudext_avail: lsusb = utils.which('lsusb') if lsusb: lsusb = os.path.join(lsusb, 'lsusb') status, output = utils.run("%s -d03f0:" % lsusb) if output: lsusb_pat = re.compile( """^Bus\s([0-9a-fA-F]{3,3})\sDevice\s([0-9a-fA-F]{3,3}):\sID\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)""", re.IGNORECASE) log.debug(output) try: import hpmudext except ImportError: log.error( "NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext." ) self.num_errors += 1 for o in output.splitlines(): ok = True match = lsusb_pat.search(o) if match is not None: bus, dev, vid, pid, mfg = match.groups() #log.info("\nHP Device 0x%x at %s:%s: " % (int(pid, 16), bus, dev)) result_code, deviceuri = hpmudext.make_usb_uri( bus, dev) if result_code == hpmudext.HPMUD_R_OK: deviceuri = to_string_utf8(deviceuri) # log.info(" Device URI: %s" % deviceuri) d = None try: d = device.Device( deviceuri, None, None, None, True) except Error: continue if not d.supported: continue else: log.debug( " Device URI: (Makeuri FAILED)") continue printers = cups.getPrinters() printer_name = None for p in printers: if p.device_uri == deviceuri: printer_name = p.name break devnode = os.path.join("/", "dev", "bus", "usb", bus, dev) if not os.path.exists(devnode): devnode = os.path.join( "/", "proc", "bus", "usb", bus, dev) if os.path.exists(devnode): # log.debug(" Device node: %s" % devnode) st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, \ st_size, st_atime, st_mtime, st_ctime = os.stat(devnode) getfacl = utils.which('getfacl', True) if getfacl: # log.debug("%s %s" % (getfacl, devnode)) status, output = utils.run( "%s %s" % (getfacl, devnode)) getfacl_out_list = output.split('\r\n') out = '' for g in getfacl_out_list: if 'getfacl' not in g and '' is not g and 'file' not in g: pat = re.compile('''.*:(.*)''') if pat.search(g): out = out + ' ' + pat.search( g).group(1) log.info( "%-15s %-30s %-15s %-8s %-8s %-8s %s" % ("USB", printer_name, "Required", "-", "-", "OK", "Node:'%s' Perm:'%s'" % (devnode, out))) else: log.info( "%-15s %-30s %-15s %-8s %-8s %-8s %s" % ("USB", printer_name, "Required", "-", "-", "OK", "Node:'%s' Mode:'%s'" % (devnode, st_mode & 0o777))) selinux_file = '/etc/selinux/config' if os.path.exists(selinux_file): tui.header("SELINUX") try: selinux_fp = open(selinux_file, 'r') except IOError: log.error("Failed to open %s file." % selinux_file) else: for line in selinux_fp: line = re.sub(r'\s', '', line) if line == "SELINUX=enforcing": self.num_warns += 1 log.warn("%-12s %-12s %-10s %-3s %-3s %-8s %s" \ %("SELinux", "enabled", "Optional", "-", "-", "INCOMPAT", "'SELinux needs to be disabled for Plugin printers and Fax functionality.'")) self.disable_selinux = True break if self.disable_selinux == False: log.info("%-15s %-15s %-10s %-3s %-3s %-8s %s"\ %("SELinux", "disabled", "Optional", "-", "-", "OK", "-")) self.smart_install_devices = smart_install.get_smartinstall_enabled_devices( ) if len(self.smart_install_devices): tui.header("'CD-ROM'/'Smart Install' Detected Devices") self.num_errors += 1 for d in self.smart_install_devices: log.error("%-30s %-20s %s " % (d, "CD_ROM_Enabled", "Needs to disable Smart Install")) else: log.error("HPLIP not found.") self.num_errors += 1 if is_quiet_mode: log.set_where(org_log_location) return self.num_errors, self.num_warns
log_file = os.path.normpath('./hp-check.log') log.info(log.bold("Saving output in log file: %s" % log_file)) log.debug("Log file=%s" % log_file) if os.path.exists(log_file): os.remove(log_file) log.set_logfile(log_file) log.set_where(log.LOG_TO_CONSOLE_AND_FILE) log.info("\nInitializing. Please wait...") core = CoreInstall(MODE_CHECK) core.init() core.set_plugin_version() tui.header("SYSTEM INFO") log.info(log.bold("Basic system information:")) log.info(core.sys_uname_info) log.info() log.info(log.bold("Distribution:")) log.info("%s %s" % (core.distro_name, core.distro_version)) #log.info(log.bold("\nHPOJ running?")) #if core.hpoj_present: #log.error("Yes, HPOJ is running. HPLIP is not compatible with HPOJ. To run HPLIP, please remove HPOJ.") #num_errors += 1 #else: #log.info("No, HPOJ is not running (OK).")
try: log.debug("Starting GUI loop...") app.exec_() except KeyboardInterrupt: log.error("User exit") clean_exit(0) else: # INTERACTIVE_MODE try: log.info( "(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)" ) log.info("") tui.header("PLUG-IN INSTALLATION FOR HPLIP %s" % version) if plugin_installed: 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: clean_exit(0) if plugin_path is None: table = tui.Formatter(header=('Option', 'Description'), min_widths=(10, 50))
def main(args): global errors global model_dat line_num = 0 log.set_module("dat2drv.py") cur_path = os.path.realpath(os.path.normpath(os.getcwd())) dat_path = os.path.join(cur_path, 'data', 'models') model_dat = models.ModelData(dat_path) load_models() verbose = False quiet = False try: opts, args = getopt.getopt(args, 'd:l:ho:vq', ['logging=', 'help', 'help-rest', 'help-man', 'drv=', 'output=', 'verbose', 'quiet']) except getopt.GetoptError as e: log.error(e.msg) usage() sys.exit(0) log_level = 'info' if os.getenv("HPLIP_DEBUG"): log.set_level('debug') for o, a in opts: if o in ('-h', '--help'): usage() elif o == '--help-rest': usage('rest') elif o == '--help-man': usage('man') elif o in ('-v', '--verbose'): verbose = True elif o in ('-q', '--quiet'): quiet = True elif o in ('-l', '--logging'): log.set_level(a.lower().strip()) if not quiet: utils.log_title(__title__, __version__) drv_dir = os.path.join(cur_path, 'prnt', 'drv') errors = [] warns = [] notes = [] for template_file in utils.walkFiles(drv_dir, recurse=False, abs_paths=True, return_folders=False, pattern='*.in.template'): basename = os.path.basename(template_file).split('.')[0] # Output drv_in_file = os.path.join(cur_path, 'prnt', 'drv', '%s.drv.in' % basename) # XML output (per model) output_path = os.path.join(cur_path, 'prnt', 'drv', 'foomatic_xml', basename) # XML Output (master driver list) driver_path = os.path.join(cur_path, 'prnt', 'drv', 'foomatic_xml', basename, '%s.xml' % basename) log.info("Working on %s file..." % basename) log.info("Input file: %s" % template_file) log.info("Output file: %s" % drv_in_file) log.info("Output XML directory: %s" % output_path) log.info("Output driver XML file: %s" % driver_path) # CREATE DRV.IN FILE log.info("Processing %s.drv.in.template..." % basename) tui.update_spinner() template_classes = [] template_file_f = open(template_file, 'r') drv_in_file_f = open(drv_in_file, 'w') models_placement = {} for m in models_dict: models_placement[m] = 0 line = 0 for x in template_file_f: if verbose: log.info(x.strip()) line += 1 tui.update_spinner() drv_in_file_f.write(x) match = pat_template.match(x) if match is not None: matches = [] indent = match.group(1) indent2 = ' '*(len(indent)+2) classes = match.group(2).split(':') tech_class = classes[0] if tech_class not in models.TECH_CLASSES: errors.append("(%s:line %d) Invalid tech-class (%s): %s" % (basename, line, tech_class, x.strip())) continue template_classes.append(tech_class) tech_subclass = classes[1:] ok = True for sc in tech_subclass: if sc not in models.TECH_SUBCLASSES: errors.append("(%s:line %d) Invalid tech-subclass (%s): %s" % (basename, line, sc, x.strip())) ok = False if not ok: continue for m in models_dict: include = False if tech_class in models_dict[m]['tech-class'] and \ len(models_dict[m]['tech-subclass']) == len(tech_subclass): for msc in models_dict[m]['tech-subclass']: if msc not in tech_subclass: break else: include = True if include: models_placement[m] += 1 matches.append(m) if matches: try: matches.sort(key=lambda y: pat_prod_num.search(y).group(1)) except: matches.sort(key=str.lower) for p in matches: if verbose: log.info("(%s) Adding section for model: %s" % (basename, p)) drv_in_file_f.write("%s{\n" % indent) if basename == 'hpcups': model_name = models_dict[p]['norm_model'] else: model_name = models_dict[p]['norm_model'] + " %s" % basename orig_model_name = model_name while True: if len(model_name) > 31: for k in SHORTENING_REPLACEMENTS: if k in model_name.lower(): model_name = utils.ireplace(model_name, k, SHORTENING_REPLACEMENTS[k]) model_name = model_name.replace(' ', ' ') if len(model_name) < 32: warns.append('len("%s")>31, shortened to len("%s")=%d using sub-brand shortening replacements.' % (orig_model_name, model_name, len(model_name))) break if len(model_name) < 32: break if "series" in model_name.lower(): model_name = utils.ireplace(model_name, "series", "Ser.") model_name = model_name.replace(' ', ' ') if len(model_name) < 32: warns.append('len("%s")>31, shortened to len("%s")=%d using "series" to "ser." replacement.' % (orig_model_name, model_name, len(model_name))) break if "ser." in model_name.lower(): model_name = utils.ireplace(model_name, "ser.", "") model_name = model_name.replace(' ', ' ') if len(model_name) < 32: warns.append('len("%s")>31, shortened to len("%s")=%d using "ser." removal.' % (orig_model_name, model_name, len(model_name))) break if len(model_name) > 31: model_name = model_name[:31] errors.append('len("%s")>31 chars, could not shorten to <32. Truncating to 31 chars (%s).' % (orig_model_name, model_name)) break drv_in_file_f.write('%sModelName "%s"\n' % (indent2, orig_model_name)) if len(models_dict[p]['tech-class']) > 1: if basename == "hpcups": drv_in_file_f.write('%sAttribute "NickName" "" "%s %s, %s $Version' % (indent2, orig_model_name, models.TECH_CLASS_PDLS[tech_class],basename)) else: drv_in_file_f.write('%sAttribute "NickName" "" "%s %s, $Version' % (indent2, orig_model_name, models.TECH_CLASS_PDLS[tech_class])) else: if basename == "hpcups": drv_in_file_f.write('%sAttribute "NickName" "" "%s, %s $Version' % (indent2, orig_model_name, basename)) else: drv_in_file_f.write('%sAttribute "NickName" "" "%s, $Version' % (indent2, orig_model_name)) if models_dict[p]['plugin'] in (1, 2): if (models_dict[p]['plugin-reason'] & 15 ) in (1, 2, 3, 4, 5, 6, 8, 9, 10, 12): drv_in_file_f.write(', requires proprietary plugin') drv_in_file_f.write('"\n') drv_in_file_f.write('%sAttribute "ShortNickName" "" "%s"\n' % (indent2, model_name)) pp = p.replace('_', ' ') if 'apollo' in p.lower(): devid = "MFG:Apollo;MDL:%s;DES:%s;" % (pp, pp) elif 'laserjet' in p.lower() or 'designjet' in p.lower(): devid = "MFG:Hewlett-Packard;MDL:%s;DES:%s;" % (pp, pp) else: devid = "MFG:HP;MDL:%s;DES:%s;" % (pp, pp) drv_in_file_f.write('%sAttribute "1284DeviceID" "" "%s"\n' % (indent2, devid)) if len(models_dict[p]['tech-class']) > 1: if basename == 'hpcups': drv_in_file_f.write('%sPCFileName "%s-%s.ppd"\n' % (indent2, fixFileName(p), models.TECH_CLASS_PDLS[tech_class])) else: drv_in_file_f.write('%sPCFileName "%s-%s-%s.ppd"\n' % (indent2, fixFileName(p), basename, models.TECH_CLASS_PDLS[tech_class])) elif tech_class != 'Postscript': if basename == 'hpcups': drv_in_file_f.write('%sPCFileName "%s.ppd"\n' % (indent2, fixFileName(p))) else: drv_in_file_f.write('%sPCFileName "%s-%s.ppd"\n' % (indent2, fixFileName(p), basename)) else: drv_in_file_f.write('%sPCFileName "%s-ps.ppd"\n' % (indent2, fixFileName(p))) for c in models_dict[p]['case_models']: drv_in_file_f.write('%sAttribute "Product" "" "(%s)"\n' % (indent2, c)) drv_in_file_f.write("%s}\n" % indent) else: errors.append("(%s:line %d) No models matched the specified classes on line: %s" % (basename, line, x.strip())) else: match = pat_template2.match(x) if match is not None: errors.append("(%s:line %d) Malformed line: %s (missing initial //)" % (basename, line, x.strip())) template_file_f.close() drv_in_file_f.close() tui.cleanup_spinner() for tc in models.TECH_CLASSES: if tc.lower() in ('undefined', 'postscript', 'unsupported'): continue if tc not in template_classes: warns.append("(%s) Section <%%%s:...%%> not found." % (basename, tc)) # OUTPUT XML FILES if not os.path.exists(output_path): os.makedirs(output_path) if os.path.exists(driver_path): os.remove(driver_path) files_to_delete = [] for f in utils.walkFiles(output_path, recurse=True, abs_paths=True, return_folders=False, pattern='*'): files_to_delete.append(f) for f in files_to_delete: os.remove(f) driver_f = open(driver_path, 'w') driver_doc = XMLDocument("driver", id="driver/hplip") name_node = driver_doc.add("name") name_node.addText("hplip") url_node = driver_doc.add("url") url_node.addText("http://hplipopensource.com") supplier_node = driver_doc.add("supplier") supplier_node.addText("Hewlett-Packard") mfg_node = driver_doc.add("manufacturersupplied") mfg_node.addText("HP|Apollo") lic_node = driver_doc.add("license") lic_node.addText("BSD/GPL/MIT") driver_doc.add("freesoftware") support_node = driver_doc.add("supportcontact", level="voluntary", url="https://launchpad.net/hplip") support_node.addText("HPLIP Support at Launchpad.net") shortdesc_node = driver_doc.add("shortdescription") shortdesc_en_node = shortdesc_node.add("en") shortdesc_en_node.addText("HP's driver suite for printers and multi-function devices") func_node = driver_doc.add("functionality") maxresx_node = func_node.add("maxresx") maxresx_node.addText("1200") maxresy_node = func_node.add("maxresy") maxresy_node.addText("1200") func_node.add("color") exec_node = driver_doc.add("execution") exec_node.add("nopjl") exec_node.add("ijs") proto_node = exec_node.add("prototype") #proto_node.addText("gs -q -dBATCH -dPARANOIDSAFER -dQUIET -dNOPAUSE -sDEVICE=ijs -sIjsServer=hpijs%A%B%C -dIjsUseOutputFD%Z -sOutputFile=- -") comments_node = driver_doc.add("comments") comments_en_node = comments_node.add("en") comments_en_node.addText("") printers_node = driver_doc.add("printers") for m in models_dict: if models_dict[m]['support-type'] == SUPPORT_TYPE_NONE: continue if 'apollo' in m.lower(): make = 'Apollo' else: make = 'HP' if 'apollo' in m.lower(): ieee1284 = "MFG:Apollo;MDL:%s;DES:%s;" % (m, m) else: ieee1284 = "MFG:HP;MDL:%s;DES:%s;" % (m, m) postscriptppd = '' if 'Postscript' in models_dict[m]['tech-class']: postscriptppd = "%s-ps.ppd" % fixFileName(m) stripped_model = m if stripped_model.startswith('hp_'): stripped_model = stripped_model.replace('hp_', '').capitalize() elif stripped_model.startswith('apollo_'): stripped_model = stripped_model.replace('apollo_', '').capitalize() fixed_model = stripped_model.replace('_', ' ').capitalize() # Output to the per-model XML file outputModel(m, fixed_model, stripped_model, make, postscriptppd, ieee1284, output_path, verbose) # Output to driver master XML file outputDriver(m, fixed_model, stripped_model, make, printers_node, verbose) driver_f.write(str(driver_doc)) driver_f.close() # Make sure all models ended up in drv.in file log.info("Checking for errors...") tui.update_spinner() for m in models_dict: tui.update_spinner() tc = models_dict[m]['tech-class'] st = models_dict[m]['support-type'] if not tc or 'Undefined' in tc: if st: errors.append('(%s) Invalid tech-class for model %s ("Undefined" or missing)' % (basename, m)) #else: # warns.append('(%s) Invalid tech-class for unsupported model %s ("Undefined" or missing)' % (basename, m)) else: if not models_placement[m] and st and \ len(tc) == 1 and 'Postscript' not in tc: sects = [] for tc in models_dict[m]['tech-class']: for sc in models_dict[m]['tech-subclass']: sects.append(sc) errors.append("(%s) Model '%s' did not have a matching section. Needed section: <%%%s:%s%%>" % (basename, m, tc, ':'.join(sects))) if len(tc) == 1 and 'Postscript' in tc: notes.append("(%s) Postscript-only model %s was not included in DRV file." % (basename, m)) tui.cleanup_spinner() # end for if not quiet or verbose: if notes: tui.header("NOTES") for n in notes: log.note(n) if warns: tui.header("WARNINGS") for w in warns: log.warn(w) if errors: tui.header("ERRORS") for e in errors: log.error(e) else: if warns: log.warn("%d warnings" % len(warns)) if errors: log.error("%d errors" % len(errors))
except KeyboardInterrupt: clean_exit(0) else: # INTERACTIVE_MODE try: try: from base import password except ImportError: log.warn("Failed to import Password Object") else: cups.setPasswordCallback(password.showPasswordPrompt) #Removing Queue if remove: tui.header("REMOVING PRINT/FAX QUEUE") sts, printer_name, device_uri = mod.getPrinterName(selected_device_name,None,['hp','hpfax']) selected_device_name = printer_name log.info (log.bold("Removing '%s : %s' Queue"%(printer_name, device_uri))) status, status_str = cups.cups_operation(cups.delPrinter, INTERACTIVE_MODE, '', None, selected_device_name) if cups.IPP_OK == status: log.info("Successfully deleted %s Print/Fax queue"%selected_device_name) utils.sendEvent(EVENT_CUPS_QUEUES_REMOVED,device_uri, printer_name) clean_exit(0) else: log.error("Failed to delete %s Print/Fax queue. Error : %s"%(selected_device_name,status_str)) clean_exit(1) if not auto: