HOME


Mini Shell 1.0
DIR: /snap/core20/current/usr/share/subiquity/subiquitycore/__pycache__/
Upload File :
Current File : //snap/core20/current/usr/share/subiquity/subiquitycore/__pycache__/snapd.cpython-38.pyc
U

K��^,�@s�ddlZddlmZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlZe�d�ZGdd�d�ZGd	d
�d
�ZGdd�d�ZGd
d�d�ZGdd�d�ZGdd�d�ZdS)�N)�partial)�
quote_plus�	urlencode)�
run_in_thread)�run_commandzsubiquitycore.snapdc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�SnapdConnectioncCs$||_d�t|��|_t��|_dS)Nzhttp+unix://{}/)�root�formatr�url_base�requests_unixsocketZSession�session)�selfrZsock�r�+/usr/share/subiquity/subiquitycore/snapd.py�__init__'szSnapdConnection.__init__cKs*|r|dt|�7}|jj|j|dd�S)N�?�<)�timeout)rr�getr
)r
�path�argsrrrr,szSnapdConnection.getcKs2|r|dt|�7}|jj|j|t�|�dd�S)Nrr)�datar)rr�postr
�json�dumps�r
r�bodyrrrrr1s�zSnapdConnection.postc	Cs�t�d�tj�|jd�}tj|dd�ttj�|d�d��}|�|�	��W5QRX|jdkrtdd	gdd
dgg}n
dd
gg}|D]}t
|�q�dS)Nz(restarting snapd to pick up proxy configz"etc/systemd/system/snapd.service.dT)�exist_okzsnap_proxy.conf�w�/Z	systemctlz
daemon-reloadZrestartz
snapd.service�sleep�2)�log�debug�osr�joinr�makedirs�open�writeZproxy_systemd_dropinr)r
�proxyZ
dropin_dir�fpZcmds�cmdrrr�configure_proxy8s
�
�
zSnapdConnection.configure_proxyN)�__name__�
__module__�__qualname__rrrr,rrrrr&src@s$eZdZdd�Zdd�Zdd�ZdS)�_FakeFileResponsecCs
||_dS�N)r)r
rrrrrLsz_FakeFileResponse.__init__cCsdSr1r�r
rrr�raise_for_statusOsz"_FakeFileResponse.raise_for_statusc
Cs,t|j��}t�|�W5QR�SQRXdSr1)r'rr�load)r
r*rrrrRsz_FakeFileResponse.jsonN�r-r.r/rr3rrrrrr0Jsr0c@s$eZdZdd�Zdd�Zdd�ZdS)�_FakeMemoryResponsecCs
||_dSr1�r)r
rrrrrYsz_FakeMemoryResponse.__init__cCsdSr1rr2rrrr3\sz$_FakeMemoryResponse.raise_for_statuscCs|jSr1r7r2rrrr_sz_FakeMemoryResponse.jsonNr5rrrrr6Wsr6c@s eZdZdZdd�Zdd�ZdS)�ResponseSetzqResponses for a endpoint that returns different data each time.

    Motivating example is v2/changes/$change_id.cCs||_d|_dS)Nr)�files�index)r
r9rrrrhszResponseSet.__init__cCsb|j|j}ttj�dd��}|dkrL|j|t|j�krLt|j�d|_n|j|7_t|�S)NZSUBIQUITY_REPLAY_TIMESCALE�)r9r:�intr$�environr�lenr0)r
�f�drrr�nextlszResponseSet.nextN)r-r.r/�__doc__rrArrrrr8csr8c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�FakeSnapdConnectioncCs||_||_i|_dSr1)�
snap_data_dir�scale_factor�
response_sets)r
rDrErrrryszFakeSnapdConnection.__init__cCst�d�t�d|j�dS)Nz3pretending to restart snapd to pick up proxy config�)r"r#�timer rE)r
r)rrrr,~s
z#FakeSnapdConnection.configure_proxycKsb|dkr&|ddkr&tddddd��S|dkrL|dd	krLtdd
ddd��Std�||f���dS)
Nzv2/snaps/subiquity�actionZrefresh�async���ZOK)�type�changezstatus-code�statusZswitch�ZAcceptedz*Don't know how to fake POST response to {})r6�	Exceptionr	rrrrr�s"���zFakeSnapdConnection.postcKs�t�d|j�|�dd�}|r8|dtt|����7}||jkrP|j|��St	j
�|j|�}t	j
�
|d�r|t|d�St	j
�|�r�tt�t	j
�|d���}t|�}|j|<|��Std�||f���dS)Nr;r�-z.jsonz*.jsonz)Don't know how to fake GET response to {})rHr rE�replacer�sorted�itemsrFrAr$rr%rD�existsr0�isdir�globr8rQr	)r
rr�filename�filepathr9Zrsrrrr�s 
�zFakeSnapdConnection.getN)r-r.r/rr,rrrrrrrCxsrCc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
AsyncSnapdcCs
||_dSr1)�
connection)r
r\rrrr�szAsyncSnapd.__init__c�s,tt|jj|f|��IdH}|��|��Sr1)rrr\rr3r)r
rr�responserrrr�s
�
zAsyncSnapd.getc�s2tt|jj||f|��IdH}|��|��dS)NrN)rrr\rr3r)r
rrrr]rrrr�s
�
zAsyncSnapd.postc�sX|j||f|�IdH}d�|�}|�|�IdH}|dddkrBqTt�d�IdHq dS)Nz
v2/changes/{}�resultrOZDoneg�������?)rr	r�asyncior )r
rrrrNZchange_pathr^rrr�
post_and_wait�s
zAsyncSnapd.post_and_waitN)r-r.r/rrrr`rrrrr[�sr[)r_�	functoolsrrXrZloggingr$rHZurllib.parserrZsubiquitycore.async_helpersrZsubiquitycore.utilsrrZ	getLoggerr"rr0r6r8rCr[rrrr�<module>s"
$
.