
    6e                         d Z ddlZddlZddlmZ ddlmZ ddlmZ  ej                  dej                        Zd Zd Zd	 Zd
 Z	 	 ddZy)z"Cookiecutter repository functions.    N)RepositoryNotFound)clone)unzipz
# something like git:// ssh:// file:// etc.
((((git|hg)\+)?(git|ssh|file|https?):(//)?)
 |                                      # or
 (\w+@[\w\.]+)                          # something like user@...
)
c                 >    t        t        j                  |             S )z)Return True if value is a repository URL.)bool
REPO_REGEXmatchvalues    9/usr/lib/python3/dist-packages/cookiecutter/repository.pyis_repo_urlr      s    
  '((    c                 @    | j                         j                  d      S )z#Return True if value is a zip file.z.zip)lowerendswithr
   s    r   is_zip_filer      s    ;;=!!&))r   c                 r    | |v r||    S | j                  d      \  }}}||v r||   j                  |      S | S )zExpand abbreviations in a template name.

    :param template: The project template name.
    :param abbreviations: Abbreviation definitions.
    :)	partitionformat)templateabbreviationsprefixseprests        r   expand_abbreviationsr       sS     = X&& !**3/FCV$++D11Or   c                     t         j                  j                  |       }t         j                  j                  t         j                  j	                  | d            }|xr |S )zDetermine if `repo_directory` contains a `cookiecutter.json` file.

    :param repo_directory: The candidate repository directory.
    :return: True if the `repo_directory` is valid, else False.
    zcookiecutter.json)ospathisdirisfilejoin)repo_directoryrepo_directory_existsrepo_config_existss      r    repository_has_cookiecutter_jsonr&   2   sK     GGMM.9
^%89 !7%77r   c                    t        | |      } t        |       rt        | t        |       |||      }|g}d}	nDt        |       rt	        | |||      }
|
g}d}	n$| t
        j                  j                  ||       g}d}	|r-|D cg c]"  }t
        j                  j                  ||      $ }}|D ]  }t        |      s||	fc S  t        dj                  | dj                  |                  c c}w )aj  
    Locate the repository directory from a template reference.

    Applies repository abbreviations to the template reference.
    If the template refers to a repository URL, clone it.
    If the template is a path to a local repository, use it.

    :param template: A directory containing a project template directory,
        or a URL to a git repository.
    :param abbreviations: A dictionary of repository abbreviation
        definitions.
    :param clone_to_dir: The directory to clone the repository into.
    :param checkout: The branch, tag or commit ID to checkout after clone.
    :param no_input: Do not prompt for user input and eventually force a refresh of
        cached resources.
    :param password: The password to use when extracting the repository.
    :param directory: Directory within repo where cookiecutter.json lives.
    :return: A tuple containing the cookiecutter template directory, and
        a boolean describing whether that directory should be cleaned up
        after the template has been instantiated.
    :raises: `RepositoryNotFound` if a repository directory could not be found.
    )zip_uriis_urlclone_to_dirno_inputpasswordT)repo_urlcheckoutr*   r+   FzMA valid repository for "{}" could not be found in the following locations:
{}
)r   r   r   r   r   r   r   r"   r&   r   r   )r   r   r*   r.   r+   r,   	directoryunzipped_dirrepository_candidatescleanupcloned_reposrepo_candidates                r   determine_repo_dirr7   @   s   > $Hm<H8x(%
 ".	X	%	
 "-!)277<<h+O P0E!
+,BGGLLI&!
 !
 0 ++N;!7**+ 	$))4I*JK !
s   'C,)NN)__doc__r   recookiecutter.exceptionsr   cookiecutter.vcsr   cookiecutter.zipfiler   compileVERBOSEr   r   r   r   r&   r7    r   r   <module>r@      sW    ( 	 	 6 " &RZZ JJ	
)
*
$8( Dr   