summaryrefslogtreecommitdiff
path: root/pywal
diff options
context:
space:
mode:
authorLorenz Leitner <lorenz.leitner@student.tugraz.at>2019-03-15 09:49:21 +0100
committerLorenz Leitner <lorenz.leitner@student.tugraz.at>2019-03-15 09:49:21 +0100
commit3a95122157071c44f521210858a5c6bacfe9c3bb (patch)
treeff0eb9b5626219645e163cafc3b3e5abc6c4d927 /pywal
parentb91ecad12bad39a41611b41f5db436a2cf4f34d7 (diff)
Iterative images recursively
Diffstat (limited to 'pywal')
-rw-r--r--pywal/image.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/pywal/image.py b/pywal/image.py
index ecd46ff..71a12f0 100644
--- a/pywal/image.py
+++ b/pywal/image.py
@@ -22,9 +22,10 @@ def get_image_dir_recursive(img_dir):
images = []
for path, subdirs, files in os.walk(img_dir):
for name in files:
- if name.lower().endswith(file_types) and not name.endswith(current_wall):
- images.append(os.path.join(path, name))
-
+ if name.lower().endswith(file_types):
+ if name.endswith(current_wall):
+ current_wall = os.path.join(path, name)
+ images.append(os.path.join(path, name))
return images, current_wall
@@ -59,18 +60,24 @@ def get_random_image_recursive(img_dir):
"""Pick a random image file from a directory recursively."""
images, current_wall = get_image_dir_recursive(img_dir)
+ if len(images) > 2 and current_wall in images:
+ images.remove(current_wall)
+
if not images:
logging.error("No images found in directory.")
sys.exit(1)
- print(images)
random.shuffle(images)
return os.path.join("", images[0])
-def get_next_image(img_dir):
+def get_next_image(img_dir, recursive):
"""Get the next image in a dir."""
- images, current_wall = get_image_dir(img_dir)
+ if recursive:
+ images, current_wall = get_image_dir_recursive(img_dir)
+ else:
+ images, current_wall = get_image_dir(img_dir)
+
images.sort(key=lambda img: [int(x) if x.isdigit() else x
for x in re.split('([0-9]+)', img)])
@@ -86,7 +93,7 @@ def get_next_image(img_dir):
except IndexError:
image = images[0]
- return os.path.join(img_dir, image)
+ return os.path.join(img_dir if not recursive else "", image)
def get(img, cache_dir=CACHE_DIR, iterative=False, recursive=False):
@@ -97,7 +104,7 @@ def get(img, cache_dir=CACHE_DIR, iterative=False, recursive=False):
elif os.path.isdir(img):
if iterative:
- wal_img = get_next_image(img)
+ wal_img = get_next_image(img, recursive)
else:
if recursive: