Skip to content

Commit

Permalink
Make PIL a soft dependency (#74)
Browse files Browse the repository at this point in the history
* Update matter.py

* Update matter.py
  • Loading branch information
Weathercold authored Feb 13, 2022
1 parent 90869e0 commit 1a05515
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions matter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from argparse import ArgumentParser, RawTextHelpFormatter
from os.path import dirname, basename, isdir, exists
from shutil import which, rmtree, copytree, copyfile
from PIL import Image
try:
from PIL import Image
except:
has_PIL = False
else:
has_PIL = True

# Local Matter modules
from utils import *
Expand Down Expand Up @@ -179,13 +184,16 @@ def download_icon(icon_name):


def download_background(background_path):
if not has_PIL:
error("PIL not detected, cannot download background")
info(f"Downloading background image")

url = f"{background_path}"
try:
with request.urlopen(url) as f:
response = f.read()
except HTTPError as err: # A subclass of URLError
error(f"Couldn't get background image ({err.reason})", f"At URL {err.geturl()}")
error(f"Couldn't get background image ({err.reason})", f"At URL {err.geturl()}")
except URLError as err:
error(f"Couldn't get background image ({err.reason})")
bg_path = BACKGROUND_TMP_PATHF.format('background_image')
Expand Down Expand Up @@ -215,7 +223,7 @@ def convert_icon_svg2png(icon_name, whisper=False):
if not has_command("inkscape"):
if not has_command("convert"):
error(
"Stop. Both `inkscape` and `convert` command from imagemagick was not found",
"Stop. Both `inkscape` and `convert` command from imagemagick were not found",
"Consider installing `inkscape` for the best results",
)
else:
Expand Down Expand Up @@ -505,7 +513,7 @@ def do_preinstall_hint():
f"{color_string('Grub Theme'.upper(), fg='lightcyan')}"
f"{color_string(' ]', fg='brightwhite')}"
)
info("Argument -i required. Which icons go to which grub entries?.")
info("Argument -i required. Which icons go to which grub entries?")
info("Your grub entries are:")
do_list_grub_cfg_entries()
info("Look for icons you like at https://materialdesignicons.com/")
Expand Down

0 comments on commit 1a05515

Please sign in to comment.