You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/06/03 21:19:28 UTC
[29/38] git commit: [#6255] change to work with either PIL or Pillow
[#6255] change to work with either PIL or Pillow
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/686ae83a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/686ae83a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/686ae83a
Branch: refs/heads/cj/6218
Commit: 686ae83a1b7e305d0363b309ecb2ca36f95d3735
Parents: 4caff7c
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon May 20 17:26:07 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Jun 3 17:01:51 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/filesystem.py | 12 ++++++------
Allura/allura/tests/functional/test_admin.py | 11 ++++++-----
.../allura/tests/functional/test_neighborhood.py | 6 +++---
.../tests/functional/test_forum_admin.py | 4 ++--
.../forgetracker/tests/functional/test_root.py | 9 +++++----
ForgeWiki/forgewiki/tests/functional/test_root.py | 10 +++++-----
scripts/rethumb.py | 5 ++---
7 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/Allura/allura/model/filesystem.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
index 41a64ab..c56e595 100644
--- a/Allura/allura/model/filesystem.py
+++ b/Allura/allura/model/filesystem.py
@@ -20,7 +20,7 @@ from cStringIO import StringIO
import logging
import pylons
-import Image
+import PIL
from gridfs import GridFS
from tg import config
from paste.deploy.converters import asint
@@ -136,9 +136,9 @@ class File(MappedClass):
if square and height != width:
sz = max(width, height)
if 'transparency' in image.info:
- new_image = Image.new('RGBA', (sz,sz))
+ new_image = PIL.Image.new('RGBA', (sz,sz))
else:
- new_image = Image.new('RGB', (sz,sz), 'white')
+ new_image = PIL.Image.new('RGB', (sz,sz), 'white')
if height < width:
# image is wider than tall, so center horizontally
new_image.paste(image, ((width-height)/2, 0))
@@ -148,7 +148,7 @@ class File(MappedClass):
image = new_image
if thumbnail_size:
- image.thumbnail(thumbnail_size, Image.ANTIALIAS)
+ image.thumbnail(thumbnail_size, PIL.Image.ANTIALIAS)
thumbnail_meta = thumbnail_meta or {}
thumbnail = cls(
@@ -175,9 +175,9 @@ class File(MappedClass):
return None, None
try:
- image = Image.open(fp)
+ image = PIL.Image.open(fp)
except IOError as e:
- log.error('Error opening image %s %s', filename, e)
+ log.error('Error opening image %s %s', filename, e, exc_info=True)
return None, None
format = image.format
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 9741d3c..79f595e 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -18,9 +18,10 @@
import re
import os, allura
import pkg_resources
-import Image, StringIO
+import StringIO
from contextlib import contextmanager
+import PIL
from nose.tools import assert_equals
from ming.orm.ormsession import ThreadLocalORMSession
@@ -216,7 +217,7 @@ class TestProjectAdmin(TestController):
short_description='A Test Project'),
upload_files=[upload])
r = self.app.get('/p/test/icon')
- image = Image.open(StringIO.StringIO(r.body))
+ image = PIL.Image.open(StringIO.StringIO(r.body))
assert image.size == (48,48)
r = self.app.get('/p/test/icon?foo=bar')
@@ -236,11 +237,11 @@ class TestProjectAdmin(TestController):
project = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
filename = project.get_screenshots()[0].filename
r = self.app.get('/p/test/screenshot/'+filename)
- uploaded = Image.open(file_path)
- screenshot = Image.open(StringIO.StringIO(r.body))
+ uploaded = PIL.Image.open(file_path)
+ screenshot = PIL.Image.open(StringIO.StringIO(r.body))
assert uploaded.size == screenshot.size
r = self.app.get('/p/test/screenshot/'+filename+'/thumb')
- thumb = Image.open(StringIO.StringIO(r.body))
+ thumb = PIL.Image.open(StringIO.StringIO(r.body))
assert thumb.size == (150,150)
#FIX: home pages don't currently support screenshots (now that they're a wiki);
# reinstate this code (or appropriate) when we have a macro for that
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index a641f74..c45d50e 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -20,7 +20,7 @@ import os
from cStringIO import StringIO
import urllib2
-import Image
+import PIL
from tg import config
from nose.tools import assert_equal
from ming.orm.ormsession import ThreadLocalORMSession
@@ -234,7 +234,7 @@ class TestNeighborhood(TestController):
params=dict(name='Mozq1', css='', homepage='# MozQ1'),
extra_environ=dict(username='root'), upload_files=[upload])
r = self.app.get('/adobe/icon')
- image = Image.open(StringIO(r.body))
+ image = PIL.Image.open(StringIO(r.body))
assert image.size == (48, 48)
r = self.app.get('/adobe/icon?foo=bar')
@@ -788,7 +788,7 @@ class TestNeighborhood(TestController):
assert 'Updated description.' in r
r = self.app.get('/adobe/_admin/awards/%s' % foo_id, extra_environ=dict(username='root'))
r = self.app.get('/adobe/_admin/awards/%s/icon' % foo_id, extra_environ=dict(username='root'))
- image = Image.open(StringIO(r.body))
+ image = PIL.Image.open(StringIO(r.body))
assert image.size == (48, 48)
self.app.post('/adobe/_admin/awards/grant',
params=dict(grant='FOO', recipient='adobe-1'),
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
index d8d460a..a1bc1a2 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
@@ -17,10 +17,10 @@
import os
import allura
-import Image
from StringIO import StringIO
import logging
+import PIL
from alluratest.controller import TestController
from allura.lib import helpers as h
@@ -136,7 +136,7 @@ class TestForumAdmin(TestController):
},
upload_files=[upload]),
r = self.app.get('/discussion/testforum/icon')
- image = Image.open(StringIO(r.body))
+ image = PIL.Image.open(StringIO(r.body))
assert image.size == (48,48)
def test_delete_undelete(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 7423e2b..5c2be7a 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -21,9 +21,10 @@ import urllib
import os
import time
import json
-import Image, StringIO
+import StringIO
import allura
+import PIL
from mock import patch
from nose.tools import assert_true, assert_false, assert_equal, assert_in
from nose.tools import assert_raises, assert_not_in
@@ -543,13 +544,13 @@ class TestFunctionalController(TrackerTestController):
ticket = tm.Ticket.query.find({'ticket_num':1}).first()
filename = ticket.attachments.first().filename
- uploaded = Image.open(file_path)
+ uploaded = PIL.Image.open(file_path)
r = self.app.get('/bugs/1/attachment/'+filename)
- downloaded = Image.open(StringIO.StringIO(r.body))
+ downloaded = PIL.Image.open(StringIO.StringIO(r.body))
assert uploaded.size == downloaded.size
r = self.app.get('/bugs/1/attachment/'+filename+'/thumb')
- thumbnail = Image.open(StringIO.StringIO(r.body))
+ thumbnail = PIL.Image.open(StringIO.StringIO(r.body))
assert thumbnail.size == (100,100)
def test_sidebar_static_page(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 362d8bd..9e8cf58 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -18,12 +18,12 @@
# under the License.
import os
-import Image, StringIO
+import StringIO
import allura
import json
+import PIL
from nose.tools import assert_true, assert_equal, assert_in
-
from ming.orm.ormsession import ThreadLocalORMSession
from mock import patch
@@ -379,13 +379,13 @@ class TestRootController(TestController):
page = model.Page.query.find(dict(title='TEST')).first()
filename = page.attachments.first().filename
- uploaded = Image.open(file_path)
+ uploaded = PIL.Image.open(file_path)
r = self.app.get('/wiki/TEST/attachment/'+filename)
- downloaded = Image.open(StringIO.StringIO(r.body))
+ downloaded = PIL.Image.open(StringIO.StringIO(r.body))
assert uploaded.size == downloaded.size
r = self.app.get('/wiki/TEST/attachment/'+filename+'/thumb')
- thumbnail = Image.open(StringIO.StringIO(r.body))
+ thumbnail = PIL.Image.open(StringIO.StringIO(r.body))
assert thumbnail.size == (255,255)
# Make sure thumbnail is present
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/686ae83a/scripts/rethumb.py
----------------------------------------------------------------------
diff --git a/scripts/rethumb.py b/scripts/rethumb.py
index 0cae31c..5f753ff 100644
--- a/scripts/rethumb.py
+++ b/scripts/rethumb.py
@@ -19,7 +19,7 @@ import sys
import time
import pkg_resources
-import Image
+import PIL
import tg
from pylons import tmpl_context as c
from paste.deploy.converters import asint
@@ -55,7 +55,7 @@ class RethumbCommand(base.Command):
base.log.warning("There are %d thumbnails for '%s' - consider clearing them with --force", count, attachment.filename)
return
- image = Image.open(attachment.rfile())
+ image = PIL.Image.open(attachment.rfile())
del doc['content_type']
del doc['filename']
att_cls.save_thumbnail(attachment.filename, image, attachment.content_type, att_cls.thumbnail_size, doc, square=True)
@@ -133,4 +133,3 @@ if __name__ == '__main__':
command = RethumbCommand('rethumb')
command.parse_args(sys.argv)
command.command()
-