Ñò ìÿÒXc @s®ddkZddkZddkZddkTddkZddkZddkZddklZddkl Z dZ dZ dZ dd d „ƒYZd d d „ƒYZdS(iÿÿÿÿN(t*(tipautil(tservicess/tmpssysrestore.indexssysrestore.statet FileStorecBsheZdZeed„Zd„Zd„Zd„Zd„Z d d„Z d„Z d„Z d „ZRS( s.Class for handling backup and restore of filescCsJ||_tii|i|ƒ|_tiƒ|_h|_|iƒdS(sÒCreate a _StoreFiles object, that uses @path as the base directory. The file @path/sysrestore.index is used to store information about the original location of the saved files. N( t_pathtostpathtjoint_indextrandomtRandomtfilest_load(tselfRt index_file((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt__init__,s   cCs‘tid|iƒh|_tiƒ}|i|iƒxR|iƒD]D}|djo1x.|i|ƒD]\}}||i| no files, removing fileNR tw(RRRtlenR RRtexiststremoveRRt add_sectionRtsettstrtfiletwritetclose(R RRRtf((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pytsaveMs     c Csntid|ƒtii|ƒptdƒ‚ntii|ƒptid|ƒdStii|ƒ\}}d}x7tdƒD])}d|i i dd ƒ}||7}q†W|d |7}tii |i |ƒ}tii |ƒotid |ƒdSti||ƒti|ƒ}ti t|iƒt|iƒt|iƒ|gd ƒ|i|<|iƒdS( s¬Create a copy of the file at @path - so long as a copy does not already exist - which will be restored to its original location by restore_files(). s)Backing up system configuration file '%s'sAbsolute path requireds( -> Not backing up - '%s' doesn't existNtis%02xiiÿt-s1 -> Not backing up - already have a copy of '%s't,(RRRRtisabst ValueErrortisfiletsplittrangeR trandintRRRtshutiltcopy2tstattstringR!tst_modetst_uidtst_gidR R&( R Rtreldirt backupfiletfilenametitht backup_pathR2((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt backup_filecs* @c Csct}xV|iiƒD]E\}}ti|ddƒ\}}}}||jo t}PqqW|S(sChecks whether file at @path was added to the file store Returns #True if the file exists in the file store, #False otherwise R)i(tFalseR RR3R-tTrue( R RtresultRRtmodetuidtgidtfilepath((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pythas_file…s !  c CsÞ|d jotid|ƒntid||ƒtii|ƒptdƒ‚n|d j o$tii|ƒ otdƒ‚nd }d }d }d }xV|iiƒD]E\}}t i |ddƒ\}}}} | |jo |}Pq°q°W|ptdƒ‚ntii |i |ƒ} tii | ƒptid| ƒtS|d j o |}nti| |ƒti| ƒti|t|ƒt|ƒƒti|t|ƒƒti|ƒ|i|=|iƒtS( s<Restore the copy of a file at @path to its original location and delete the copy. Takes optional parameter @new_path which specifies the location where the file is to be restored. Returns #True if the file was restored, #False if there was no backup file to restore s(Restoring system configuration file '%s's0Restoring system configuration file '%s' to '%s'sAbsolute path requiredsAbsolute new path requiredR)isNo such file name in the indexs' -> Not restoring - '%s' doesn't existN(tNoneRRRRR*R+R RR3R-RRRR>R0tcopyRtchowntinttchmodt ipaservicestrestore_contextR&R?( R Rtnew_pathRARBRCR9RRRDR<((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt restore_file’sB ! !        cCst|iƒdjotSxß|iiƒD]Î\}}ti|ddƒ\}}}}tii|i |ƒ}tii |ƒpt i d|ƒq+nt i||ƒti|ƒti|t|ƒt|ƒƒti|t|ƒƒti|ƒq+Wh|_|iƒtS(sÇRestore the files in the inbdex to their original location and delete the copy. Returns #True if the file was restored, #False if there was no backup file to restore iR)is' -> Not restoring - '%s' doesn't exist(RR R>RR3R-RRRRRRRR0RGRRHRIRJRKRLR&R?(R R9RRARBRCRR<((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pytrestore_all_filesÊs" !   cCst|iƒdjS(sReturn True or False if there are any files in the index Can be used to determine if a program is configured. i(RR (R ((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt has_filesìsc CsYtid|ƒtii|ƒptdƒ‚nd}d}d}d}xV|iiƒD]E\}}t i |ddƒ\}}}}||jo |}Pq[q[W|ptdƒ‚ntii |i |ƒ} tii | ƒptid| ƒtSyti| ƒWn2tj o&} tid| t| ƒfƒnX|i|=|iƒtS( sàRemove file at path @path from list of backed up files. Does not remove any files from the filesystem. Returns #True if the file was untracked, #False if there was no backup file to restore s)Untracking system configuration file '%s'sAbsolute path requiredR)isNo such file name in the indexs' -> Not restoring - '%s' doesn't existsError removing %s: %sN(RRRRR*R+RFR RR3R-RRRR>tunlinkt ExceptionterrorR!R&R?( R RRARBRCR9RRRDR<te((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt untrack_fileôs4  !  "  N(t__name__t __module__t__doc__tSYSRESTORE_PATHtSYSRESTORE_INDEXFILERR R&R=RERFRNRORPRU(((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyR)s   " 8 " t StateFilecBs\eZdZeed„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z RS( s°A metadata file for recording system state which can be backed up and later restored. The format is something like: [httpd] running=True enabled=False cCs/tii||ƒ|_h|_|iƒdS(sºCreate a StateFile object, loading from @path. The dictionary @modules, a member of the returned object, is where the state can be modified. @modules is indexed using a module name to return another dictionary containing key/value pairs with the saved state of that module. The keys in these latter dictionaries are arbitrary strings and the values may either be strings or booleans. N(RRRRtmodulesR (R Rt state_file((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyR)s  cCsËtid|iƒh|_tiƒ}|i|iƒxŒ|iƒD]~}h|i|(R RtmoduleRR((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyR :s       c CsDtid|iƒx?|iiƒD].}t|i|ƒdjo|i|=q#q#Wt|iƒdjo<tidƒtii|iƒoti |iƒndSt i ƒ}xa|iiƒD]P}|i |ƒx:|i|i ƒD]%\}}|i||t|ƒƒqêWqÃWt|idƒ}|i|ƒ|iƒdS(siSave the modules to @_path. If @modules is an empty dict, then @_path should be removed. sSaving StateFile to '%s'is -> no modules, removing fileNR(RRRR\tkeysRRRRRRRRRR R!R"R#R$(R R^RRRR%((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyR&Ns(    ! cCsƒt|tttfƒptdƒ‚n|ii|ƒph|i|(R R^((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyt has_state¢s( RVRWRXRYtSYSRESTORE_STATEFILERR R&RdRfRhRiRj(((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyR[s    (((Rtos.pathR0tipapython.ipa_log_managerRR R3t ipapythonRRRKRYRZRkRR[(((s8/usr/lib/python2.6/site-packages/ipapython/sysrestore.pyts       ö