
    .h2                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ  G d d      Ze	dk(  r e
ej                                yy)    )annotationsN)Pathc                  <    e Zd ZdZedd       Zedd       ZddZy)CPUInfoa  
    Provide cross-platform CPU brand and model information.

    Query platform-specific sources to retrieve a human-readable CPU descriptor and normalize it for consistent
    presentation across macOS, Linux, and Windows. If platform-specific probing fails, generic platform identifiers are
    used to ensure a stable string is always returned.

    Methods:
        name: Return the normalized CPU name using platform-specific sources with robust fallbacks.
        _clean: Normalize and prettify common vendor brand strings and frequency patterns.
        __str__: Return the normalized CPU name for string contexts.

    Examples:
        >>> CPUInfo.name()
        'Apple M4 Pro'
        >>> str(CPUInfo())
        'Intel Core i7-9750H 2.60GHz'
    c                    	 t         j                  dk(  rJt        j                  g ddd      j                  j                         } | r"t        j                  |       S t         j                  j                  d      rot        d      }|j                         r|j                  d      j                         D ]0  }d	|v st        j                  |j                  d
d      d         c S  nt         j                  j                  d      r`	 ddl}|j                  |j                   d      5 }|j#                  |d      \  }}|rt        j                  |      cddd       S 	 ddd       t        j&                         xs5 t)        t        j*                         dd      xs t        j,                         } t        j                  | xs d      S # 1 sw Y   mxY w# t$        $ r Y {w xY w# t$        $ rJ t        j&                         xs t        j,                         xs d} t        j                  | xs d      cY S w xY w)zDReturn a normalized CPU model string from platform-specific sources.darwin)sysctlz-nzmachdep.cpu.brand_stringT)capture_outputtextlinuxz/proc/cpuinfoignore)errorsz
model name:   winr   Nz.HARDWARE\DESCRIPTION\System\CentralProcessor\0ProcessorNameString	processor zUnknown CPU)sysplatform
subprocessrunstdoutstripr   _clean
startswithr   exists	read_text
splitlinessplitwinregOpenKeyHKEY_LOCAL_MACHINEQueryValueEx	Exceptionr   getattrunamemachine)splinewrkval_s          S/var/www/html/ai-service/venv/lib/python3.12/site-packages/ultralytics/utils/cpu.pynamezCPUInfo.name    s    	6||x'NN@QU\`&  ">>!,,((1)88: !8 < G G I I'4/#*>>$**S!2DQ2G#HHI ((/	'B$9$9;lm 7qr!#4I!JQ#*>>##67 77 ""$h0@+r(RhV^VfVfVhA>>!"4}557 7 !   	6""$@(8(8(:@bA>>!"4}55	6si   AG+ A!G+ )G+ +!G+  G -,G	G $G ,A#G+ GG 	G(%G+ 'G((G+ +AH>=H>c                    t        j                  dd| j                               } | j                  dd      j                  dd      j                  dd      j                  dd      j                         } t        j                  d| t         j
                        }|r%|j                  d	       d|j                  d
       S t        j                  d| t         j
                        }|r%|j                  d	       d|j                  d
       S | S )z3Normalize and prettify a raw CPU descriptor string.z\s+ z(TM)r   z(tm)z(R)z(r)z%(Intel.*?i\d[\w-]*) CPU @ ([\d.]+GHz)r      z((AMD.*?Ryzen.*?[\w-]*) CPU @ ([\d.]+GHz))resubr   replacesearchIgroup)r)   ms     r0   r   zCPUInfo._cleanE   s     FF63	*IIfb!))&"5==eRHPPQVXZ[aacII>244Hggaj\1771:,//IIA1bddKggaj\1771:,//    c                "    | j                         S )zReturn the normalized CPU name.)r1   )selfs    r0   __str__zCPUInfo.__str__T   s    yy{r<   N)returnstr)r)   rA   r@   rA   )__name__
__module____qualname____doc__staticmethodr1   r   r?    r<   r0   r   r      s5    & "6 "6H  r<   r   __main__)
__future__r   r   r5   r   r   pathlibr   r   rB   printr1   rG   r<   r0   <module>rL      sC    #  	  
 J JZ z	',,. r<   