Passed
Push — master ( 47312b...0d4b48 )
by Andrey
01:13
created

cookiecutter.find.find_template()   B

Complexity

Conditions 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
rs 8.6666
c 0
b 0
f 0
cc 6
nop 1
1
# -*- coding: utf-8 -*-
2
3
"""Functions for finding Cookiecutter templates and other components."""
4
5
import logging
6
import os
7
8
from cookiecutter.exceptions import NonTemplatedInputDirException
9
10
logger = logging.getLogger(__name__)
11
12
13
def find_template(repo_dir):
14
    """Determine which child directory of `repo_dir` is the project template.
15
16
    :param repo_dir: Local directory of newly cloned repo.
17
    :returns project_template: Relative path to project template.
18
    """
19
    logger.debug('Searching %s for the project template.', repo_dir)
20
21
    repo_dir_contents = os.listdir(repo_dir)
22
23
    project_template = None
24
    for item in repo_dir_contents:
25
        if 'cookiecutter' in item and '{{' in item and '}}' in item:
26
            project_template = item
27
            break
28
29
    if project_template:
30
        project_template = os.path.join(repo_dir, project_template)
31
        logger.debug('The project template appears to be %s', project_template)
32
        return project_template
33
    else:
34
        raise NonTemplatedInputDirException
35