Your IP : 216.73.216.14


Current Path : /usr/lib/python3/dist-packages/UpdateManager/Core/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/UpdateManager/Core/__pycache__/MyCache.cpython-38.pyc

U

�c�G�@sbddlmZmZddlZe�dde�ddlZddlZddlZddl	Z	z(ddl
mZddlm
Z
ddlmZWn0ek
r�ddlmZm
Z
ddlmZYnXzdd	lmZWn ek
r�dd	lmZYnXddlZddlZddlZddlZdd
lmZzddlmZWnek
�r(dZYnXdZd
Z e dZ!Gdd�de"�Z#Gdd�dej$j%�Z%dS)�)�absolute_import�print_functionN�ignorezapt API not stable yet)�	HTTPError)�urlopen)�urlsplit)rr)�
BadStatusLine)�gettext)�	Launchpadz/var/lib/synaptic/preferencesz.https://changelogs.ubuntu.com/changelogs/pool/z%s/%s/%s/%s_%s/%sc@seZdZdZdS)�HttpsChangelogsUnsupportedErrorz� https changelogs with credentials are unsupported because of the
        lack of certitifcation validation in urllib2 which allows MITM
        attacks to steal the credentials
    N)�__name__�
__module__�__qualname__�__doc__�rr�</usr/lib/python3/dist-packages/UpdateManager/Core/MyCache.pyr9src@s�eZdZdZd,dd�Zdd�Zdd�Zd	d
�Zedd��Z	ed
d��Z
dd�Zedd��Zdd�Z
dd�Zdd�Zdd�Zd-dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZdS).�MyCacheZUbuntuNcstj�|||�||_t|j�dks(t�|��r4t�|��i|_	i|_
|jjdkr\|�
�|jjdkrt|jjdksxt�d|_tj�d�}|r�t�dd�dd�|D��d�|_tjdd	gd
d����t�dd��fdd�|D��d�|_nd|_d|_dS)
NrzAPT::VersionedKernelPackages�(�|cSsg|]}d|�qS)�^r��.0�prrr�
<listcomp>_sz$MyCache.__init__.<locals>.<listcomp>�)�unamez-rT)Zuniversal_newlinescs.g|]&}|�d�s"d|d�n�|�qS)z.*r)�
startswithr�Zrunning_kernel_versionrrrcs��)�aptZCache�__init__�rootdir�lenZreq_reinstall_pkgs�AssertionError�_dpkgJournalDirty�
_initDepCache�all_changes�all_news�	_depcache�broken_count�saveDistUpgrade�	del_count�	launchpad�apt_pkg�configZ
value_list�re�compile�joinZversioned_kernel_pkgs_regexp�
subprocessZcheck_output�rstripZrunning_kernel_pkgs_regexp)�selfZprogressr Zapt_versioned_kernel_pkgsrrrrEsF
��
���


