summaryrefslogtreecommitdiff
path: root/pywal/image.py
diff options
context:
space:
mode:
authorDylan Araps <dylanaraps@users.noreply.github.com>2017-07-23 15:37:14 +1000
committerGitHub <noreply@github.com>2017-07-23 15:37:14 +1000
commit0c1d76e2b3611b541316dc8d7eb67f18cec5e7f2 (patch)
treeaaf8141c62789dcfc4f72af24ae96df71459a084 /pywal/image.py
parent9c871ec567504c2566c4ce9f3d382f544cb62b57 (diff)
parent07b8ad8e0d97f54277c2e744f745ba3e47d0e53c (diff)
Merge pull request #52 from dylanaraps/api
api: Start work on a proper api.
Diffstat (limited to 'pywal/image.py')
-rw-r--r--pywal/image.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/pywal/image.py b/pywal/image.py
index 394967d..eec05f6 100644
--- a/pywal/image.py
+++ b/pywal/image.py
@@ -5,37 +5,33 @@ import os
import pathlib
import random
-from pywal.settings import CACHE_DIR
-from pywal import util
+from .settings import __cache_dir__
+from . import util
+from . import wallpaper
def get_random_image(img_dir):
"""Pick a random image file from a directory."""
- current_wall = CACHE_DIR / "wal"
+ current_wall = wallpaper.get()
+ current_wall = os.path.basename(current_wall[0])
- if current_wall.is_file():
- current_wall = util.read_file(current_wall)
- current_wall = os.path.basename(current_wall[0])
-
- # Add all images to a list excluding the current wallpaper.
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
images = [img for img in os.scandir(img_dir)
if img.name.endswith(file_types) and img.name != current_wall]
- # If no images are found, use the current wallpaper.
if not images:
print("image: No new images found (nothing to do), exiting...")
quit(1)
- return img_dir / random.choice(images).name
+ return str(img_dir / random.choice(images).name)
-def get_image(img):
+def get(img, cache_dir=__cache_dir__):
"""Validate image input."""
image = pathlib.Path(img)
if image.is_file():
- wal_img = image
+ wal_img = str(image)
elif image.is_dir():
wal_img = get_random_image(image)
@@ -44,5 +40,8 @@ def get_image(img):
print("error: No valid image file found.")
exit(1)
+ # Cache the image file path.
+ util.save_file(wal_img, cache_dir / "wal")
+
print("image: Using image", wal_img)
- return str(wal_img)
+ return wal_img