Skip to content

Commit

Permalink
Code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed May 14, 2013
1 parent 750795d commit 8a50bfb
Show file tree
Hide file tree
Showing 104 changed files with 644 additions and 449 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ kill_redis:
redis: kill_redis redis: kill_redis
@redis-server redis.conf ; sleep 1 @redis-server redis.conf ; sleep 1
@redis-cli -p 7778 -a hey_you info @redis-cli -p 7778 -a hey_you info

flake:
@flake8 . --ignore=W801,E501
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
3 changes: 1 addition & 2 deletions tests/fixtures/conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com

2 changes: 1 addition & 1 deletion tests/fixtures/conf1.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com
2 changes: 1 addition & 1 deletion tests/fixtures/default.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/file_loader_conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/file_storage_conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/file_storage_conf_2.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/file_storage_conf_3.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/jsonp.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mongo_storage_conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mysql_storage_conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/no_storage_conf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
2 changes: 1 addition & 1 deletion tests/test_app.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down
1 change: 1 addition & 0 deletions tests/test_drop_shadow_filter.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


from thumbor.filters.drop_shadow import Filter from thumbor.filters.drop_shadow import Filter



def test_drop_shadow_filter_regex(): def test_drop_shadow_filter_regex():
reg = Filter.regex reg = Filter.regex


Expand Down
3 changes: 2 additions & 1 deletion tests/test_file_loader.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand All @@ -18,6 +18,7 @@


fixtures_folder = join(abspath(dirname(__file__)), 'fixtures') fixtures_folder = join(abspath(dirname(__file__)), 'fixtures')



class FileLoaderTest(AsyncHTTPTestCase): class FileLoaderTest(AsyncHTTPTestCase):


def get_app(self): def get_app(self):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_focal_points.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


from thumbor.point import FocalPoint from thumbor.point import FocalPoint



def test_focal_point(): def test_focal_point():
point = FocalPoint(x=10.0, y=20.0, weight=3.4) point = FocalPoint(x=10.0, y=20.0, weight=3.4)


assert point.x == 10.0 assert point.x == 10.0
assert point.y == 20.0 assert point.y == 20.0
assert point.weight == 3.4 assert point.weight == 3.4



def test_default_weight_is_one(): def test_default_weight_is_one():
point = FocalPoint(x=10.0, y=20.0) point = FocalPoint(x=10.0, y=20.0)


assert point.weight == 1.0 assert point.weight == 1.0



def test_from_square(): def test_from_square():
point = FocalPoint.from_square(x=10.0, y=20.0, width=100, height=200) point = FocalPoint.from_square(x=10.0, y=20.0, width=100, height=200)
assert point.x == 55.0 assert point.x == 55.0
assert point.y == 110.0 assert point.y == 110.0
assert point.weight == 20000.0 assert point.weight == 20000.0



def test_focal_points_alignments(): def test_focal_points_alignments():
for point in [ for point in [
('left', 'top', 100, 200, 0.0, 0.0), ('left', 'top', 100, 200, 0.0, 0.0),
Expand All @@ -42,11 +46,10 @@ def test_focal_points_alignments():
]: ]:
yield assert_point_from_alignment, point yield assert_point_from_alignment, point



def assert_point_from_alignment(point): def assert_point_from_alignment(point):
comp_point = FocalPoint.from_alignment(point[0], point[1], width=point[2], height=point[3]) comp_point = FocalPoint.from_alignment(point[0], point[1], width=point[2], height=point[3])


assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % (point[4], comp_point.x) assert comp_point.x == point[4], "Expected x => %.2f Got x => %.2f" % (point[4], comp_point.x)
assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % (point[5], comp_point.y) assert comp_point.y == point[5], "Expected y => %.2f Got y => %.2f" % (point[5], comp_point.y)
assert comp_point.weight == 1.0 assert comp_point.weight == 1.0


4 changes: 2 additions & 2 deletions tests/test_meta_transform.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


get_conf_path = lambda filename: abspath(join(dirname(__file__), 'fixtures', filename)) get_conf_path = lambda filename: abspath(join(dirname(__file__), 'fixtures', filename))



class MetaHandlerTestCase(AsyncHTTPTestCase): class MetaHandlerTestCase(AsyncHTTPTestCase):


def get_app(self): def get_app(self):
Expand Down Expand Up @@ -173,6 +174,7 @@ def test_meta_returns_proper_json_for_flip(self):
assert operations[2]['type'] == 'flip_horizontally' assert operations[2]['type'] == 'flip_horizontally'
assert operations[3]['type'] == 'flip_vertically' assert operations[3]['type'] == 'flip_vertically'



class MetaHandlerJSONPTestCase(AsyncHTTPTestCase): class MetaHandlerJSONPTestCase(AsyncHTTPTestCase):


def get_app(self): def get_app(self):
Expand All @@ -187,5 +189,3 @@ def test_meta_returns_proper_json_for_no_ops_with_callback(self):


assert text.strip().startswith('callback({') assert text.strip().startswith('callback({')
assert text.strip().endswith('});') assert text.strip().endswith('});')


1 change: 0 additions & 1 deletion tests/test_urls.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com

3 changes: 1 addition & 2 deletions tests/transform_helper.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com

2 changes: 1 addition & 1 deletion tests/visual_test/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com
4 changes: 3 additions & 1 deletion tests/visual_test/compare_engines.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
REPETITIONS = 200 REPETITIONS = 200
IMAGE_NAME = 'fred' IMAGE_NAME = 'fred'



def get_engine(engine_name): def get_engine(engine_name):
module_name = 'thumbor.engines.%s' % engine_name module_name = 'thumbor.engines.%s' % engine_name
module = __import__(module_name) module = __import__(module_name)
return reduce(getattr, module_name.split('.')[1:], module).Engine return reduce(getattr, module_name.split('.')[1:], module).Engine



