oB]c@ssdZddlZddlZddlmZddlmZddlmZeZdZ dZ dZ dS( s% Migrator -------- **Summary:** migrate old versions of cloud-init data to new This module handles moving old versions of cloud-init data to newer ones. Currently, it only handles renaming cloud-init's per-frequency semaphore files to canonicalized name and renaming legacy semaphore names to newer ones. This module is enabled by default, but can be disabled by specifying ``migrate: false`` in config. **Internal name:** ``cc_migrator`` **Module frequency:** per always **Supported distros:** all **Config keys**:: migrate: iN(thelpers(tutil(t PER_ALWAYSc Cs |jjd|jjdf}d}x|D]}| s1tjj| rWq1nxtj|D]}tjj||}tjj|rgtjj |\}}t j |}||krtjj|||} t j || |d7}qqgqgWq1W|S(Ntsemii(tpathst get_ipatht get_cpathtostpathtexiststlistdirtjointisfiletsplitextRtcanon_sem_nametshutiltmove( tcloudRt am_adjustedtsem_pathtpt full_pathtnametextt canon_nametnew_path((s@/usr/lib/python2.7/site-packages/cloudinit/config/cc_migrator.pyt_migrate_canon_sems(s$  c Csiddgd6}|jjd|jjdf}xW|D]O}| s>tjj| rdq>ntj|}x|jD] \}}|tj |g}g} x]tj |D]L} tjj | \} } | |krtjj | r| j | qqWx| D]w} tjtjj|| tjj | \} }x:|D]2}|jd| ||j||WdQXqOWqWqWq>WdS(Ns apt-configurespackage-update-upgrade-installsapt-update-upgradeRs*Migrating %s => %s with the same frequency(RRRRRR RtFileSemaphorestitemsRR R R tappendRtdel_fileR tdebugtlock(Rtlogt legacy_adjustRRt sem_helpertmod_namet migrate_tot possiblest old_existsRRt_extt_nametfreqtm((s@/usr/lib/python2.7/site-packages/cloudinit/config/cc_migrator.pyt_migrate_legacy_sems:s. $     cCsetj|dt}tj|s8|jd|dSt|}|jd|t||dS(Ntmigrates,Skipping module named %s, migration disableds8Migrated %s semaphore files to there canonicalized names(Rtget_cfg_option_strtTruettranslate_boolRRR,(RtcfgRR!t_argst do_migratet sems_moved((s@/usr/lib/python2.7/site-packages/cloudinit/config/cc_migrator.pythandleWs  ( t__doc__RRt cloudinitRRtcloudinit.settingsRt frequencyRR,R5(((s@/usr/lib/python2.7/site-packages/cloudinit/config/cc_migrator.pyts