From d0e9f843e23196f790b640327bef3718e74b0347 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 8 Apr 2013 11:19:56 +0300 Subject: [PATCH] PIL: Support systems with Pillow and without Fixes for systems with Pillow, but leaves a "try: except ImportError" to support anything that doesn't have a PIL top level import. Signed-off-by: Alon Levy --- extlib/freesound/audioprocessing.py | 2 +- mediagoblin/media_types/ascii/asciitoimage.py | 11 ++++++++--- mediagoblin/media_types/ascii/processing.py | 7 +++++-- mediagoblin/media_types/audio/spectrogram.py | 5 ++++- mediagoblin/media_types/audio/transcoders.py | 5 ++++- mediagoblin/media_types/image/processing.py | 5 ++++- mediagoblin/media_types/video/transcoders.py | 5 ++++- mediagoblin/tests/test_exif.py | 5 ++++- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/extlib/freesound/audioprocessing.py b/extlib/freesound/audioprocessing.py index c1dfe2eb..2c2b35b5 100644 --- a/extlib/freesound/audioprocessing.py +++ b/extlib/freesound/audioprocessing.py @@ -20,7 +20,7 @@ # Bram de Jong # 2012, Joar Wandborg -import Image, ImageDraw, ImageColor #@UnresolvedImport +from PIL import Image, ImageDraw, ImageColor #@UnresolvedImport from functools import partial import math import numpy diff --git a/mediagoblin/media_types/ascii/asciitoimage.py b/mediagoblin/media_types/ascii/asciitoimage.py index 108de023..786941f6 100644 --- a/mediagoblin/media_types/ascii/asciitoimage.py +++ b/mediagoblin/media_types/ascii/asciitoimage.py @@ -14,9 +14,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import Image -import ImageFont -import ImageDraw +try: + from PIL import Image + from PIL import ImageFont + from PIL import ImageDraw +except ImportError: + import Image + import ImageFont + import ImageDraw import logging import pkg_resources import os diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index 309aab0a..2f6079be 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -15,7 +15,10 @@ # along with this program. If not, see . import chardet import os -import Image +try: + from PIL import Image +except ImportError: + import Image import logging from mediagoblin import mg_globals as mgg @@ -42,7 +45,7 @@ def process_ascii(proc_state): """Code to process a txt file. Will be run by celery. A Workbench() represents a local tempory dir. It is automatically - cleaned up when this function exits. + cleaned up when this function exits. """ entry = proc_state.entry workbench = proc_state.workbench diff --git a/mediagoblin/media_types/audio/spectrogram.py b/mediagoblin/media_types/audio/spectrogram.py index 458855c1..dd4d0299 100644 --- a/mediagoblin/media_types/audio/spectrogram.py +++ b/mediagoblin/media_types/audio/spectrogram.py @@ -19,7 +19,10 @@ # Bram de Jong # 2012, Joar Wandborg -from PIL import Image +try: + from PIL import Image +except ImportError: + import Image import math import numpy diff --git a/mediagoblin/media_types/audio/transcoders.py b/mediagoblin/media_types/audio/transcoders.py index 3a9a2125..84e6af7e 100644 --- a/mediagoblin/media_types/audio/transcoders.py +++ b/mediagoblin/media_types/audio/transcoders.py @@ -15,7 +15,10 @@ # along with this program. If not, see . import logging -import Image +try: + from PIL import Image +except ImportError: + import Image from mediagoblin.processing import BadMediaFail from mediagoblin.media_types.audio import audioprocessing diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index e951ef29..93f9d03e 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -14,7 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import Image +try: + from PIL import Image +except ImportError: + import Image import os import logging diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index 58b2c0d4..90a767dd 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -26,7 +26,10 @@ import pygst pygst.require('0.10') import gst import struct -import Image +try: + from PIL import Image +except ImportError: + import Image from gst.extend import discoverer diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py index 5eeaa676..824de3c2 100644 --- a/mediagoblin/tests/test_exif.py +++ b/mediagoblin/tests/test_exif.py @@ -15,7 +15,10 @@ # along with this program. If not, see . import os -import Image +try: + from PIL import Image +except ImportError: + import Image from mediagoblin.tools.exif import exif_fix_image_orientation, \ extract_exif, clean_exif, get_gps_data, get_useful -- 2.25.1