File: //usr/share/netplan/netplan/cli/commands/__pycache__/get.cpython-38.pyc
U
��~f�
� @ sX d Z ddlZddlZddlZddlZddlm mZ ddlm Z G dd� dej
�ZdS )znetplan get command line� Nc s4 e Zd Z� fdd�Zdd� Zdd� Zdd� Z� ZS ) �
NetplanGetc s t � jdddd� d S )N�getzRGet a setting by specifying a nested key like "ethernets.eth0.addresses", or "all"T)�
command_id�description�leaf)�super�__init__��self�� __class__� �./usr/share/netplan/netplan/cli/commands/get.pyr s �zNetplanGet.__init__c C sD | j jdtdddd� | j jdddd � | j| _| �� | �� d S )
N�key�?�allzThe nested key in dotted format)�type�nargs�default�helpz
--root-dir�/z>Read configuration files from this root directory instead of /)r r )�parser�add_argument�str�command_get�func�
parse_args�run_commandr r
r
r �run# s
�zNetplanGet.runc C sz |dkr|j |d� d S |�d�s0d�d|f�}t�dd|��dd�}t�� �"}|j |d� tj |||d� W 5 Q R X d S )Nr )�output_file�network�.z (?<!\\)\.� z\.)
� dump_yaml�
startswith�join�re�sub�replace�tempfile�NamedTemporaryFile�
libnetplan�dump_yaml_subtree)r
r �np_stater Ztmp_inr
r
r �
dump_state- s
zNetplanGet.dump_statec C s� t �� }|j| jd� t �� }|�|� ztj�� tj}W n t j
k
rZ t�� }Y nX | �
| j||� |tjkr�|�� |�d� tj�|�� �d�� |�� d S )N)�rootdirr zutf-8)r+ �Parser�load_yaml_hierarchy�root_dir�State�import_parser_results�sys�stdout�fileno�io�UnsupportedOperationr) �
TemporaryFiler. r �flush�seek�write�read�decode�close)r
r r- r r
r
r r ; s
zNetplanGet.command_get)�__name__�
__module__�__qualname__r r r. r �
__classcell__r
r
r r r s
r )�__doc__r5 r8 r) r&