|
29 | 29 | class Unimported(BeetsPlugin):
|
30 | 30 | def __init__(self):
|
31 | 31 | super().__init__()
|
32 |
| - self.config.add({"ignore_extensions": [], "ignore_subdirectories": []}) |
| 32 | + self.config.add( |
| 33 | + { |
| 34 | + "ignore_extensions": [], |
| 35 | + "ignore_subdirectories": [], |
| 36 | + "ignore_as_globs": False, |
| 37 | + } |
| 38 | + ) |
| 39 | + |
| 40 | + def walk(self, lib): |
| 41 | + ignore_subdirs = self.config["ignore_subdirectories"].as_str_seq() |
| 42 | + if self.config["ignore_as_globs"].get(bool): |
| 43 | + # The way beets ignore elements in the library, using globbing, |
| 44 | + # whatever the depth |
| 45 | + for root, _, files in util.sorted_walk( |
| 46 | + lib.directory, ignore=ignore_subdirs |
| 47 | + ): |
| 48 | + yield (root, files) |
| 49 | + else: |
| 50 | + # the reverse-compatible search, with ignore_subdirectories as |
| 51 | + # a direct child of the library root |
| 52 | + ignore_dirs = [ |
| 53 | + os.path.join(lib.directory, x.encode()) for x in ignore_subdirs |
| 54 | + ] |
| 55 | + for root, _, files in os.walk(lib.directory): |
| 56 | + # do not traverse if root is a child of an ignored directory |
| 57 | + if any(root.startswith(ignored) for ignored in ignore_dirs): |
| 58 | + continue |
| 59 | + yield (root, files) |
33 | 60 |
|
34 | 61 | def commands(self):
|
35 | 62 | def print_unimported(lib, opts, args):
|
36 | 63 | ignore_exts = [
|
37 | 64 | ("." + x).encode()
|
38 | 65 | for x in self.config["ignore_extensions"].as_str_seq()
|
39 | 66 | ]
|
40 |
| - ignore_dirs = [ |
41 |
| - os.path.join(lib.directory, x.encode()) |
42 |
| - for x in self.config["ignore_subdirectories"].as_str_seq() |
43 |
| - ] |
44 | 67 | in_folder = set()
|
45 |
| - for root, _, files in os.walk(lib.directory): |
46 |
| - # do not traverse if root is a child of an ignored directory |
47 |
| - if any(root.startswith(ignored) for ignored in ignore_dirs): |
48 |
| - continue |
| 68 | + for root, files in self.walk(lib): |
49 | 69 | for file in files:
|
50 | 70 | # ignore files with ignored extensions
|
51 | 71 | if any(file.endswith(ext) for ext in ignore_exts):
|
|
0 commit comments