�
܍~c� � � � d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
mZmZ ddl
mZmZmZmZmZ dZdd�Zdd
�Zd� Zd� Zed
k r e� � dS dS )zEDefine 'clean' utility and handler as part of cloud-init commandline.� N)�settings)�Init)�ProcessExecutionError�runparts�subp)�del_dir�del_file�error�get_config_logfiles�is_linkz/etc/machine-idc � � | st j dd�� � } | � dddddd �
� � | � dddd�
� � | � ddddd�
� � | � dddddd�
� � | S )a# Build or extend an arg parser for clean utility.
@param parser: Optional existing ArgumentParser instance representing the
clean subcommand which will be extended to support the args of
this utility.
@returns: ArgumentParser with proper argument configuration.
�cleanzARemove logs and artifacts so cloud-init re-runs on a clean system)�prog�descriptionz-lz--logs�
store_trueF�remove_logszRemove cloud-init logs.)�action�default�dest�helpz--machine-idzWRemove /etc/machine-id for golden image creation. Next boot generates a new machine-id.)r r r �-rz--rebootz;Reboot system after logs are cleaned so cloud-init re-runs.z-sz--seed�remove_seedz5Remove cloud-init seed directory /var/lib/cloud/seed.)�argparse�ArgumentParser�add_argument��parsers �5/usr/lib/python3/dist-packages/cloudinit/cmd/clean.py�
get_parserr s� � � �
��(��!�
�
�
�� �������
�
&�
� � � � ������
5� � � � � �������
J� � � � � �������
�
D�
� � � � �M� Fc
�t � t g �� � }|� � � | r&t |j � � D ]}t |� � �t
j � |j j � � sdS t
j �
|j j d� � }t j d|j j z � � D ]�}||k r|s� t
j � |� � rt |� � st |� � nt |� � �Z# t $ r<}t d� |t# |� � � � � � Y d}~ dS d}~ww xY w t% t& |