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 __getPluginFilesList(self, src_dir): if not os.path.exists(src_dir+"/plugin.spec"): log.warn("%s/plugin.spec file doesn't exists."%src_dir) return [] cwd = os.getcwd() os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' BIN = sys_conf.get('dirs', 'bin') # Copying plugin.spec file to home dir. if src_dir != HOMEDIR: shutil.copyfile(src_dir+"/plugin.spec", HOMEDIR+"/plugin.spec") os.chmod(HOMEDIR+"/plugin.spec",0644) processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) os.chdir(cwd) return [] src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') if not src: log.error("Missing 'src=' value in section [%s]" % s) os.chdir(cwd) return [] if not trg: log.error("Missing 'trg=' value in section [%s]" % s) os.chdir(cwd) return [] src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.chdir(cwd) return copies
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
def __getPluginFilesList(self, src_dir): if not os.path.exists(src_dir + "/plugin.spec"): log.warn("%s/plugin.spec file doesn't exists." % src_dir) return [] cwd = os.getcwd() os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' BIN = sys_conf.get('dirs', 'bin') # Copying plugin.spec file to home dir. if src_dir != HOMEDIR: shutil.copyfile(src_dir + "/plugin.spec", HOMEDIR + "/plugin.spec") os.chmod(HOMEDIR + "/plugin.spec", 0o644) processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' elif (processor == 'armv6l' or processor == 'armv7l' or processor == 'aarch64' or processor == 'aarch32'): ARCH = 'arm%d' % BITNESS else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) os.chdir(cwd) return [] src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') if not src: log.error("Missing 'src=' value in section [%s]" % s) os.chdir(cwd) return [] if not trg: log.error("Missing 'trg=' value in section [%s]" % s) os.chdir(cwd) return [] src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.chdir(cwd) return copies
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
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 copyPluginFiles(src_dir): os.chdir(src_dir) plugin_spec = ConfigBase("plugin.spec") products = plugin_spec.keys("products") BITNESS = utils.getBitness() ENDIAN = utils.getEndian() PPDDIR = sys_conf.get('dirs', 'ppd') DRVDIR = sys_conf.get('dirs', 'drv') HOMEDIR = sys_conf.get('dirs', 'home') DOCDIR = sys_conf.get('dirs', 'doc') CUPSBACKENDDIR = sys_conf.get('dirs', 'cupsbackend') CUPSFILTERDIR = sys_conf.get('dirs', 'cupsfilter') RULESDIR = '/etc/udev/rules.d' processor = utils.getProcessor() if processor == 'power_machintosh': ARCH = 'ppc' else: ARCH = 'x86_%d' % BITNESS if BITNESS == 64: SANELIBDIR = '/usr/lib64/sane' LIBDIR = '/usr/lib64' else: SANELIBDIR = '/usr/lib/sane' LIBDIR = '/usr/lib' copies = [] for PRODUCT in products: MODEL = PRODUCT.replace('hp-', '').replace('hp_', '') UDEV_SYSFS_RULES=sys_conf.get('configure','udev_sysfs_rules','no') for s in plugin_spec.get("products", PRODUCT).split(','): if not plugin_spec.has_section(s): log.error("Missing section [%s]" % s) return False src = plugin_spec.get(s, 'src', '') trg = plugin_spec.get(s, 'trg', '') link = plugin_spec.get(s, 'link', '') # In Cent os 5.x distro's SYSFS attribute will be used. and Other distro's uses ATTR/ATTRS attribute in rules. # Following condition to check this... if UDEV_SYSFS_RULES == 'no' and 'sysfs' in src: continue if UDEV_SYSFS_RULES == 'yes' and 'sysfs' not in src: continue if not src: log.error("Missing 'src=' value in section [%s]" % s) return False if not trg: log.error("Missing 'trg=' value in section [%s]" % s) return False src = os.path.basename(utils.cat(src)) trg = utils.cat(trg) if link: link = utils.cat(link) copies.append((src, trg, link)) copies = utils.uniqueList(copies) copies.sort() os.umask(0) for src, trg, link in copies: if not os.path.exists(src): log.debug("Source file %s does not exist. Skipping." % src) continue if os.path.exists(trg): log.debug("Target file %s already exists. Replacing." % trg) os.remove(trg) trg_dir = os.path.dirname(trg) if not os.path.exists(trg_dir): log.debug("Target directory %s does not exist. Creating." % trg_dir) os.makedirs(trg_dir, 0755) if not os.path.isdir(trg_dir): log.error("Target directory %s exists but is not a directory. Skipping." % trg_dir) continue try: shutil.copyfile(src, trg) except (IOError, OSError), e: log.error("File copy failed: %s" % e.strerror) continue else: if not os.path.exists(trg): log.error("Target file %s does not exist. File copy failed." % trg) continue else: os.chmod(trg, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH) if link: if os.path.exists(link): log.debug("Symlink already exists. Replacing.") os.remove(link) log.debug("Creating symlink %s (link) to file %s (target)..." % (link, trg)) try: os.symlink(trg, link) except (OSError, IOError), e: log.debug("Unable to create symlink: %s" % e.strerror) pass