def main(): def main():
root = abspath(dirname(__file__)) root = abspath(dirname(__file__))
image = join(root, '%s.jpg' % IMAGE_NAME) image = join(root, '%s.jpg' % IMAGE_NAME)
Expand Down Expand Up @@ -80,7 +82,7 @@ def main():
engine.load(source, '.jpg') engine.load(source, '.jpg')
engine.crop(100, 100, 200, 200) engine.crop(100, 100, 200, 200)
engine.resize(50, 50) engine.resize(50, 50)
result = engine.read('.jpg') engine.read('.jpg')


times[key] = "%.6f" % (time.time() - start) times[key] = "%.6f" % (time.time() - start)


Expand Down
7 changes: 4 additions & 3 deletions tests/visual_test/detect.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# thumbor imaging service # thumbor imaging service
# https://github.com/globocom/thumbor/wiki # https://github.com/globocom/thumbor/wiki


# Licensed under the MIT license: # Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com # Copyright (c) 2011 globo.com timehome@corp.globo.com


Expand Down Expand Up @@ -39,7 +39,7 @@
loaded_cascade_file = cv.Load(cascade_file) loaded_cascade_file = cv.Load(cascade_file)


for image_path in images_path: for image_path in images_path:

with tempfile.NamedTemporaryFile() as temp_file: with tempfile.NamedTemporaryFile() as temp_file:
file_name = temp_file.name file_name = temp_file.name


Expand All @@ -53,7 +53,8 @@


grayscale = cv.LoadImageM(file_name, cv.CV_LOAD_IMAGE_GRAYSCALE) grayscale = cv.LoadImageM(file_name, cv.CV_LOAD_IMAGE_GRAYSCALE)


faces = cv.HaarDetectObjects(grayscale, loaded_cascade_file, faces = cv.HaarDetectObjects(
grayscale, loaded_cascade_file,
cv.CreateMemStorage(), 1.1, 3, cv.CV_HAAR_DO_CANNY_PRUNING, (30, 30)) cv.CreateMemStorage(), 1.1, 3, cv.CV_HAAR_DO_CANNY_PRUNING, (30, 30))


if faces: if faces:
Expand Down
14 changes: 7 additions & 7 deletions thumbor/console.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
from thumbor.context import ServerParameters from thumbor.context import ServerParameters
from thumbor import __version__ from thumbor import __version__



def get_server_parameters(arguments=None): def get_server_parameters(arguments=None):
parser = optparse.OptionParser(usage="thumbor or type thumbor -h (--help) for help", description=__doc__, version=__version__) parser = optparse.OptionParser(usage="thumbor or type thumbor -h (--help) for help", description=__doc__, version=__version__)
parser.add_option("-p", "--port", type="int", dest="port", default=8888, help = "The port to run this thumbor instance at [default: %default]." ) parser.add_option("-p", "--port", type="int", dest="port", default=8888, help="The port to run this thumbor instance at [default: %default].")
parser.add_option("-i", "--ip", dest="ip", default="0.0.0.0", help = "The host address to run this thumbor instance at [default: %default]." ) parser.add_option("-i", "--ip", dest="ip", default="0.0.0.0", help="The host address to run this thumbor instance at [default: %default].")
parser.add_option("-c", "--conf", dest="conf", default="", help = "The path of the configuration file to use for this thumbor instance [default: %default]." ) parser.add_option("-c", "--conf", dest="conf", default="", help="The path of the configuration file to use for this thumbor instance [default: %default].")
parser.add_option("-k", "--keyfile", dest="keyfile", default="", help = "The path of the security key file to use for this thumbor instance [default: %default]." ) parser.add_option("-k", "--keyfile", dest="keyfile", default="", help="The path of the security key file to use for this thumbor instance [default: %default].")
parser.add_option("-l", "--log-level", dest="log_level", default="warning", help = "The log level to be used. Possible values are: debug, info, warning, error, critical or notset. [default: %default]." ) parser.add_option("-l", "--log-level", dest="log_level", default="warning", help="The log level to be used. Possible values are: debug, info, warning, error, critical or notset. [default: %default].")
parser.add_option("-a", "--app", dest="app", default='thumbor.app.ThumborServiceApp', help = "A custom app to use for this thumbor server in case you subclassed ThumborServiceApp [default: %default]." ) parser.add_option("-a", "--app", dest="app", default='thumbor.app.ThumborServiceApp', help="A custom app to use for this thumbor server in case you subclassed ThumborServiceApp [default: %default].")


(options, args) = parser.parse_args(arguments) (options, args) = parser.parse_args(arguments)


Expand All @@ -36,4 +37,3 @@ def get_server_parameters(arguments=None):
keyfile=keyfile, keyfile=keyfile,
log_level=log_level, log_level=log_level,
app_class=options.app) app_class=options.app)

9 changes: 5 additions & 4 deletions thumbor/context.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def __init__(self,
'bottom': self.int_or_0(crop_bottom) 'bottom': self.int_or_0(crop_bottom)
} }


self.should_crop = self.crop['left'] > 0 or \ self.should_crop = \
self.crop['top'] > 0 or \ self.crop['left'] > 0 or \
self.crop['right'] > 0 or \ self.crop['top'] > 0 or \
self.crop['bottom'] > 0 self.crop['right'] > 0 or \
self.crop['bottom'] > 0


self.adaptive = bool(adaptive) self.adaptive = bool(adaptive)
self.fit_in = bool(fit_in) self.fit_in = bool(fit_in)
Expand Down
Loading

0 comments on commit 8a50bfb

Please sign in to comment.