HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/aptsources/__pycache__/distro.cpython-38.pyc
U

&��c�\�@s�ddlZddlZddlZddlZddlZddlmZddlmZGdd�de	�Z
Gdd�de�ZGdd	�d	e�Z
Gd
d�de�ZGdd
�d
e�Zdd�Zdd�ZGdd�d�Zddddgfdd�ZdS)�N)�ElementTree)�gettextc@seZdZdS)�NoDistroTemplateExceptionN)�__name__�
__module__�__qualname__�rr�3/usr/lib/python3/dist-packages/aptsources/distro.pyr%src@sleZdZgfdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�DistributioncCs.||_||_||_||_||_d|_d|_dS)z2 Container for distribution specific informations Zdebzdeb-srcN)�id�codename�description�release�is_like�binary_type�source_type)�selfrrr
rrrrr	�__init__+szDistribution.__init__cCs�||_d|_g|_g|_g|_g|_g|_g|_g|_g|_	d|_
g|_d|_d|_
d|_g|_|jjjD]&}|�|j�rj|j|jkrj||_q�qj|jdkr�td|j|jf��g}g}g}g}|jjD�]�}|j�s|�|j��r|j�r|jj�r|�|jj��r|j�d��r6|j�s6|j� |�|�!|j"�n�|j�d��rZ|j�rZ|j� |�n�|j#|j$k�r�|j�s�|j� |�|�!|j"�|� |j�nj|j#|j$k�r�|j�r�|j� |�nF|j#|j%k�r�|j�s�|j� |�n"|j#|j%k�r|j�r|j� |�|js�|j|jj&kr�|j�s8|j#|j$k�r8|j� |�q�|j�s\|j#|j%k�r\|j� |�q�|j� |�q�t'|�|_t'|�|_|�!|�|�!|�t'|�|_t'|�|_	|�(�dS)zf
        Find the corresponding template, main and child sources
        for the distribution
        NF�z7Error: could not find a distribution template for %s/%s�cdrom:))�sourceslist�source_template�
child_sources�main_sourcesZdisabled_sourcesZ
cdrom_sourcesZdownload_comps�
enabled_comps�cdrom_comps�
used_media�get_source_code�source_code_sources�default_server�main_server�nearest_server�used_serversZmatcherZ	templates�is_codename�nameZdistributionrrr�listZinvalid�dist�templateZofficial�uri�
startswithZdisabled�append�extend�comps�typerrZchildren�set�get_mirrors)rrr'Zmediar,rr�sourcerrr	�get_sources7s�
�

��
�����������
�
�





zDistribution.get_sourcesNc
	Cs�|jj|_|jD]}|�d�s|j�|�qt|j�dkrD|j|_	n|jdj
|_	i|_d}tj
�|��rt|d�}t|dd�dkr�|j|_|�d�}|D]v}z|jd}Wntk
r�|jd	}YnXz|jd
}Wntk
r�|jd}YnXt�d|�|j|��<q�d|_d|_tjd
dd�}	|	�d�}
|	�d�}|dk�rRt|	�}|	|
d|���}|�rv|||_||jk�r�|j||_||_dS)zR
        Provide a set of mirrors where you can get the distribution from
        rrz%/usr/share/xml/iso-codes/iso_3166.xml)�file�iterNZiso_3166_entryZcommon_namer$Zalpha_2_codeZalpha_3_code�iso_3166ZLANGZen_UK)�default�_�.����)r�base_urir rr)r"r*�lenrrr(�	countries�os�path�existsr�getattrZgetiteratorr3Zattrib�KeyErrorr�dgettext�lower�country�country_code�getenv�findr!)
r�mirror_templateZmedium�fnameZet�itZelmZdescr�codeZlocale�a�zrErrr	r/�sN





�



zDistribution.get_mirrorscCsjd}|�d�}|�d�}|dkr<|dkr<||td�|�}||jkrXtd�|j|Sd|�d�SdS)zu Try to get a human readable name for the main mirror of a country
            Customize for different distributions Nz://z.archive.ubuntu.comr8�
Server for %s�%s�/ )rGr;r<r6�rstrip�r�serverrD�iZlirrr	�_get_mirror_name�s


zDistribution._get_mirror_namecCs�dd�}g}t|j�dks:t|j�dkrt||jd|j�rt|�td�|jdg�|jrp|�|�|j�|jdg��n8t|j�dkr�||jd|j�s�|�td�|jdg�|jd}|jr�|||j�s�|�|�|j�|jdg�|r�|�|�|�|dg�n�t|j�dk�r�|�td�|jdg�|j�rD|�|�|j�|jdg�|�td�d	dg�|jD]L}|�|�|dg}|||j��s^|||j��r��q^n||k�r^|�|��q^|S)
z- Return a list of used and suggested servers cSst�|�d�|�d��S)zl Helper function that handles comaprision of mirror urls
                that could contain trailing slashesrP)�re�match�striprQ)Zmir1Zmir2rrr	�compare_mirrors�sz5Distribution.get_server_list.<locals>.compare_mirrorsr9rzMain serverTFzCustom serversN)r;r"r r*r6r!rU)rrYZmirrorsrSZmirror_entryrrr	�get_server_list�sV���
�
��

�
zDistribution.get_server_listrc
Cs�|dkr|j}|dkr|j}|dkr.t|j�}|dkr<|j}|j�|||||�}|jr�||jkr�|jj|j|||||j	|jj�
|�dd�dS)z3
        Add distribution specific sources
        Nr9)r2�pos)rrr%rrr�addrrr2�index)rr-r(r&r,ZcommentZ
new_sourcerrr	�
add_sources&
�zDistribution.add_sourcecCsXt|g�}|jD].}|jjD] }|j|kr|jr|�|j�qq|D]}|�|�qDdS)z�
        Enable a component in all main, child and source code sources
        (excluding cdrom based sources)

        comp:         the component that should be enabled
        N)r.rr'Z
componentsr$Zparent_componentr\�_enable_component)r�compr,r0�crrr	�enable_component%s

zDistribution.enable_componentc	sZ�fdd�}g}|�|j�|�|j�i}i}|D]B}|j|jkr4|j|krZt�||j<|jD]}||j�|�q`q4|j	D]B}|j|j
kr~|j|kr�t�||j<|jD]}||j�|�q�q~t|j�dkr�|jd�gd�n*|D]}|||�q�|j	D]}|||�q�|j
�rVt|j	�dk�r>|j|j
d�gd�n|j	D]}|||��qDdS)Ncs@|j|krdS�||jkr dS|j���||j���dS)z�
            Check if we already added the component to the repository, since
            a repository could be splitted into different apt lines. If not
            add the component
            N)r&r,r*r\)r0�comps_per_dist�r`rr	�add_component_only_once7s
z?Distribution._enable_component.<locals>.add_component_only_oncer9rO)r,)r-r,)r+rrr-rr&r.r,r\rrr;r^r)	rr`re�sourcesrcZcomps_per_sdist�srar0rrdr	r_5s:






zDistribution._enable_componentcCs�g}|�|j�|�|j�|�|j�||jkrBg}|�|j�|D]4}||jkrF|j�|�t|j�dkrF|j�|�qFdS)zx
        Disable a component in all main, child and source code sources
        (excluding cdrom based sources)
        r9N)	r+rrrrr,�remover;r)rr`rfr0rrr	�disable_componentss

zDistribution.disable_componentcs��fdd�}g}g}|�_�jD]}||||�q �jD]*}|jjdksV|jj|jkr8||||�q8�jD]}||||�qjdS)zN Change the server of all distro specific sources to
            a given host csd||_|jD]8}|j|j|g|kr0|j�|�q|�|j|j|g�qt|j�dkr`�j�|�dS)Nr9)r(r,r&rhr*r;r)r0r(�seenr`�rrr	�change_server_of_source�s
z;Distribution.change_server.<locals>.change_server_of_sourceN)rrrr'r:r(r)rr(rlZseen_binaryZseen_sourcer0rrkr	�
change_server�s

�
zDistribution.change_servercCs||jkrdSdSdS)z1 Compare a given name with the release codename. TFN)r�rr$rrr	r#�s
zDistribution.is_codename)N)NNNNr)rrrrr1r/rUrZr^rbr_rirmr#rrrr	r
)s ]
93�
>r
c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DebianDistributionz+ Class to support specific Debian features cCs ||jks|jdkrdSdSdS)z� Compare a given name with the release codename and check if
            if it can be used as a synonym for a development releases )Ztesting�unstableTFN)rrrnrrr	r#�szDebianDistribution.is_codenamecCszd}|�d�}|�d�}|dkr<|dkr<||td�|�}||jkrhtd�t�d|j|�����Sd|�d�SdS)	z_ Try to get a human readable name for the main mirror of a country
            Debian specific Nz://ftp.z.debian.orgr8rNr4rOrP)rGr;r<r6rrBrQrRrrr	rU�s