���
zMyCache.__init__cCs>tj�tj�d��d}t�|�D]}t�d|�r"dSq"dS)z`
        test if the dpkg journal is dirty
        (similar to debSystem::CheckUpdates)
        zDir::State::statusz/updatesz[0-9]+TF)	�os�path�dirnamer,r-Z	find_file�listdirr.�match)r3�d�frrrr#js
��zMyCache._dpkgJournalDirtycCs0|j��tj�t�r"|j�t�|j��dS�N)r'Zread_pinfiler4r5�exists�SYNAPTIC_PINFILEZinit�r3rrrr$vs
zMyCache._initDepCachecCs|��dSr;)r$r>rrr�clearsz
MyCache.clearcCs,t�|j�}t��}|�||j|j�|jS)z< get the size of the packages that are required to download )r,ZPackageManagerr'ZAcquireZget_archivesZ_listZ_recordsZfetch_needed)r3ZpmZfetcherrrr�required_download�szMyCache.required_downloadcCs|jjSr;)r'Z
inst_countr>rrr�
install_count�szMyCache.install_countcCs|jjSr;)r'�
keep_countr>rrrrB�szMyCache.keep_countcCs|jjSr;)r'r*r>rrrr*�szMyCache.del_countcCsR|D]H}|sqd}|D]*}|j|jjks<t�|j|j|j�sd}q|rdSqdS)z<Return True if any of the dependencies in deps match target.TF)�name�package�	shortnamer,Z	check_dep�versionZrelation)r3�targetZdepsZdep_orr8Zbase_deprrr�_check_dependencies�s ��zMyCache._check_dependenciescCsl|j}|sdS|D]T}|j}|dk	r|�||�d��r|�||�d��rt�d|jj|jf�dSqdS)NFZ	ConflictsZReplacesz*%s Conflicts/Replaces %s; allowing removalT)�	installed�	candidaterHZget_dependencies�logging�inforDrE)r3�pkgrGZcpkgrJrrr�find_removal_justification�s.�����z"MyCache.find_removal_justificationcCs�|j�d�|jj}|dkrVdd�|D�}|t|�ks:t�|D]}|�|�r>|d8}q>|dkr�|��|jjdkr~|jjdks�t�n|jjdks�t�|j��|S)z@ this functions mimics a upgrade but will never remove anything TrcSsg|]}|jr|�qSr)Z
marked_delete)rrMrrrr�sz+MyCache.saveDistUpgrade.<locals>.<listcomp>�)r'Zupgrader*r!r"rNr?r()r3ZwouldDeleteZdeleted_pkgsrMrrrr)�s 


�
zMyCache.saveDistUpgradecCs,|�d�}t|�dkr(d�|dd��}|S)z strip of the epoch �:rO�N)�splitr!r0)r3ZverstrZ
vers_no_epochrrr�_strip_epoch�s
zMyCache._strip_epochFcCs�||}|jj}d}|jj�|j�j}|jj}	|�|	�}
|�	d�}t
|�dkrV|d}|d}|�d�rtd|d}|r~|}
nt|||||
|f}
t
|
�}|jdkr�|jr�td��t|
�}d	}d
t�|�}|���dd�}|d	kr�q�t�||�}|�r�t|jd
d�}|�r(d|k�r(|�	dd�d}|�d�}|�rRd|k�rR|�	dd�d}|�rv|�r�t�||�dk�r��q�n|�r�t�||�dk�r��q�||}q�|S)z* helper that fetches the file in question �main�/rOr�lib�ZhttpszKhttps locations with username/password are notsupported to fetch changelogsrQz^%s \((.*)\)(.*)$zUTF-8�replacerFNrP)rJ�source_nameZ_pcacher'Zget_candidate_verZ_pkg�section�source_versionrSrRr!r�CHANGELOGS_URIrZschemeZusernamerrr.�escape�readline�decoder8�getattrrI�groupr,Zversion_compare)r3rC�fnameZstrict_versioning�changelogs_urirM�srcpkgZsrc_sectionrZ�srcver_epoch�srcverZ
split_section�prefix�uri�res�	changelogZalllinesZregexp�liner8rIZchangelogverrrr�_get_changelog_or_news�sp



��
������
zMyCache._get_changelog_or_newsc	Cs�tst�d�dS||j}|jD]B}t|�jdkr6q"t�d|�}|dk	r"|�	d�|�	d�}}qtq"t�
d�dS|jdkr�tjdd	d
d�|_|jj
jd||fd
�}|dkr�t�
d�dS|j|jd|jd�}|s�t�
d�dS|d��S)zbReturn the changelog URI from the Launchpad API

        Return None in case of an error.
        z9Launchpadlib not available, cannot retrieve PPA changelogNzppa.launchpad.netzhttp.*/(.*)/(.*)/ubuntu/.*rO�z)Unable to find a valid PPA candidate URL.zupdate-managerZ
productionZdevel)rFz
~%s/ubuntu/%s)Z	referencez6Unable to retrieve the archive from the Launchpad API.T)rYZexact_matchrFz;No published sources were retrieved from the Launchpad API.r)r
rKZwarningrJZurisrZhostnamer.�searchra�errorr+Zlogin_anonymouslyZarchivesZgetByReferenceZgetPublishedSourcesrYr[ZchangelogUrl)	r3rCZcdtrhr8�userZppa�archiveZspphsrrr�_extract_ppa_changelog_uri)s@




�
�
�
z"MyCache._extract_ppa_changelog_uricCs�||}|jj}|dkrdS|jj�d�}|s2dS|�d�d��}d|krb|�d�d�d�}n|jj}|�d�d}|d||fS)NZSourcerrrOrrUz/%s_%s.changelog)	rJrh�record�getrR�stripr2r[�
rpartition)r3rCrM�deb_uriZsrcrecrdrfZbase_urirrr�+_guess_third_party_changelogs_uri_by_sourceWsz3MyCache._guess_third_party_changelogs_uri_by_sourcecCs,||}|jj}|r(d|�dd�dSdS)z` guess changelogs uri based on ArchiveURI by replacing .deb
            with .changelog
        z%s.changelog�.rOrN)rJrh�rsplit)r3rCrMrwrrr�+_guess_third_party_changelogs_uri_by_binaryhs
