o
    VAf                     @   s   d dl Z ddlmZ dZG dd deZedkrSe Zedej	 ed	ej
 ed
ej edej edej edej edej edej edej dS dS )    N   )systemz/proc/cpuinfoc                   @   s   e Zd ZdZi Zdd Zedd Zedd Z	edd	 Z
ed
d Zedd Zedd Zedd Zedd Zedd Zedd Zedd ZdS )CPUz
		A class that represents the first CPU in a system.

		We get all information form the first CPU (or core) and assume that
		all other ones are equal.
	c                 C   s   |   | _dS )zD
			Initialize this class by reading all data from /proc/cpuinfo.
		N)read_cpuinfo_CPU__cpuinfoself r	   1/usr/lib/python3.10/site-packages/fireinfo/cpu.py__init__%   s   zCPU.__init__c                 C   s   t  S )N)r   ZSystemr   r	   r	   r
   r   +   s   z
CPU.systemc                  C   sr   i } t t}	 | }|sn%z
|dd\}}W n	 ty!   Y nw | dd}| }|| |< q|  | S )zT
			Read information from PROC_CPUINFO and store
			it into a dictionary cpuinfo.
		T:r    _)openPROC_CPUINFOreadlinesplit
ValueErrorstripreplaceclose)Zcpuinfoflinekeyvalr	   r	   r
   r   /   s"   zCPU.read_cpuinfoc              	   C   s>   d}dD ]}z| j | }W q ty   Y qw |rt|S dS )z'
			Return the bogomips of this CPU.
		N)bogomipsZBogoMIPS)r   KeyErrorfloat)r   r   r   r	   r	   r
   r   M   s   zCPU.bogomipsc                 C   .   z
t | jd }W |S  ty   d}Y |S w )z'
			Return the model id of this CPU.
		modelNintr   r   )r   r   r	   r	   r
   r   ]      z	CPU.modelc              	   C   s0   dD ]}z| j | W   S  ty   Y qw dS )z+
			Return the model string of this CPU.
		)Z
model_nameZ	ProcessorN)r   r   )r   r   r	   r	   r
   model_stringi   s   zCPU.model_stringc                 C   sB   z| j d }W |S  ty    | jjdrd}Y |S d}Y |S w )z,
			Return the vendor string of this CPU.
		Z	vendor_idZarmZARM )r   r   r   Zarch
startswith)r   vendorr	   r	   r
   r&   t   s   z
CPU.vendorc                 C   r   )z*
			Return the stepping id of this CPU.
		steppingNr    )r   r'   r	   r	   r
   r'      r"   zCPU.steppingc                 C   s8   z
| j d }W | S  ty   | j d }Y | S w )z$
			Return all flags of this CPU.
		flagsZFeatures)r   r   r   )r   r(   r	   r	   r
   r(      s   z	CPU.flagsc                 C   r   )z-
			Return the speed (in MHz) of this CPU.
		Zcpu_MHzr   )r   r   r   )r   speedr	   r	   r
   r)      r"   z	CPU.speedc                 C   r   )z(
			Return the family id of this CPU.
		Z
cpu_familyNr    )r   familyr	   r	   r
   r*      r"   z
CPU.familyc                 C   s
   t dS )z$
			Count number of CPUs (cores).
		SC_NPROCESSORS_ONLN)ossysconfr   r	   r	   r
   count   s   
z	CPU.countN)__name__
__module____qualname____doc__r   r   propertyr   staticmethodr   r   r   r#   r&   r'   r(   r)   r*   r.   r	   r	   r	   r
   r      s4    










r   __main__zVendor:zModel:z	Stepping:zFlags:z	Bogomips:zSpeed:zFamily:zCount:zModel string:)r,   r$   r   r   objectr   r/   cprintr&   r   r'   r(   r   r)   r*   r.   r#   r	   r	   r	   r
   <module>   s"    !