Пример #1
0
def _resolve_excluded_files(config, key, file_dir):
    raw_patterns = model_helper.read_list(config, key)
    if raw_patterns is None:
        patterns = []
    else:
        patterns = [resolve_env_vars(e) for e in strip(raw_patterns)]
    return FileMatcher(patterns, file_dir)
Пример #2
0
    def test_recursive_glob_relative_different_work_dir(self):
        created_files = ['file1', 'file2', 'file3']
        test_utils.create_files(created_files, 'sub')

        matcher = FileMatcher(['**'], test_utils.temp_folder + '2')
        subfolder_path = os.path.join(test_utils.temp_folder, 'sub')
        files = model_helper.list_files(subfolder_path,
                                        excluded_files_matcher=matcher)
        self.assertEqual(['file1', 'file2', 'file3'], files)
Пример #3
0
def list_files(dir,
               *,
               file_type=None,
               file_extensions=None,
               excluded_files_matcher: FileMatcher = None):
    if not os.path.exists(dir) or not os.path.isdir(dir):
        raise InvalidFileException(dir, 'Directory not found')

    result = []

    if excluded_files_matcher and excluded_files_matcher.has_match(
            pathlib.Path(dir)):
        return result

    if not is_empty(file_extensions):
        file_type = FILE_TYPE_FILE

    sorted_files = sorted(os.listdir(dir), key=lambda s: s.casefold())
    for file in sorted_files:
        file_path = pathlib.Path(dir, file)

        if file_type:
            if file_type == FILE_TYPE_DIR and not file_path.is_dir():
                continue
            elif file_type == FILE_TYPE_FILE and not file_path.is_file():
                continue

        if file_extensions and file_path.is_file():
            extension = file_path.suffix
            if normalize_extension(extension) not in file_extensions:
                continue

        if excluded_files_matcher and excluded_files_matcher.has_match(
                file_path):
            continue

        result.append(file)

    return result
Пример #4
0
 def create_matcher(excluded_paths):
     return FileMatcher(excluded_paths, test_utils.temp_folder)