�
z#DebianDistribution._get_mirror_namecCstj|dd�dS)Nz http://ftp.%s.debian.org/debian/�rH�r
r/rkrrr	r/�s�zDebianDistribution.get_mirrorsN)rrr�__doc__r#rUr/rrrr	ro�sroc@seZdZdZdd�ZdS)�UbuntuDistributionz+ Class to support specific Ubuntu features cCstj|dd�dS)Nz$http://%s.archive.ubuntu.com/ubuntu/rqrrrkrrr	r/�s�zUbuntuDistribution.get_mirrorsN�rrrrsr/rrrr	rt�srtc@seZdZdZdd�ZdS)�UbuntuRTMDistributionz/ Class to support specific Ubuntu RTM features cCs|jj|_dS)N)rr:r rkrrr	r/�sz!UbuntuRTMDistribution.get_mirrorsNrurrrr	rv�srvc
Cs�ddlm}m}ddl}ddddd�}z@|d	d
g|d���d}|�d�}|�d
d�|�d�D��Wn<tk
r�}z|j|j	kr�t
�d|�W5d}~XYnX|S)z-Call lsb_release --idrc and return a mapping.r��Popen�PIPENZsid�DebianzDebian GNU/Linux unstable (sid)rp)�Codename�Distributor ID�Description�ReleaseZlsb_releasez-idrc)�stdoutzutf-8css |]}d|kr|�d�VqdS)z:	N)�split)�.0�lrrr	�	<genexpr>�sz_lsb_release.<locals>.<genexpr>�
z#lsb_release failed, using defaults:)�
subprocessrxry�errno�communicate�decode�updater��OSError�ENOENT�logging�warning)rxryr��result�out�excrrr	�_lsb_release�s�
 r�c
Cs�ddlm}m}ddl}zddlm}Wn$tk
rLt�tjtj	�}YnXzN|ddg||dd��
�d}|��D]$}|�d	�rt|�
d
d�dWSqtWn<tk
r�}z|j|jkr�t�d|�W5d}~XYnXdS)
z=Get the current channel from system-image-cli -i if possible.rrwN)�DEVNULLzsystem-image-cliz-iT)r�stderrZuniversal_newlinesz	channel: z: r9z+system-image-cli failed, using defaults: %s)r�rxryr�r��ImportErrorr=�open�devnull�O_RDWRr��
splitlinesr)r�r�r�r�r�)rxryr�r�r�r�r�rrr	�_system_image_channel�s0��
�r�c@s>eZdZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�
_OSReleasez/etc/os-releaseTcCsDi|_d|_tj|_tj�|j�s&dS|��d|_|r@|�	�dS)NFT)
r��validr��OS_RELEASE_FILEr2r=r>�isfile�parse�inject_lsb_compat)rZ
lsb_compatrrr	rsz_OSRelease.__init__cCsd|jd|jd<|jd|jd<|j�d�|jd<|jdsN|j�d�|jd<|j�d�|jd	<dS)
NZIDr|ZPRETTY_NAMEr}ZVERSION_CODENAMEr{ZUBUNTU_CODENAMEZ
VERSION_IDr~)r��getrkrrr	r�s
z_OSRelease.inject_lsb_compatcCsBt|jd�}|D]$}|��}|s"q|j|�dd��q|��dS)N�r�=r9)r�r2rX�parse_entryr��close)r�f�linerrr	r�sz_OSRelease.parsecCs4|�|�}|dkr&t|t�r&|�d�}||j|<dS)N�ID_LIKE� )�parse_value�
isinstance�strr�r�)r�key�valuerrr	r�&s

z_OSRelease.parse_entrycCs"t�|�}t|�dkr|dS|S)Nr9r)�shlexr�r;)rr��valuesrrr	r�.s
z_OSRelease.parse_valueN)T)
rrrZDEFAULT_OS_RELEASE_FILEr�rr�r�r�r�rrrr	r�s

	r�c	Cs|r|r|r|s�t�}g}t�}|jr,|j}t�}|d}|d}|d}|d}|�dg�}|dkr�t�}|dk	r�d|kr�d	}|�d
d�d�dd�d
}|}|}|dkr�t|||||�S|d	kr�t	|||||�S|dkr�t
|||||�St|||||�SdS)z�
    Check the currently used distribution and return the corresponding
    distriubtion class that supports distro specific features.

    If no paramter are given the distro will be auto detected via
    a call to lsb-release
    r|r{r}r~r�ZUbuntuNzubuntu-rtm/z
Ubuntu-RTM�/r9�-rrz)r�r�r�r�r�r��rsplitr�rtrvror
)	rrr
rrZ
os_releaseZ	os_resultZ
lsb_resultZchannelrrr	�
get_distro5s@

�r�)rr�rVr�r=Zxml.etree.ElementTreerZapt_pkgr6�	Exceptionr�objectr
rortrvr�r�r�r�rrrr	�<module>s(5