3 \�me � @ sd d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl m Z mZ e je �ZdZeddd g�Zd:ej_ed d�edd �edd�edd�edd�edd�edd�edd�edd�edd�edd�ed d!�ed"d#�ed$d%�ed&d'�ed(d)�ed*d+�d,�Zeee d-�d.d/�Zeee d-�d0d1�Zeeee d2�d3d4�Zeee d-�d5d6�Zeed7�d8d9�ZdS );� N)� namedtuple)�Optional)�subp)�is_container� is_FreeBSDz/sys/class/dmi/id�KernelNames�linux�freebsdZboard_asset_tagzsmbios.planar.tagZboard_vendorzsmbios.planar.makerZ board_namezsmbios.planar.productZboard_serialzsmbios.planar.serialZ board_versionzsmbios.planar.versionZ bios_datezsmbios.bios.reldateZbios_vendorzsmbios.bios.vendorZbios_versionzsmbios.bios.versionZchassis_asset_tagzsmbios.chassis.tagZchassis_vendorzsmbios.chassis.makerZchassis_serialzsmbios.chassis.serialZchassis_versionzsmbios.chassis.versionZ sys_vendorzsmbios.system.makerZproduct_namezsmbios.system.productZproduct_serialzsmbios.system.serialZproduct_uuidzsmbios.system.uuidZproduct_versionzsmbios.system.version)zbaseboard-asset-tagzbaseboard-manufacturerzbaseboard-product-namezbaseboard-serial-numberzbaseboard-versionzbios-release-datezbios-vendorzbios-versionzchassis-asset-tagzchassis-manufacturerzchassis-serial-numberzchassis-versionzsystem-manufacturerzsystem-product-namezsystem-serial-numberzsystem-uuidzsystem-version)�key�returnc C s� t j| �}|dks|jdkr dS djt|j�}tjd|� tjj |�sVtjd|� dS y"t |d��}|j� }W dQ R X W n tk r� tjd|� dS X |dt |�d d kr�d }y|jd�j� S tk � r� } ztjd|||� W Y dd}~X nX dS ) z/ Reads dmi data from /sys/class/dmi/id Nz{0}/{1}zquerying dmi data %szdid not find %s�rbzCould not read %s� �� � � �utf8z-utf-8 decode of content (%s) in %s failed: %s)�DMIDECODE_TO_KERNEL�getr �format�DMI_SYS_PATH�LOG�debug�os�path�exists�open�read�PermissionError�len�decode�strip�UnicodeDecodeError�error)r �kmapZdmi_key_path�fpZkey_data�e� r&