Skip to content

Commit

Permalink
Merge pull request #134 from nikolaizombie1/fix-show-all-subfolders-s…
Browse files Browse the repository at this point in the history
…ymlink-bug

Fix bug by using glob function that follows symlinks.
  • Loading branch information
anufrievroman authored Jan 25, 2025
2 parents c12fc30 + 3ab522c commit 856254a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions waypaper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import os
import random
import shutil
from pathlib import Path

from pathlib import Path
from typing import List
from glob import glob

from waypaper.options import IMAGE_EXTENSIONS, BACKEND_OPTIONS

Expand All @@ -23,8 +26,9 @@ def get_image_paths(backend: str,
only_gifs: bool = False,
depth: int = 1):
"""Get a list of file paths depending on the filters that were requested"""
if depth < 0:
return get_image_paths_infinite_recursion(backend, root_folder, include_hidden, only_gifs)
image_paths = []

for root, directories, files in os.walk(root_folder):
# Remove hidden files from consideration:
for directory in directories:
Expand All @@ -37,7 +41,8 @@ def get_image_paths(backend: str,

# Remove deep folders from consideration:
if depth is not None and root != root_folder:
current_depth = root.count(os.path.sep) - str(root_folder).count(os.path.sep)
current_depth = root.count(os.path.sep) - str(root_folder).count(
os.path.sep)
if current_depth > depth:
continue

Expand All @@ -54,6 +59,24 @@ def get_image_paths(backend: str,
return image_paths


def get_image_paths_infinite_recursion(backend: str,
root_folder: str,
include_hidden: bool = False,
only_gifs: bool = False):
"""Get a list of file paths depending on the filters that were requested"""
paths = os.walk(root_folder, followlinks=True)
paths = map(lambda x: map(lambda y: os.path.join(x[0], y), x[2]), paths)
paths = [ x for xs in paths for x in xs ]
print(paths)
if only_gifs:
paths = list(filter(lambda f: f.lower().endswith(".gif"),paths))
else:
paths = list(filter(lambda x: has_image_extension(x, backend), paths))
if not include_hidden:
paths = list(filter(lambda x: not x.startswith(".") , paths))
return paths


def get_random_file(backend: str,
folder: str,
include_subfolders: bool,
Expand Down

0 comments on commit 856254a

Please sign in to comment.