� V�"`c�����������@���s����d��Z��d�d�l�Z�d�d�l�Z�d�d�l�Z�d�d�l�m�Z�d�d�l�m�Z�d�d�l�m�Z�d�d�l�m �Z �d�d�l �m�Z�d�d �l�m �Z �d�d �l�m�Z�m�Z�d�d�l�m�Z�m�Z�d�d�l�m�Z�d �e�f�d�������YZ�d�e�f�d�������YZ�d�S(���sJ��� FIXME(bja, 2017-11) External and SourceTree have a circular dependancy! i����Ni���(���t���ExternalsDescription(���t���read_externals_description_file(���t���create_externals_description(���t���create_repository(���t ���GitRepository(���t���ExternalStatus(���t���fatal_errort���printlog(���t ���EMPTY_STRt���LOCAL_PATH_INDICATOR(���t���VERBOSITY_VERBOSEt ���_Externalc�����������B���s_���e��Z�d��Z�d����Z�d����Z�d����Z�d����Z�d����Z�d����Z�d����Z �d����Z �d ����Z�RS( ���sE��� _External represents an external object inside a SourceTree c���������C���sq��|�|��_��d�|��_�t�|��_�d�|��_�t����|��_�|�t�j �|��_ �t�j�j �|�|��j ���}�t�j�j�|���|��_�t�j�j�|��j���|��_�t�j�j�|��j���|��_�t�j�j �|��j�|��j���|��j�k�s��t���|�t�j�|��_�|�t�j�|��_�|��j�st�j�|��j���rt�j�|��_�qn��t�|�|�t�j�d�|��}�|�rB|�|��_�n��|��j�rm|��j�j����d�k�rm|��j����n��d�S(���s���Parse 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 t���svn_ignore_ancestryt���noneN(���t���_namet���Nonet���_repoR���t ���_externalst���_externals_sourcetreeR���t���_statR����t���PATHt���_local_patht���ost���patht���joint���abspatht���_repo_dir_patht���dirnamet���_base_dir_patht���basenamet���_repo_dir_namet���AssertionErrort���REQUIREDt ���_requiredt ���EXTERNALSR���t���has_submodulest���GIT_SUBMODULES_FILENAMER���t���REPOt���lowert���_create_externals_sourcetree(���t���selft���root_dirt���namet���ext_descriptionR���t���repo_dirt���repo(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyt���__init__���s0���� c���������C���s���|��j��S(���s3��� Return the external object's name (���R���(���R(���(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyt���get_nameN���s����c���������C���s���|��j��S(���s3��� Return the external object's path (���R���(���R(���(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyt���get_local_pathT���s����c���������C���s���|��j�����|��j�_�|��j�s-�t�j�|��j�_�n0�|��j�t�k�rN�t�j �|��j�_�n�t�j �|��j�_�i��}�t�j�j�|��j ���s��t�j�|��j�_�d�j�|��j���}�t�j�|���d�|��j�_�|��j�s��d�|��j�_�qg|��j�j����|��j�j����|��j�_�nx�|��j�r|��j�j�|��j�|��j ���n��|��j�rg|��j�rgt�j����}�t�j�|��j ���|��j�j�|��j���}�t�j�|���n��i��}�|��j�t�k�r�|��j�|�|��j�j�<n��|�r�|�j�|���n��|�S(���sZ�� 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. s<���status check: repository directory for "{0}" does not exist.s���not checked outt���unknown(���R0���R���R���R!���R���t���OPTIONALt���source_typeR���R ���t ���STANDALONEt���MANAGEDR���t���existsR���t���EMPTYt ���sync_statet���formatR���t���loggingt���infot���current_versionR���t���expected_versiont���tagt���brancht���statusR���R���t���getcwdt���chdirt���update(���R(���t ���ext_statst���msgt���cwdt ���all_stats(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyR@���Z���s:���� % c���������C���s��|�r �n��t��j�j�|��j���s|�y�t��j�|��j���Wq|�t�k �rx�}�|�j�t�j�k�ry�d�j �|��j���}�t �|���qy�q|�Xn��|��j�j�t �j�k�r��|�t�k�r��|��j�j�t���q��n��|��j�r|��j�j�t �j�k�r��|�d�}�n�|�}�|��j�j�|��j�|��j�|�|��j������n��d�S(���sZ�� 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 correct branch or tag. If load_all is True, also load all of the the externals sub-externals. s ���Could not create directory "{0}"i���N(���R���R���R6���R���t���makedirsR���t���OSErrort���errnot���EEXISTR9���R���R���R3���R���R4���R ���t���log_status_messageR���R8���t ���STATUS_OKt���checkoutR���t���clone_recursive(���R(���t ���verbosityt���load_allt���errorRE���t���checkout_verbosity(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyRN�������s&���� c���������C���sE���|��j�����rA�|��j�r!�d�|��_�n��|��j����|��j�j�|�|���n��d�S(���s3���Checkout the sub-externals for this object N(���t���load_externalsR���R���R'���RN���(���R(���RP���RQ���(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyt���checkout_externals����s ���� c���������C���sm���t��}�t�j�j�|��j���ri�|��j�ri�|��j�j����d�k�rf�t�j�j�t�j�j�|��j�|��j�����}�qf�qi�n��|�S(���s2���Return True iff an externals file should be loadedR ���(���t���FalseR���R���R6���R���R���R&���R���(���R(���t���load_ex(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyRT�������s���� c���������C���s���|��j��}�|�S(���s9���Return True iff any .gitmodules files should be processed(���R���(���R(���t ���recursive(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyRO�������s���� c���������C���s)��t��j�j�|��j���s�d�St��j����}�t��j�|��j���|��j�j����d�k�ri�d�j�|��j���}�t �|���n��t��j�j�|��j���s��t �j����r��t�j �|��_�q��n��t��j�j�|��j���s��d�j�|��j�|��j���}�t �|���n��|��j�}�t�|�|��j���}�t�|�d�|��j��}�t�|�|���|��_�t��j�|���d�S(���s ��� NR ���sB���Internal: Attempt to create source tree for externals = none in {}sK���External externals description file "{0}" does not exist! In directory: {1}t���parent_repo(���R���R���R6���R���RA���RB���R���R&���R9���R���R���R#���R����R$���R���R���R���t ���SourceTreeR���(���R(���RF���RE���t���externals_roott ���model_datat ���externals(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyR'�������s,���� (���t���__name__t ���__module__t���__doc__R.���R/���R0���R@���RN���RU���RT���RO���R'���(����(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyR������s��� 3 ? + RZ���c�����������B���s2���e��Z�d��Z�e�d���Z�e�d���Z�d�d���Z�RS(���s<��� SourceTree represents a group of managed externals c���������C���s����t��j�j�|���|��_�i��|��_�g��|��_�x[�|�D]S�}�t�|��j�|�|�|�|���}�|�|��j�|�<|�|�t�j�r.�|��j�j �|���q.�q.�Wd�S(���sD��� Build a SourceTree object from a model description N( ���R���R���R���t ���_root_dirt���_all_componentst���_required_compnamesR���R����R ���t���append(���R(���R)���t���modelR���t���compt���src(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyR.�����s���� c���������C���s����|��j��j����}�i��}�x��|�D]��}�t�d�j�|���d�d��|��j��|�j����}�xn�|�j����D]`�}�|�|�j�j�|���s[�t�j�j�|�|�|�j���|�|�_�|�|�}�|�|�=|�|�|�j�<q[�q[�W|�j �|���q�W|�S(���s���Report 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.... s���{0}, t���endt����( ���Rb���t���keysR���R9���R@���R���t ���startswithR���R���RC���(���R(���t���relative_path_baset ���load_compst���summaryRf���t���statR*���t ���comp_stat(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyR@�����s���� c���������C���s����|�t��k�r�t�d���n�t�d�d�d��|�rA�|��j�j����}�n!�|�d�k �rY�|�g�}�n �|��j�}�xW�|�D]O�}�|�t��k��r��t�d�j�|���d�d��n �t�t���|��j�|�j�|�|���qi�Wt�d���x%�|�D]�}�|��j�|�j �|�|���q��Wd�S(���sK�� 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. s���Checking out externals: Rh���Ri���s���{0}, N( ���R ���R���Rb���Rj���R���Rc���R9���R���RN���RU���(���R(���RP���RQ���t ���load_compRm���Rf���(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyRN���<��s ���� N( ���R^���R_���R`���RV���R.���R ���R@���R���RN���(����(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyRZ��� ��s��� (���R`���RJ���R:���R���t���externals_descriptionR����R���R���t���repository_factoryR���t���repository_gitR���t���externals_statusR���t���utilsR���R���t���global_constantsR���R ���R ���t���objectR���RZ���(����(����(����sP���/gpfs/hps/nco/ops/nwpara/hiresw.v8.0.1/sorc/manage_externals/manic/sourcetree.pyt���<module>���s����