ó oBú]c@sÁdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m 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.pyterrorsc Cs—|s!tjddddƒ}n|jddddd td d d 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. tprogtcleant descriptionsARemove logs and artifacts so cloud-init re-runs on a clean systems-ls--logstactiont store_truetdefaulttdestt remove_logsthelpsRemove cloud-init logs.s-rs--reboots;Reboot system after logs are cleaned so cloud-init re-runs.s-ss--seedt remove_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§t j d|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_dirtjointglobRRtOSErrorR tformattstr(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.RRtrebootRRRR R(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.utilRRRRRRR tNoneRRR.R7R:t__name__(((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/clean.pyts    .