def is_memory(dictionary): "Checks if given dictionary looks like memory component" try: bare_validate_paths(dictionary, ['properties', 'Memory size']) except InvalidPathError: return False return True
def is_cpu(dictionary): "Checks if given dictionary looks like cpu component" try: bare_validate_paths(dictionary, ['Product Asset Tag']) except InvalidPathError: return False return True
def is_pwr(dictionary): "Checks if given dictionary looks like a power-supply component" try: bare_validate_paths(dictionary, ['Board Extra']) except InvalidPathError: return False desc = dictionary['Board Extra'].lower() if re.match(r'.*?psu.*?', desc): return True return False
def extract_flat_props(dictionary, path, props): "Extracts the props in the list from the dictionary, which are at given path" info = {} for prop in props: try: working_path = path.copy() working_path.append(prop) bare_validate_paths(dictionary, working_path) info[prop] = extract_by_path( dictionary, working_path).strip() # Noticed some unstripped values in JSON except InvalidPathError: # Going to be a none-value pass return info
def cpus_temperatures(sys, _chass): cpu_temps = {} for cpu_nr in range(constants.MAX_PROCESSORS): cpu_temp_path = [ 'sensors', f'cpu{cpu_nr}_temp', 'reading', 'value' ] try: bare_validate_paths(sys, cpu_temp_path) cpu_temps[f'cpu_{cpu_nr}'] = {} cpu_temps[f'cpu_{cpu_nr}']['temp'] = extract_by_path( sys, cpu_temp_path) except InvalidPathError: # Going to mean just lack of value pass return cpu_temps
def is_fan(dictionary): "Checks whether given sensor is a fan" try: bare_validate_paths(dictionary, ['sensor_info', 'sensor_type']) bare_validate_paths(dictionary, ['sensor_info', 'name']) bare_validate_paths(dictionary, ['reading', 'value']) # just to be sure except InvalidPathError: return False return dictionary['sensor_info']['sensor_type'] == 'fan'