backend: Error handling

This commit is contained in:
Dylan Araps 2018-03-31 13:28:11 +11:00
parent 277edbc5e0
commit c10f7e7323
4 changed files with 17 additions and 3 deletions

View File

@ -3,7 +3,13 @@ Generate a colorscheme using ColorThief.
"""
import sys
from colorthief import ColorThief
try:
from colorthief import ColorThief
except ImportError:
print("Error: ColorThief wasn't found on your system.",
"Try another backend. (wal --backend)")
sys.exit(1)
from .. import util

View File

@ -1,7 +1,9 @@
"""
Generate a colorscheme using Colorz.
"""
import shutil
import subprocess
import sys
from .. import util
@ -40,6 +42,11 @@ def adjust(colors, light):
def get(img, light=False):
"""Get colorscheme."""
if not shutil.which("colorz"):
print("Error: Colorz wasn't found on your system.",
"Try another backend. (wal --backend)")
sys.exit(1)
colors = gen_colors(img)
colors = [color.decode('UTF-8').split()[0] for color in colors]
return adjust(colors, light)

View File

@ -26,8 +26,8 @@ def has_im():
elif shutil.which("convert"):
return ["convert"]
print("error: imagemagick not found, exiting...\n"
"error: wal requires imagemagick to function.")
print("Error: ImageMagick wasn't found on your system.",
"Try another backend. (wal --backend)")
sys.exit(1)

View File

@ -3,6 +3,7 @@ Generate a palette using various backends.
"""
import os
import re
import shutil
import sys
from . import backends