def filterFiles(groupDict, fileList, category):
    """
    Filters the files into groups. This function currently only support MTB project structure.
    It assumes a libs directory that contains all libaries used by the project and  creates a 
    group for each folder under libs directory. All application source is added at the top level
    project under Keil uVision.
    """
    for fileName in fileList:
        cleanFile = cleanUpPath(fileName)
        # 'include' path should end with slash
        if category == 'include' and not cleanFile.endswith('/'):
            cleanFile += '/'
        dirsList = PurePath(cleanFile).parts
        # uVision with GCC toolchain creates *.o files in the project root
        # Exclude generated object files (auto-discovered in incremental exports)
        if cleanFile.endswith('.o') and len(dirsList) == 1:
            print(
                "WARNING: object file {0} was not added to the generated .cpdsc, add manually as needed"
                .format(cleanFile))
            continue
        try:
            # Find the first libs directory.
            index = dirsList.index("libs")
            # Any child of libs directory is a group.
            grp = dirsList[index + 1]
            groupDict[grp].append((cleanFile, category))
        except (ValueError, IndexError) as e:
            groupDict[GRP_UNFILTERED].append((cleanFile, category))
Exemplo n.º 2
0
def filterFiles(groupDict, searchDict, fileList):
    """
    Filters the files into groups. This function currently only support MTB project structure.
    It assumes a libs directory that contains all libaries used by the project and  creates a 
    group for each folder under libs directory. All application source is added at the top level
    project under IAR.
    """
    for fl in fileList:
        cleanFile = cleanUpPath(fl)
        dirsList = PurePath(fl).parts
        try:
            # Find the first libs directory.
            index = dirsList.index("libs")
            # Any child of libs directory is a group.
            grp = dirsList[index + 1]
            groupDict[(grp, )].append(cleanFile)
        except ValueError:
            # group items in make search into groups
            addedToSearchGroup = False
            for k, v in searchDict.items():
                if cleanFile.startswith(k):
                    groupDict[v].append(cleanFile)
                    addedToSearchGroup = True
            if not addedToSearchGroup:
                groupDict[GRP_UNFILTERED].append(cleanFile)
def filterFiles(groupDict, fileList):
    """
    Filters the files into groups. This function currently only support MTB project structure.
    It assumes a libs directory that contains all libaries used by the project and  creates a 
    group for each folder under libs directory. All application source is added at the top level
    project under IAR.
    """
    for fl in fileList:
        cleanFile = cleanUpPath(fl)
        dirsList = PurePath(fl).parts
        try:
            # Find the first libs directory.
            index = dirsList.index("libs")
            # Any child of libs directory is a group.
            grp = dirsList[index + 1]
            groupDict[grp].append(cleanFile)
        except ValueError:
            groupDict[GRP_UNFILTERED].append(cleanFile)
    def get_example_file_paths(self):
        """
        For each example, get the example file paths.
        """
        for eg in self.example_types:
            # Get the paths to the examples in a particular sub directory e.g Cxx.
            file_paths = defaultdict(list)
            directory = Path(self.base_directory, eg)
            # Does the directory exist?
            if not directory.is_dir():
                raise RuntimeError(f'Non-existent folder: {str(directory)}')
            exclude_dirs = ['Deprecated']
            if eg == 'CSharp':
                fn_pattern = re.compile(r'^[0-9a-zA-Z_\-]+\.cs$')
            elif eg == 'Cxx':
                fn_pattern = re.compile(
                    r'^[0-9a-zA-Z_\-]+\.(hxx|HXX|hpp|HPP|[hH]\+\+|[hH]|cpp|CPP|cxx|CXX|[cC]\+\+|txx|TXX)$')
                exclude_dirs = exclude_dirs + ['CMakeTechniques', 'Untested']
            elif eg == 'Java':
                fn_pattern = re.compile(r'^[0-9a-zA-Z_\-]+\.java$')
                exclude_dirs = exclude_dirs + ['Untested']
            elif eg == 'Python':
                fn_pattern = re.compile(r'^[0-9a-zA-Z_\-]+\.py$')
                exclude_dirs = exclude_dirs + ['Problems']
            else:
                raise RuntimeError('Unknown example type.')

            # Walk the tree.
            for root, directories, files in os.walk(str(directory)):
                # The only visible folders on the web pages are those directly under the language.
                # So we keep folders like Cxx/xx but exclude folders like Cxx/xx/yy.
                if root[len(str(directory)):].count(os.sep) > 1:
                    continue
                sp = PurePath(root).parts
                idx = sp.index(eg)
                key = '/'.join(sp[idx:])
                if exclude_dirs and len(sp[idx:]) > 1:
                    if sp[idx:][1] in exclude_dirs:
                        continue
                for filename in files:
                    m = fn_pattern.match(filename)
                    if m:
                        file_paths[key].append(str(Path(root, filename)))
            self.example_file_paths[eg] = file_paths