Current File : //usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pyc
�
oB�]c@s�dZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZm
Z
d�Zdd�Zed�Zd�Zd	�Zed
kr�e�ndS(sEDefine 'clean' utility and handler as part of cloud-init commandline.i����N(tInit(tProcessExecutionErrortdel_dirtdel_filetget_config_logfilestis_linktsubpcCstjjd|d�dS(NsERROR: s
(tsyststderrtwrite(tmsg((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pyterrorscCs�|s!tjdddd�}n|jddddd	td
ddd
�|jddddd	tdd�|jddddd	td
ddd�|S(s#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.
    tprogtcleantdescriptionsARemove logs and artifacts so cloud-init re-runs on a clean systems-ls--logstactiont
store_truetdefaulttdesttremove_logsthelpsRemove cloud-init logs.s-rs--reboots;Reboot system after logs are cleaned so cloud-init re-runs.s-ss--seedtremove_seeds5Remove cloud-init seed directory /var/lib/cloud/seed.(targparsetArgumentParsertadd_argumenttFalse(tparser((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pyt
get_parsers		cCs+tdg�}|j�|rFx$t|j�D]}t|�q/Wntjj|jj	�sbdStjj
|jj	d�}x�tjd|jj	�D]�}||kr�|r�q�ny:tjj|�r�t|�r�t
|�n
t|�Wq�tk
r"}tdj|t|���dSXq�WdS(s4Helper which removes artifacts dir and optionally log files.

    @param: remove_logs: Boolean. Set True to delete the cloud_dir path. False
        preserves them.
    @param: remove_seed: Boolean. Set True to also delete seed subdir in
        paths.cloud_dir.
    @returns: 0 on success, 1 otherwise.
    tds_depsitseeds%s/*sCould not remove {0}: {1}i(Rtread_cfgRtcfgRtostpathtisdirtpathst	cloud_dirtjointglobRRtOSErrorRtformattstr(RRtinittlog_filet	seed_pathR!te((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pytremove_artifacts0s&	
 
	cCs�t|j|j�}|dkr�|jr�dddg}yt|dt�Wq�tk
r�}tdj|t	|���d}q�Xn|S(s3Handle calls to 'cloud-init clean' as a subcommand.itshutdowns-rtnowtcaptures-Could not reboot this system using "{0}": {1}i(
R.RRtrebootRRRRR(R)(tnametargst	exit_codetcmdR-((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pythandle_clean_argsPs
cCs)t�}tjtd|j���dS(s4Tool to collect and tar all cloud-init related logs.R
N(RRtexitR7t
parse_args(R((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pytmain_s	t__main__(t__doc__RR&R Rtcloudinit.stagesRtcloudinit.utilRRRRRRRtNoneRRR.R7R:t__name__(((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pyt<module>s.