From 94a833d3bd9534b5e8b1487c78ddf7ba8bc0d3a9 Mon Sep 17 00:00:00 2001 From: Greg Darke Date: Sun, 15 Mar 2009 12:34:30 +1100 Subject: [PATCH] Move the PIL imports to the module scope, and add a warning if they are not found --- wallchanger.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wallchanger.py b/wallchanger.py index 7d6cd6a..74be97b 100755 --- a/wallchanger.py +++ b/wallchanger.py @@ -6,6 +6,10 @@ import commands, sys, os, os.path, time import logging +try: + import PIL, PIL.Image +except ImportError: + PIL = None __all__ = ("init", "set_image") @@ -85,8 +89,11 @@ class BaseChanger(object): def convert_image_format(self, filename, format='BMP', allowAlpha=False, extension='.bmp'): """Convert the image to another format, and store it in a local place""" if not os.path.exists(filename): + logger.warn('The input file "%s" does not exist, so it will not be converted', filename) + return filename, False + if PIL is None: + logger.warn('PIL could not be found, not converting image format') return filename, False - import PIL, PIL.Image self.remove_old_image_cache() output_name = os.path.join(self._ConvertedWallpaperLocation, '%s%s' % (time.time(), extension)) -- 2.39.2