示例#1
0
def tidy(directory: str, collection: dict):
    ignoring_file = '.rmdupignore'
    wildcard = Wildcard()
    for dirpath, _, filenames in os.walk(directory):
        wildcard.append(dirpath, ignoring_file)
        if wildcard.match(dirpath):
            continue

        path = PurePath(dirpath)
        for filename in filenames:
            if filename == ignoring_file or filename == 'Icon\r':
                continue

            filepath = str(path.joinpath(filename))

            # ignore
            if wildcard.match(filepath):
                continue

            f = FileInfo(filepath)
            if isinstance(f, FileInfo):
                logging.debug(f.uri)
                collection.setdefault(f, []).append(str(f))
            else:
                logging.warning(f)
示例#2
0
def test_wildcard(monkeypatch):
    read_data = '''
.git/
*/.git/
*.jpg
*.py
a/*/c/
*/mame0184-64bit/

'''
    with patch('io.open', mock_open(read_data=read_data)):
        wildcard = Wildcard('.', '.rmdupignore')
        assert wildcard.match('.git')
        assert wildcard.match('.git/a/b/c')
        assert wildcard.match('/a/b/c/.git/')
        assert wildcard.match('/a/b/c/.git/d/e/f')
        assert wildcard.match('/a/b/c/d.e.f.jpg')