o g+@spdZddlmZddlmZddlmZddlmZddlmZm Z ddlm Z m Z Gd d d e Z d d Zd S)ztExternalStatus Class to store status and state information about repositories and create a string representation. )absolute_import)unicode_literals)print_function) EMPTY_STR)printlog indent_string)VERBOSITY_VERBOSEVERBOSITY_DUMPc@speZdZdZdZdZdZdZdZdZ dZ d Z dZ dZ d d Zd d ZddZddZddZddZddZdS)ExternalStatusaClass to represent the status of a given source repository or tree. Individual repositories determine their own status in the Repository objects. This object is just resposible for storing the information and passing it up to a higher level for reporting or global decisions. There are two states of concern: * If the repository is in-sync with the externals description file. * If the repostiory working copy is clean and there are no pending transactions (e.g. add, remove, rename, untracked files). -?esM !ocCs4|j|_|j|_|j|_t|_t|_t|_t|_dS)N) DEFAULT sync_state clean_state source_typerpathcurrent_versionexpected_version status_output)selfr^/lfs/h1/nco/ptmp/ethan.collins/aqm/aqm.v7.0.11/sorc/manage_externals/manic/externals_status.py__init__.s zExternalStatus.__init__cCs0||tkr ||tkr|dSdS)z8Write status message to the screen and log file N)_default_status_messager _verbose_status_messager _dump_status_message)r verbosityrrrlog_status_message7s  z!ExternalStatus.log_status_messagecCs&dj|j|j|j|jd}t|dS)z7Return the default terse status message string z{sync}{clean}{src_type} {path})synccleanZsrc_typerN)formatrrrrrrmsgrrrr @s  z&ExternalStatus._default_status_messagecCsl|j}|j|jkr d}n|j|jkrd}d|j}|j|jkr)dj|j|jd}dj||d}t|dS) z1Return the verbose status message string z clean sandboxzmodified sandboxzon {0}z{current} --> {expected})currentZexpectedz {clean}, {sync})r&r%N) rr STATUS_OKDIRTYr'rrrr)rZ clean_strZsync_strr)rrrr!Hs     z&ExternalStatus._verbose_status_messagecCst|jd}t|dS)z.Return the dump status message string N)rrrr(rrrr"Xs  z#ExternalStatus._dump_status_messagecCsHd}|}|s d}|S|jtjkp|jtjk}|r"|jtjkr"d}|S)zReport if it is safe to update a repository. Safe is defined as: * If a repository is empty, it is safe to update. * If a repository exists and has a clean working copy state with no pending transactions. FT)existsrr r+MODEL_MODIFIEDr)rsafe_to_updateZ repo_existsZ sync_saferrrr0^s   zExternalStatus.safe_to_updatecCsH|jtjk}|jtjkp|jtjkp|jtjk}|r |r d}|Sd}|S)aTDetermine if the repo exists. This is indicated by: * sync_state is not EMPTY * if the sync_state is empty, then the valid states for clean_state are default, empty or unknown. Anything else and there was probably an internal logic error. NOTE(bja, 2017-10) For the moment we are considering a sync_state of default or unknown to require user intervention, but we may want to relax this convention. This is probably a result of a network error or internal logic error but more testing is needed. FT)rr EMPTYrrUNKNOWN)rZis_emptyZ clean_validr.rrrr.ys    zExternalStatus.existsN)__name__ __module__ __qualname____doc__rr2r1r/r,r+Z STATUS_ERROROPTIONALZ STANDALONEZMANAGEDrr$r r!r"r0r.rrrrr s&   r cCs&d}|D] }||}||M}q|S)akCheck if *ALL* repositories are in a safe state to update. We don't want to do a partial update of the repositories then die, leaving the model in an inconsistent state. Note: if there is an update to do, the repositories will by definiation be out of synce with the externals description, so we can't use that as criteria for updating. T)r0) tree_statusr0compstatrrrcheck_safe_to_update_reposs  r;N)r6 __future__rrrglobal_constantsrutilsrrr r objectr r;rrrrs