<commit_before># Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import stat

class FileScanner(object):
    """Recursively scans a set of directories and files."""
    def __init__(self, files, skip_files=None):
        self._files = set()
        for file in files:
            assert type(file) == str
            self._files.add(file.encode("utf-8"))
        self._skip_files_stat = set()
        if skip_files:
            for skip_file in skip_files:
                self._skip_files_stat.add(os.stat(skip_file))

    def __iter__(self):
        for file in self._files:
            assert type(file) == bytes
            file = os.path.abspath(file)
            file_stat = os.lstat(file)
            if stat.S_ISDIR(file_stat.st_mode):
                for root, dirs, files in os.walk(
                        file, onerror=self._reportWalkError):
                    dir_stat = os.lstat(root)
                    if self._skip(dir_stat):
                        print("skipping directory: %s" % root)
                        dirs.clear()
                        files.clear()
                        continue

                    yield root, dir_stat
                    files.sort()
                    dirs.sort()
                    for path in files:
                        full_path = os.path.join(root, path)
                        file_stat = os.lstat(full_path)
                        if stat.S_ISLNK(file_stat.st_mode):
                            yield full_path, file_stat
                        else:
                          yield from self._skipOrYield(full_path, file_stat)
            elif stat.S_ISLNK(file_stat.st_mode):
                yield file, file_stat
            else:<commit_msg>handle disappearing files a bit more gracefully<commit_after># Copyright 2013 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import stat

class FileScanner(object):
    """Recursively scans a set of directories and files."""
    def __init__(self, files, skip_files=None):
        self._files = set()
        for file in files:
            assert type(file) == str
            self._files.add(file.encode("utf-8"))
        self._skip_files_stat = set()
        if skip_files:
            for skip_file in skip_files:
                self._skip_files_stat.add(os.stat(skip_file))

    def __iter__(self):
        for file in self._files:
            assert type(file) == bytes
            file = os.path.abspath(file)
            try:
                file_stat = os.lstat(file)
            except FileNotFoundError:
                print("file disappeared: %s" % file)
                continue
            if stat.S_ISDIR(file_stat.st_mode):
                for root, dirs, files in os.walk(
                        file, onerror=self._reportWalkError):
                    try:
                        dir_stat = os.lstat(root)
                    except FileNotFoundError:
                        print("file disappeared: %s" % root)
                        continue
                    if self._skip(dir_stat):
                        print("skipping directory: %s" % root)
                        dirs.clear()
                        files.clear()
                        continue

                    yield root, dir_stat
                    files.sort()
                    dirs.sort()
                    for path in files:
                        full_path = os.path.join(root, path)
                        try:
                            file_stat = os.lstat(full_path)
                        except FileNotFoundError:
                            print("file disappeared: %s" % full_path)
                            continue
                        if stat.S_ISLNK(file_stat.st_mode):
                            yield full_path, file_stat
                        else:
                            yield from self._skipOrYield(full_path, file_stat)
            elif stat.S_ISLNK(file_stat.st_mode):
                yield file, file_stat
            else:
{'fraction_non_alphanumeric': 0.0777601899485556, 'fraction_numerical': 0.003561535417491096, 'mean_word_length': 1.5199401794616152, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5483121', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1255, 'n_words': 397}