o g8@sdZddlZddlZddlZddlmZddlmZddlmZddlm Z ddl m Z dd l m Z dd lmZmZdd lmZmZdd lmZGd ddeZGdddeZdS)zJ FIXME(bja, 2017-11) External and SourceTree have a circular dependancy! N)ExternalsDescription)read_externals_description_file)create_externals_description)create_repository) GitRepository)ExternalStatus) fatal_errorprintlog) EMPTY_STRLOCAL_PATH_INDICATOR)VERBOSITY_VERBOSEc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS) _ExternalzE _External represents an external object inside a SourceTree cCs||_d|_t|_d|_t|_d|_|tj |_ t j ||j }t j ||_t j |j|_t j |j|_t j |j|j|jksFJ|tj|_|tj|_|js_t|jr_tj|_t||tj|d}|rn||_|jr~|jdkr|dSdSdS)aParse an external description file into a dictionary of externals. Input: root_dir : string - the root directory path where 'local_path' is relative to. name : string - name of the ext_description object. may or may not correspond to something in the path. ext_description : dict - source ExternalsDescription object svn_ignore_ancestry : bool - use --ignore-externals with svn switch N)svn_ignore_ancestrynone)_name_repor _externals_externals_sourcetreer_statZ_sparserPATH _local_pathospathjoinabspath_repo_dir_pathdirname_base_dir_pathbasename_repo_dir_nameREQUIRED _required EXTERNALSrhas_submodulesGIT_SUBMODULES_FILENAMErREPOlower_create_externals_sourcetree)selfroot_dirnameZext_descriptionrrepo_dirrepor.X/lfs/h1/nco/ptmp/ethan.collins/aqm/aqm.v7.0.11/sorc/manage_externals/manic/sourcetree.py__init__s8      z_External.__init__cC|jS)z3 Return the external object's name )rr)r.r.r/get_nameOz_External.get_namecCr1)z3 Return the external object's path )rr2r.r.r/get_local_pathUr4z_External.get_local_pathcCs ||j_|jstj|j_n|jtkrtj |j_ntj |j_i}t j |j sQtj|j_d|j}t|d|j_|jsDd|j_n5|j|j|j_n(|jr]|j|j|j |jry|jryt }t |j |j|j}t |i}|jtkr|j||jj<|r|||S)aZ If the repo destination directory exists, ensure it is correct (from correct URL, correct branch or tag), and possibly update the external. If the repo destination directory does not exist, checkout the correce branch or tag. If load_all is True, also load all of the the externals sub-externals. zr rr8rr9r log_status_messagerr= STATUS_OKcheckoutr clone_recursive)r) verbosityload_allerrorrIZcheckout_verbosityr.r.r/rPs0   z_External.checkoutcCs2|r|jr d|_||j||dSdS)z3Checkout the sub-externals for this object N)load_externalsrr(rP)r)rRrSr.r.r/checkout_externalss z_External.checkout_externalscCsDd}tj|jr |jr |jdkr tjtj|j|j}|S)z2Return True iff an externals file should be loadedFr)rrr;rrr'r)r)Zload_exr.r.r/rUsz_External.load_externalscCs |j }|S)z9Return True iff any .gitmodules files should be processed)r)r) recursiver.r.r/rQsz_External.clone_recursivecCstj|js dSt}t|j|jdkr$d|j}t |tj|js3t r3t j |_tj|jsFd|j|j}t ||j}t||j}t||jd}t|||_t|dS)z NrzBInternal: Attempt to create source tree for externals = none in {}zKExternal externals description file "{0}" does not exist! In directory: {1}) parent_repo)rrr;rrFrGrr'r>r rr$rr%rrr SourceTreer)r)rJrIZexternals_root model_data externalsr.r.r/r(s8  z&_External._create_externals_sourcetreeN) __name__ __module__ __qualname____doc__r0r3r5rErPrVrUrQr(r.r.r.r/rs4?+ rc@s0eZdZdZd ddZefddZd dd ZdS) rYz< SourceTree represents a group of managed externals FcCs`tj||_i|_g|_|D]}t|j||||}||j|<||tjr-|j |qdS)zD Build a SourceTree object from a model description N) rrrZ _root_dir_all_components_required_compnamesrrr!append)r)r*Zmodelrcompsrcr.r.r/r0s  zSourceTree.__init__c Cs|j}i}|D]D}td|dd|j|}i}|D]&}||j|r2||||<q!tj|||j}||||<|||_q!| |q |S)aReport the status components FIXME(bja, 2017-10) what do we do about situations where the user checked out the optional components, but didn't add optional for running status? What do we do where the user didn't add optional to the checkout but did add it to the status. -- For now, we run status on all components, and try to do the right thing based on the results.... {0}, end) r`keysr r>rEr startswithrrrH) r)Zrelative_path_base load_compsZsummaryrcstatZ stat_finalr+Z modified_pathr.r.r/rEs     zSourceTree.statusNcs|tkr tdntddd|rj}n |dur|g}nj}t|fddd}|D]&}|tkr>td|ddnttj|||j| ||q.tddS) aK Checkout or update indicated components into the the configured subdirs. If load_all is True, recursively checkout all externals. If load_all is False, load_comp is an optional set of components to load. If load_all is True and load_comp is None, only load the required externals. zChecking out externals: rfrgNcsj|SN)r`r5)rcr2r.r/Usz%SourceTree.checkout..)keyre) r r r`rirasortedr>r rPrV)r)rRrS load_compZ tmp_compsrkrcr.r2r/rP?s     zSourceTree.checkout)Frm)r\r]r^r_r0r rErPr.r.r.r/rY s   "rY)r_rMr?rexternals_descriptionrrrZrepository_factoryrZrepository_gitrexternals_statusrutilsr r global_constantsr r r objectrrYr.r.r.r/s        x