a
    ©!cå  ã                   @   s®   d dl mZ d dl mZ ddlmZ d dlmZ d dlZd dl	Zd dl
Z
dd„ Zd	d
„ Zdd„ Zedddddddddddddddddddd d!d"d#d$d%œƒZd&d'„ Zd(d)„ ZdS )*é    )Úabsolute_import)Úunicode_literalsé   )Útransaction)Úis_py3bytesNc                 C   sœ  t j| d�}| tjtjB  ¡ tjjD �]l}tj	j
r@t|dƒ}z| d|¡}W n> ttjfyŽ } z tj dt|ƒ ¡‚W Y d}~n
d}~0 0 t|ƒsšq(zt|ƒ}W n" tyÈ   d}tj |¡‚Y n0 |d }zŽz|tj  |¡}W n* t�y   |tj  | d¡¡}Y n0 |tj | }	|tj | }
|	tjk�r^|
�r^|d	 || d¡fv�r^|
}W n tttf�yz   Y n0 t|ƒ�r�t|dƒ}|  S dS )
z-Calculate the release version for the system.)Úrootúutf-8Zprovidesz	Error: %sNz:Error: rpmdb failed to list provides. Try: rpm --rebuilddbÚversionÚutf8Úname)r   ÚinitReadOnlyTransactionZpushVSFlagsÚrpmZ_RPMVSF_NOSIGNATURESZ_RPMVSF_NODIGESTSÚdnfÚconstZDISTROVERPKGZpycompZPY3ÚbytesZdbMatchÚ	TypeErrorÚerrorÚ
exceptionsÚErrorÚstrÚlenÚnextÚStopIterationZRPMTAG_PROVIDENAMEÚindexÚ
ValueErrorÚdecodeZRPMTAG_PROVIDEFLAGSZRPMTAG_PROVIDEVERSIONZRPMSENSE_EQUALÚKeyErrorÚ
IndexErrorr   )ZinstallrootÚtsZdistroverpkgÚidxÚeÚhdrÚmsgZ
releaseverZoffÚflagZver© r$   ú4/usr/lib/python3.9/site-packages/dnf/rpm/__init__.pyÚdetect_releasever   sB    
*

r&   c                 C   sŠ   t  ¡ }t| ƒ�f}| ¡ }z| |¡}W n: tjyb } z tj 	d 
|| ¡¡‚W Y d}~n
d}~0 0 |W  d  ƒ S 1 s|0    Y  dS )zReturn RPM header of the file.z
{0}: '{1}'N)r   r   ÚopenÚfilenoZhdrFromFdnor   r   r   r   r   Úformat)Úpathr   ÚpackageZfdnor!   r    r$   r$   r%   Ú_headerI   s    
*r,   c                    s   ‡ fdd„ˆ D ƒS )Nc                    s    i | ]}ˆ | D ]
}||“qqS r$   r$   )Ú.0ÚkÚv©Zdctr$   r%   Ú
<dictcomp>V   ó    z_invert.<locals>.<dictcomp>r$   r0   r$   r0   r%   Ú_invertU   s    r3   )Úaarch64)
ÚalphaZalphaev4Z	alphaev45Zalphaev5Z	alphaev56Zalphaev6Z	alphaev67Z	alphaev68Zalphaev7Z
alphapca56)Z	armv5tejlZarmv5telZarmv5tlZarmv6lZarmv7lZarmv8l)Zarmv6hlZarmv7hlZarmv7hnlZarmv8hl)Úi386ZathlonZgeoder6   Zi486Zi586Zi686)Úia64)Úmips)Úmipsel)Úmips64)Úmips64el)Úloongarch64)Únoarch)Úppc)Úppc64Zppc64iseriesZppc64p7Zppc64pseries)Úppc64le)Úriscv32)Úriscv64)Úriscv128)Ús390)Ús390x)Úsh3)Úsh4Zsh4a)ÚsparcZsparc64Zsparc64vZsparcv8Zsparcv9Zsparcv9v)Úx86_64Zamd64Zia32e)r4   r5   ZarmZarmhfpr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   c                 C   s   t |  S )N)Ú_BASEARCH_MAP)Zarchr$   r$   r%   Úbasearchv   s    rK   c                 C   s   | | }t |ƒrt|dƒ}|S )z€
    Returns value of rpm_hdr[key] as a string. Rpm has switched from bytes to str
    and we need to handle both properly.
    r   )r   r   )Zrpm_hdrÚkeyÚvaluer$   r$   r%   Ú	getheader{   s    
rN   )Z
__future__r   r   Ú r   Z
dnf.pycompr   Z	dnf.constr   Zdnf.exceptionsr   r&   r,   r3   rJ   rK   rN   r$   r$   r$   r%   Ú<module>   sJ   ,æ