z3MyCache._guess_third_party_changelogs_uri_by_binarycCs:|�|�|�|�z|��Wntk
r4YnXdSr;)�get_news�
get_changelog�release�	Exception)r3rC�lockrrr�get_news_and_changelogts

zMyCache.get_news_and_changelogcCs<z|�|dd�}Wntk
r(YdSX|r8||j|<dS)z7 get the NEWS.Debian file from the changelogs location zNEWS.DebianTN)rlrr&)r3rCZnewsrrrr||szMyCache.get_newsc
Csd}|D]D}|j�d�rz|�|�}WqNWqtk
rJt�d�YqXq|�|�}|�|�}d}|||fD]|}|rpz&|�|dd|�}	|j	||	7<Wqpt
tfk
r�td�}Yqpt
ttjfk
r�t�d�td�}YqpXqp|j	||7<dS)	NzLP-PPA-z'Unable to connect to the Launchpad API.rQrjFzAThis update does not come from a source that supports changelogs.zerror on changelog fetching�OFailed to download the list of changes. 
Please check your Internet connection.)�originrrrrrKZ	exceptionr{rxrlr%rr�_�IOErrorr�socketro)
r3rC�originsZchangelogs_uri_ppar�Zchangelogs_uri_binaryZchangelogs_uri_sourceZ
error_messagercrjrrr�(_fetch_changelog_for_third_party_package�sH

�����
�z0MyCache._fetch_changelog_for_third_party_packagec
Cs"||jj}td�|t||jdd�||jjf|j|<|jdd�|D�kr^|�||�dS||jj	}||jj
�dd�}z,|�|d�}t
|�d	kr�td
�||f}Wn`tk
r�td�||f}Yn>tttjfk
�r
}ztd|�td
�}W5d}~XYnX|j||7<dS)z4 get the changelog file from the changelog location zFChanges for %s versions:
Installed version: %s
Available version: %s

rFNcSsg|]
}|j�qSr)r�)r�orrrr�sz)MyCache.get_changelog.<locals>.<listcomp>rPz%3Arjrz�The changelog does not contain any relevant changes.

Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog
until the changes become available or try again later.z�The list of changes is not available yet.

Please use http://launchpad.net/ubuntu/+source/%s/%s/+changelog
until the changes become available or try again later.zcaught exception: r�)rJr�r�r`rIrFr%�CHANGELOG_ORIGINr�rYr[rXrlr!rr�rr�ro�print)r3rCr�rdrerj�errrr}�s2
��
��
zMyCache.get_changelog)N)FN)rr
rr�rr#r$r?�propertyr@rArBr*rHrNr)rSrlrrrxr{r�r|r�r}rrrrrAs4
%	


�
W.	&r)&Z
__future__rr�warnings�filterwarnings�
FutureWarningrr,rKr4Zurllib.errorrZurllib.requestrZurllib.parser�ImportErrorZurllib2ZurlparseZhttp.clientrZhttplibr�r1r.ZDistUpgrade.DistUpgradeCacheZDistUpgrader	r�Zlaunchpadlib.launchpadr
r=ZCHANGELOGS_POOLr\rrZDistUpgradeCacherrrrr�<module>s>