Oc@s\ddlZddlZddlZddlZddlZddlZddljjZ ddl Z ddl j j Zddlj jZddljZddljZddljZddgZddgZddgZddgZdd gZdd gZdd gZdd gZdd gZddgZ ddgZ!ddgZ"ddgZ#ddgZ$dddgZ%ieej&6eej'6eej(6eej)6eej*6eej+6eej,6eej-6eej.6eej/6eej06eej16eej26eej36e ej46e#ej56eej66ee76e"e86Z9de:fdYZ;de:fdYZ<dS(iNtCanceledtNonetIgnoreds Nothing to dot SucceededtFaileds Bad Requestt Configurationt ConstrainedtLockedtSearchtStoraget TransporttActuators Out of MemorysConflicting ActionstUnknowntcontentstinfotlistt_HistoryOperationcBseZdZiZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdZdZdZdZdZdZdZdZdZedZRS(sA _HistoryOperation object is a representation of data about an operation that a pkg(5) client has performed. This class is private and not intended for use by classes other than History. This class provides an abstraction layer between the stack of operations that History manages should these values need to be manipulated as they are set or retrieved. cCs_t}x'dD]}t||t||qWg|jD]}tj|^q=|_|S(Ntnamet start_timetend_timet start_statet end_statetusernametuseridtbet be_existstbe_uuidt current_betcurrent_new_betnew_bet new_be_existst new_be_uuidtresultt release_notestsnapshot(snames start_timesend_times start_states end_statesusernamesuseridsbeRsbe_uuids current_bescurrent_new_besnew_beRs new_be_uuidsresults release_notesssnapshot(Rtsetattrtgetattrterrorstcopy(tselfthtattrte((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__copy__us  (c Cs.|d krt|}ntj|||S( NR R%RRRRRRRR"( sresultserrorssbesbe_uuids current_bescurrent_new_besnew_bes new_be_existss new_be_uuidssnapshot(tstrtobjectt __setattr__(R'Rtvalue((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR.s  cCsnd|j|j|j|j|j|j|j|j|j|j |j |j |j |j |j|j|jfS(NsOperation Name: %s Operation Result: %s Operation Start Time: %s Operation End Time: %s Operation Start State: %s Operation End State: %s Operation User: %s (%s) Operation Boot Env.: %s Operation Boot Env. Currrent: %s Operation Boot Env. UUID: %s Operation New Boot Env.: %s Operation New Boot Env. Current: %s Operation New Boot Env. UUID: %s Operation Snapshot: %s Operation Release Notes: %s Operation Errors: %s (RR RRRRRRRRRRRRR"R!R%(R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__str__scCs g|_dS(N(R%(R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__init__scCs0tjsitdd6tdd6tdd6tdd6tdd6tdd6tdd6tdd6td d 6td d 6td d 6td d 6td d 6tdd6tdd6tdd6tdd6t_n|j s|j r dStj|jdtj|jdfS(svReturns a tuple containing the translated text for the operation result of the form (outcome, reason).RRRs Nothing to doRs Bad RequestRRRRR R R s Out of MemorysConflicting ActionsR Rtii(R2R2(Rt result_l10nt_RR (R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt result_texts.                 N(t__name__t __module__t__doc__R3R+R.R0RRRRRRR%RRRRRRRRR!R"R R1tpropertyR5(((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyRis0  tHistorycBseZdZdZdZdZdZgZdZ dZ dZ dZ dZ dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZddddZdZe dZ!e dZ"e d Z#d Z$d Z%e&d Z'dd Z(dZ)dZ*dZ+dddZ,dZ-dddZ.ddddZ/dZ0dZ1dZ2dZ3RS(sA History object is a representation of data about a pkg(5) client and about operations that the client is executing or has executed. It uses the _HistoryOperation class to represent the data about an operation. cCst}x'dD]}t||t||qWtj|dg|jD]}tj|^qIg|jD]}tj|^qo|_|S(Ntroot_dirt client_nametclient_versiont client_args(sroot_dirs client_namesclient_version( R:R#R$R-R.R>R&t_History__operationstdeepcopy(R'R(R)tato((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR+s   &(cCsw|dkrtj||S|jds<tj||Stj|d}|sXdSt|dd|tdS(NR>t operation_R?it operation(R-t__getattribute__t startswithRR$tlen(R'Rtops((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyRE*s cCs|dkrtd|n|jdsAtj|||Stj|d}|dkr|sg}tj|d|n|jidd6td6n|std|n|d d}t||t d||dkrt j t j d|_ytj|_Wntk r:d |_nXtj|_d}t jd rpt jd g}n |jg}|jt jd tj|d|tj|d tjnP|dkr t j d|_|jtkr|tkr|jn|d =ndS(NR>s-'history' object attribute '%s' is read-only.RCR?toperation_nametpathnameRDsF'history' object attribute '%s' cannot be set before 'operation_name'.itunknowniiR=toperation_result(tAttributeErrorRFR-R.REtappendRRR#RGtsyst exc_cleartmiscttime_to_timestampRtportablet get_usernameRtKeyErrort get_useridRtargvR<textendtpkgtVERSIONRRtDISCARDED_OPERATIONStRESULT_NOTHING_TO_DOt_History__save(R'RR/RHtoptca((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR.7sP                t.cCsNtj|dgtjjj|_||_|rJ|j|d|ndS(s*'root_dir' should be the path of the directory where the history directory can be found (or created if it doesn't exist). 'filename' should be the name of an XML file containing serialized history information to load. 'uuid_be_dic', if supplied, should be a dictionary of BE uuid information, as produced by pkg.client.bootenv.BootEnv.get_uuid_be_dic(), otherwise that method is called each time a History object is created. R>t uuid_be_dicN(R-R.RYtclienttglobal_settingsR<R;t_History__load(R'R;tfilenameRa((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR1s  cCs3|j}djg|D]}t|d^qS(Ns RD(R?tjoinR,(R'RHR^((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR0s cCstjj|jdS(scThe directory where history files will be written to or read from. thistory(tostpathRfR;(R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyRiscCsS|js dS|j}|dd}|sOtjj|jd|ddjS|S(sReturns the pathname that the history information was read from or will attempted to be written to. Returns None if no operation has started yet or if no operation has been loaded. iRJs %s-01.xmlRDN(toperation_start_timeRR?RhRiRfR(R'RHRJ((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyRJs  ccs}|js dSyGtjj|jd|j}x"t|dD]}|jVq>WWn"tk rx}tj |nXdS(s{Generates the lines of release notes for this operation. If no release notes are present, no output occurs.Ntnotestr( toperation_release_notesRhRiRfR;tfiletrstript ExceptiontapxtHistoryLoadException(R'trpathRAR*((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyRks  cCs2d|_d|_tj|dgg|_dS(s`Discards all information related to the current history object. R>N(RR<R=R-R.R?(R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytclears  cCs|jd|_|jd|_y|jdd}Wntk rNnbXtj|d}xL|jdD];}y|j|jdj Wqqt tfk rqqXqqWdS(slInternal function to load the client data from the given XML 'node' object. RtversiontargsiR>targN( t getAttributeR<R=tgetElementsByTagNamet IndexErrorR-RERNt childNodest wholeTextRM(R'tnodeRvR_tcnode((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__load_client_datas cst}jd|_jd|_jd|_jd|_jd|_jdjd|_t |jdkr|jj d n|jd d krt |_nj d rjd |_ nj d r jd |_nj drXjd|_|j rX|j|j |j|_qXnj drjd|_|jr|j|j|j|_qnj drjd|_ndfd}|d|_|d|_|jj|ddd|S(sInternal function to load the operation data from the given XML 'node' object and return a _HistoryOperation object. RRRRRR s, iRis Nothing to doRRRRs release-notescsy[j|d}|rL|j|}g|D]}|jdj^q2S|jdjSWnttfk rtnX|rgSdS(Ni(RyR{R|RMRz(t parent_namet child_nametparenttcnodesR~(R}(s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytget_node_valuess RRR%RterrorN(RRxRRRRRtsplitR RGRNR\t hasAttributeRRRtgetRRRR!RRRR%RX(R}RaR^R((R}s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__load_operation_datas@     cCs$|jy|s%tjj}nWntjk rD}i}nXytjj|j|}t j |}|j }xl|j D]a}|j dkr|j|q|j dkr|jji|d6|j||d6qqWWn5tk rn"tk r}tj|nXdS(sLoads the history from a file located in self.path/history/ {filename}. The file should contain a serialized history object in XML format. RbRDRJN(RttbootenvtBootEnvtget_uuid_be_dicRqt ApiExceptionRhRiRftxminitparsetdocumentElementR{tnodeNamet_History__load_client_dataR?RNt_History__load_operation_datatKeyboardInterruptRpRr(R'ReRaR*RJtdtrootR~((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__loads,     cCs|jdk st|jdk s*t|j}|jd}|jd|j|jd|j|j||jr|jd}|j|xL|jD]>}|jd}|j||j|j t |qWndS(sInternal function used to serialize current client data using the supplied 'd' (xml.dom.minidom) object. RbRRuRvRwN( R<RtAssertionErrorR=Rt createElementt setAttributet appendChildR>tcreateCDATASectionR,(R'RRRbRvtentryRw((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__serialize_client_dataBs     cCs|jdkr!tjdn!|jdkrBtjdn|j}|jd}|jd|j|jdt |j|jdt |j|jddj |j |jd |j |jd |j |jr|jd |jn|jr|jd |jn|jr>|jd |jn|jr]|jd|jn|jr||jd|jn|jr|jd|jn|j||jr|jd}|j||j|jt |jn|jr6|jd}|j||j|jt |jn|jr|jd}|j|xL|jD]>}|jd}|j||j|jt |qeWndS(sInternal function used to serialize current operation data using the supplied 'd' (xml.dom.minidom) object. sqUnable to determine the id of the user that performed the current operation; unable to store history information.swUnable to determine the username of the user that performed the current operation; unable to store history information.RDRRRR s, RRRRRRR"s release-notesRRR%RN(toperation_useridRRqtHistoryStoreExceptiontoperation_usernameRRRRIR,RfRLRjtoperation_end_timet operation_betoperation_be_uuidtoperation_new_betoperation_new_be_uuidtoperation_snapshotRmRtoperation_start_stateRtoperation_end_statetoperation_errors(R'RRR^tstateR%RR((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__serialize_operation_dataYsX                   cCsftj}|j|jd|j||j|tjj|jsytj |jt j Wqt k r}|j t jt jt jfkrtj|ndStk rqtk r}tj|qXn|j}xjtddD]Y}y`tjtj|tjtjBtjBt jd}|j|dtj|j dSWqt k r)}|j t j!krtjj"tjj#|\}}|j$ddd}tjj%|jd ||d|f}qn-|j t jt jfkr%tj|ndStk r<qtk r]}tj|qXqWdS( sSerializes the current history information and writes it to a file in self.path/{operation_start_time}-{sequence}.xml. RgNiidtwtencodingt-is %s-%02d%s(&RtDocumentRRt_History__serialize_client_datat"_History__serialize_operation_dataRhRitexiststmkdirRQt PKG_DIR_MODEtEnvironmentErrorterrnotEROFStEACCEStENOENTRqRRRpRJtrangetfdopentopentO_CREATtO_EXCLtO_WRONLYt PKG_FILE_MODEtwritexmlROtgetdefaultencodingtclosetEEXISTtsplitexttbasenameRRf(R'RR*RJtitfRtext((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyt__savesT           cCsd|_||_||_ytj|jWn~tk rEnttk r}|jtj tj fkr|t |_ dSt j|n+tk r}t j|n Xt |_ dS(sRemoves all history information by deleting the directory indicated by the value self.path and then creates a new history entry to record that this purge occurred. s purge-historyN(RIRRtshutiltrmtreeRiRRRRtESRCHtRESULT_SUCCEEDEDRLRqtHistoryPurgeExceptionRp(R'tbe_nameRR*((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytpurges     cCs6yx|jr||_qWWntk r1dSXdS(ssIntended to be used by the client during top-level error handling to indicate that an unrecoverable error occurred during the current operation(s). This allows History to end all of the current operations properly and handle any possible errors that might be encountered in History itself. N(RIRLR(R'R ((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytaborts   cCs||_||_||_dS(sPMarks the start of an operation to be recorded in image history.N(RIRR(R'RRR((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytlog_operation_start s  cCs|r(|j|d|_d|_n|r| ryt|j}WnMttfk rx7tjD]%\}}t ||ri|}PqiqiWnX|st }qn|st }n|r||_ n||_ dS(sMarks the end of an operation to be recorded in image history. 'result' should be a pkg.client.history constant value representing the outcome of an operation. If not provided, and 'error' is provided, the final result of the operation will be based on the class of 'error' and 'error' will be recorded for the current operation. If 'result' and 'error' is not provided, success is assumed.N(tlog_operation_errorRRRt error_resultst __class__RMRUt iteritemst isinstancetRESULT_FAILED_UNKNOWNRRmRL(R'RR R!Rtval((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytlog_operation_ends&         c Cs|jrd}d}t}t|trctj\}}}||krctj}t }qcnt|t r{|}n|rdj tj }|rt |}| s|dkr|jj}qndj g||gD]} | r| ^q}n|jj|jndS(snAdds an error to the list of errors to be recorded in image history for the current operation.R2RN(RIRtTrueRRpROtexc_infot tracebackt format_exctFalset basestringRft format_stackR,RR6RRNtstrip( R'Rt out_stacktout_errtuse_current_stackttypeRttbtoutputtitem((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR6s*      cCsi}|_x!dD]}t||||t __operationsN(sroot_dirs client_namesclient_version(t_History__snapshotR$R>R&R?R@(R'tattrsR)RARB((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytcreate_snapshotes   )cCs d|_dS(sVDiscards the current history and operation state information snapshot.N(RR(R'((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytdiscard_snapshotuscCsf|js dSxB|jjD]1\}}|jdstj|||qqW|jd|_dS(sRestores the last snapshot taken of history and operation state information completely discarding the existing history and operation state information. If nothing exists to restore, this this function will silently return.Nt__R(RRRFR-R.R?(R'RR((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytrestore_snapshotzs  N(4R6R7R8RR;R<R=R>R?RRIRRtoperation_current_beRRtoperation_current_new_beRRRjRRRRRRLRmR+RER.R1R0R9RiRJRkRtRt staticmethodRRdRRR]RRRRRRRR(((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pyR:s^ I  > $  @ F & /  (=R&RRhRRORtxml.dom.minidomtdomtminidomRRYtpkg.client.api_errorsRbt api_errorsRqtpkg.client.bootenvRtpkg.fmritfmritpkg.miscRQt pkg.portableRStRESULT_CANCELEDR\RtRESULT_FAILED_BAD_REQUESTtRESULT_FAILED_CONFIGURATIONtRESULT_FAILED_CONSTRAINEDtRESULT_FAILED_LOCKEDtRESULT_FAILED_SEARCHtRESULT_FAILED_STORAGEtRESULT_FAILED_TRANSPORTtRESULT_FAILED_ACTUATORtRESULT_FAILED_OUTOFMEMORYtRESULT_CONFLICTING_ACTIONSRR[tImageLockedErrortInvalidCatalogFiletBENamingNotSupportedtInvalidBENameExceptiontCertificateErrortPublisherErrortCanceledExceptiontImageUpdateOnLiveImageExceptiont$ProblematicPermissionsIndexExceptiontPermissionsExceptiontSearchExceptiontPlanCreationExceptiontNonLeafPackageExceptiontIpkgOutOfDateExceptiontInvalidDepotResponseExceptiontConflictingActionErrorst IllegalFmriRt MemoryErrorRR-RR:(((s8/usr/lib/python2.7/vendor-packages/pkg/client/history.pytsb