def _initialize_dmi_data(): """ Initialize _dmi_data unless it already exist and returns it """ global _dmi_data, _dmi_not_available if _dmi_data is None: if _dmi_not_available: # do not try to initialize it again and again if not available return None else: dmixml = dmidecode.dmidecodeXML() dmixml.SetResultType(dmidecode.DMIXML_DOC) # Get all the DMI data and prepare a XPath context try: data = dmixml.QuerySection('all') dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() log = up2dateLog.initLog() log.log_debug("dmidecode warnings: %s" % dmi_warn) except: # DMI decode FAIL, this can happend e.g in PV guest _dmi_not_available = 1 dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() return None _dmi_data = data.xpathNewContext() return _dmi_data
def _initialize_dmi_data(): """ Initialize _dmi_data unless it already exist and returns it """ global _dmi_data, _dmi_not_available if _dmi_data is None: if _dmi_not_available: # do not try to initialize it again and again if not available return None else : dmixml = dmidecode.dmidecodeXML() dmixml.SetResultType(dmidecode.DMIXML_DOC) # Get all the DMI data and prepare a XPath context try: data = dmixml.QuerySection('all') dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() log = up2dateLog.initLog() log.log_debug("dmidecode warnings: " % dmi_warn) except: # DMI decode FAIL, this can happend e.g in PV guest _dmi_not_available = 1 dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() return None _dmi_data = data.xpathNewContext() return _dmi_data
def log_warnings(self, dmidecode): dmiwarnings = dmidecode.get_warnings() if dmiwarnings: log.warn(_("Error reading system DMI information: %s"), dmiwarnings, exc_info=True) dmidecode.clear_warnings()
def dmi_system(item, data=None): if not data: data = dmidecode.system() #@UndefinedVariable dmidecode.clear_warnings() #@UndefinedVariable item = item.lower() for key, value in data.items(): if item == key.lower(): return value.decode('utf-8') if isinstance(value, dict) and value: value = dmi_system(item, value) if value: return value return None
def dmi_system(item, data=None): if not data: data = dmidecode.system() dmidecode.clear_warnings() item = item.lower() for key, value in data.iteritems(): if item == key.lower(): return value if isinstance(value, dict): value = dmi_system(item, value) if value: return value return None
def ProcessWarnings(): if not hasattr(dmidecode, 'get_warnings'): return warnings = dmidecode.get_warnings() if warnings == None: return for warnline in warnings.split('\n'): # Ignore these warnings, as they are "valid" if not running as root if warnline == '/dev/mem: Permission denied': continue if warnline == 'No SMBIOS nor DMI entry point found, sorry.': continue # All other warnings will be printed if len(warnline) > 0: print "** DMI WARNING ** %s" % warnline dmidecode.clear_warnings()
# this does not change, we can cache it _dmi_data = None _dmi_not_available = 0 def dmi_warnings(): if not hasattr(dmidecode, 'get_warnings'): return None return dmidecode.get_warnings() dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() log = up2dateLog.initLog() log.log_debug("Warnings collected during dmidecode import: %s" % dmi_warn) def _initialize_dmi_data(): """ Initialize _dmi_data unless it already exist and returns it """ global _dmi_data, _dmi_not_available if _dmi_data is None: if _dmi_not_available: # do not try to initialize it again and again if not available return None else: dmixml = dmidecode.dmidecodeXML() dmixml.SetResultType(dmidecode.DMIXML_DOC) # Get all the DMI data and prepare a XPath context
def log_warnings(self): dmiwarnings = dmidecode.get_warnings() if dmiwarnings: log.warn(_("Error reading system DMI information: %s"), dmiwarnings) dmidecode.clear_warnings()
except ImportError: subscription_manager_available = False # this does not change, we can cache it _dmi_data = None _dmi_not_available = 0 def dmi_warnings(): if not hasattr(dmidecode, 'get_warnings'): return None return dmidecode.get_warnings() dmi_warn = dmi_warnings() if dmi_warn: dmidecode.clear_warnings() log = up2dateLog.initLog() log.log_debug("Warnings collected during dmidecode import: %s" % dmi_warn) def _initialize_dmi_data(): """ Initialize _dmi_data unless it already exist and returns it """ global _dmi_data, _dmi_not_available if _dmi_data is None: if _dmi_not_available: # do not try to initialize it again and again if not available return None else : dmixml = dmidecode.dmidecodeXML() dmixml.SetResultType(dmidecode.DMIXML_DOC) # Get all the DMI data and prepare a XPath context try:
def log_warnings(self, dmidecode): dmiwarnings = dmidecode.get_warnings() if dmiwarnings: log.warning(f"Warnings while reading system DMI information:\n{dmiwarnings}") dmidecode.clear_warnings()
def print_warnings(): warn = dmidecode.get_warnings() if warn: print("### WARNING: %s" % warn) dmidecode.clear_warnings()
def print_warnings(): "Simple function, dumping out warnings with a prefix if warnings are found and clearing warning buffer" warn = dmidecode.get_warnings() if warn: print("### WARNING: %s" % warn) dmidecode.clear_warnings()
========== ============ Parameter Description ========== ============ item Path to the item to decode. data Optional external data to parse. ========== ============ ``Return``: String """ return None # Re-define dmi_system depending on capabilities try: import dmidecode dmidecode.clear_warnings() #@UndefinedVariable def dmi_system(item, data=None): if not data: data = dmidecode.system() #@UndefinedVariable dmidecode.clear_warnings() #@UndefinedVariable item = item.lower() for key, value in data.items(): if item == key.lower(): return value.decode('utf-8') if isinstance(value, dict) and value: value = dmi_system(item, value) if value: return value