コード例 #1
0
ファイル: yerba.py プロジェクト: brouberol/Yerba
def count_lines_by_extension(project_files):
    """
    Given a list of the project files, it returns
    the number of lines of code written in each language
    """

    res = []
    for extensions in formats.values():
        nb_lines = 0
        
        if type(extensions) is list: # ex : C++
            for extension in extensions: # C++ contains several exensions (hpp, cpp, h) 
                for p_file in project_files: # for each project file 
                    if p_file.split('.')[-1].lower() == extension: #split returns file extension
                        with open(p_file,'r') as f: # count nblines
                            for line in f:
                                Nb_lines+=1
            res.append(nb_lines)
            
        else:
            for p_file in project_files:
                if p_file.split('.')[-1].lower() == extensions: #split returns file extension
                    with open(p_file,'r') as f:
                        for line in f:
                            nb_lines+=1
            res.append(nb_lines)

    return res
コード例 #2
0
ファイル: yerba.py プロジェクト: brouberol/Yerba
def get_project_files(project_root):
    """
    Given a project root, it returns a list 
    containing all absolute path tpproject files,
    given that they are not contained in a Version 
    Control Manager directory (.git, .svn, ...)
    """

    project = walk(project_root)
    project_files = []
    for base, dirs, files in project:
        if exclude_dir[0] not in base and exclude_dir[1] not in base and exclude_dir[2] not in base: 
            # we filter out files in .git/.svn... folders
            for f in files:
                for value in formats.values(): # Ugly but C++ contains several extensions (hpp, h, cpp)
                    if f.split('.')[-1].lower() in value: # if known extensions
                        project_files.append(abspath(base+'/'+f))
                                   
    return project_files