Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions glue/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from diagonal import DiagonalAlgorithm
from horizontal import HorizontalAlgorithm
from horizontal_bottom import HorizontalBottomAlgorithm
from square import SquareAlgorithm
from vertical import VerticalAlgorithm
from vertical_right import VerticalRightAlgorithm
from .diagonal import DiagonalAlgorithm
from .horizontal import HorizontalAlgorithm
from .horizontal_bottom import HorizontalBottomAlgorithm
from .square import SquareAlgorithm
from .vertical import VerticalAlgorithm
from .vertical_right import VerticalRightAlgorithm

algorithms = {'diagonal': DiagonalAlgorithm,
'horizontal': HorizontalAlgorithm,
Expand Down
25 changes: 14 additions & 11 deletions glue/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import argparse

from PIL import __version__ as PILVersion
from PIL import Image as PImage

from glue.formats import formats
Expand All @@ -20,13 +21,13 @@ def main(argv=None):

parser.add_argument("--source", "-s",
dest="source",
type=unicode,
type=str,
default=os.environ.get('GLUE_SOURCE', None),
help="Source path")

parser.add_argument("--output", "-o",
dest="output",
type=unicode,
type=str,
default=os.environ.get('GLUE_OUTPUT', None),
help="Output path")

Expand Down Expand Up @@ -80,7 +81,7 @@ def main(argv=None):
group.add_argument("-a", "--algorithm",
dest="algorithm",
metavar='NAME',
type=unicode,
type=str,
default=os.environ.get('GLUE_ALGORITHM', 'square'),
choices=['square', 'vertical', 'horizontal',
'vertical-right', 'horizontal-bottom',
Expand All @@ -92,15 +93,15 @@ def main(argv=None):
group.add_argument("--ordering",
dest="algorithm_ordering",
metavar='NAME',
type=unicode,
type=str,
default=os.environ.get('GLUE_ORDERING', 'maxside'),
choices=['maxside', 'width', 'height', 'area', 'filename',
'-maxside', '-width', '-height', '-area', '-filename'],
help=("Ordering criteria: maxside, width, height, area or "
"filename (default: maxside)"))

# Populate the parser with options required by other formats
for format in formats.itervalues():
for format in formats.values():
format.populate_argument_parser(parser)

#
Expand Down Expand Up @@ -146,7 +147,7 @@ def add_deprecated_argument(*args, **kwargs):
options.enabled_formats.remove('img')

# Fail if any of the deprecated arguments is used
for argument in deprecated_arguments.iterkeys():
for argument in deprecated_arguments.keys():
if getattr(options, argument, None):
parser.error(("{0} argument is deprectated "
"since v0.3").format(deprecated_arguments[argument]))
Expand Down Expand Up @@ -233,16 +234,16 @@ def add_deprecated_argument(*args, **kwargs):
manager.process()
else:
manager.process()
except exceptions.ValidationError, e:
except exceptions.ValidationError as e:
sys.stderr.write(e.args[0])
return e.error_code
except exceptions.SourceImagesNotFoundError, e:
except exceptions.SourceImagesNotFoundError as e:
sys.stderr.write("Error: No images found in %s.\n" % e.args[0])
return e.error_code
except exceptions.NoSpritesFoldersFoundError, e:
except exceptions.NoSpritesFoldersFoundError as e:
sys.stderr.write("Error: No sprites folders found in %s.\n" % e.args[0])
return e.error_code
except exceptions.PILUnavailableError, e:
except exceptions.PILUnavailableError as e:
sys.stderr.write(("Error: PIL {0} decoder is unavailable"
"Please read the documentation and "
"install it before spriting this kind of "
Expand All @@ -259,13 +260,15 @@ def add_deprecated_argument(*args, **kwargs):
sys.stderr.write("\n")
sys.stderr.write("Version: {0}\n".format(__version__))
sys.stderr.write("Python: {0}\n".format(sys.version))
sys.stderr.write("PIL version: {0}\n".format(PImage.VERSION))
sys.stderr.write("PIL version: {0}\n".format(PILVersion))
sys.stderr.write("Platform: {0}\n".format(platform.platform()))
sys.stderr.write("Config: {0}\n".format(vars(options)))
sys.stderr.write("Args: {0}\n\n".format(sys.argv))
sys.stderr.write(traceback.format_exc())
sys.stderr.write("=" * 80)
sys.stderr.write("\n")
import pdb
pdb.post_mortem(sys.exc_info()[-1])
return 1

return 0
Expand Down
18 changes: 9 additions & 9 deletions glue/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys
import copy
import hashlib
import StringIO
import ConfigParser
from io import StringIO, BytesIO
import configparser as ConfigParser

from PIL import Image as PILImage

Expand Down Expand Up @@ -48,16 +48,16 @@ def __init__(self, path, config):
with open(self.path, "rb") as img:
self._image_data = img.read()

print "\t{0} added to sprite".format(self.filename)
print("\t{0} added to sprite".format(self.filename))

@cached_property
def image(self):
"""Return a Pil representation of this image """

if sys.version < '3':
imageio = StringIO.StringIO(self._image_data)
imageio = StringIO(self._image_data)
else:
imageio = StringIO.BytesIO(self._image_data)
imageio = BytesIO(self._image_data)

try:
source_image = PILImage.open(imageio)
Expand All @@ -70,7 +70,7 @@ def image(self):
img.paste(source_image, (0, 0), mask=mask)
else:
img.paste(source_image, (0, 0))
except IOError, e:
except IOError as e:
raise PILUnavailableError(e.args[0].split()[1])
finally:
imageio.close()
Expand Down Expand Up @@ -119,7 +119,7 @@ def _generate_spacing_info(self, data):
else:
data = [0] * 4

return map(int, data)
return list(map(int, data))

@cached_property
def horizontal_spacing(self):
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(self, path, config, name=None):
if ratio_output_key not in self.config:
self.config[ratio_output_key] = img_format.output_path(ratio)

print "Processing '{0}':".format(self.name)
print("Processing '{0}':".format(self.name))

# Generate sprite map
self.process()
Expand All @@ -220,7 +220,7 @@ def hash(self):
hash_list.append(os.path.relpath(image.path))
hash_list.append(image._image_data)

for key, value in self.config.iteritems():
for key, value in self.config.items():
hash_list.append(key)
hash_list.append(value)

Expand Down
2 changes: 1 addition & 1 deletion glue/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate(self):
@property
def format_label(self):
from glue.formats import formats
return dict((v,k) for k, v in formats.iteritems())[self.__class__]
return dict((v,k) for k, v in formats.items())[self.__class__]

@classmethod
def populate_argument_parser(cls, parser):
Expand Down
2 changes: 1 addition & 1 deletion glue/formats/caat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from base import BaseJSONFormat
from .base import BaseJSONFormat


class CAATFormat(BaseJSONFormat):
Expand Down
2 changes: 1 addition & 1 deletion glue/formats/cocos2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from base import BasePlistFormat
from .base import BasePlistFormat


class Cocos2dFormat(BasePlistFormat):
Expand Down
16 changes: 8 additions & 8 deletions glue/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import codecs

from glue import __version__
from base import JinjaTextFormat
from .base import JinjaTextFormat

from ..exceptions import ValidationError

Expand Down Expand Up @@ -54,20 +54,20 @@ def populate_argument_parser(cls, parser):

group.add_argument("--namespace",
dest="css_namespace",
type=unicode,
type=str,
default=os.environ.get('GLUE_CSS_NAMESPACE', 'sprite'),
help="Namespace for all css classes (default: sprite)")

group.add_argument("--sprite-namespace",
dest="css_sprite_namespace",
type=unicode,
type=str,
default=os.environ.get('GLUE_CSS_SPRITE_NAMESPACE',
'{sprite_name}'),
help="Namespace for all sprites (default: {sprite_name})")

group.add_argument("-u", "--url",
dest="css_url",
type=unicode,
type=str,
default=os.environ.get('GLUE_CSS_URL', ''),
help="Prepend this string to the sprites path")

Expand All @@ -94,7 +94,7 @@ def populate_argument_parser(cls, parser):

group.add_argument("--separator",
dest="css_separator",
type=unicode,
type=str,
default=os.environ.get('GLUE_CSS_SEPARATOR', '-'),
metavar='SEPARATOR',
help=("Customize the separator used to join CSS class "
Expand All @@ -103,7 +103,7 @@ def populate_argument_parser(cls, parser):

group.add_argument("--pseudo-class-separator",
dest="css_pseudo_class_separator",
type=unicode,
type=str,
default=os.environ.get('GLUE_CSS_PSEUDO_CLASS_SEPARATOR', '__'),
metavar='SEPARATOR',
help=("Customize the separator glue will use in order "
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_context(self, *args, **kwargs):
if self.sprite.config['css_url']:
context['sprite_path'] = '{0}{1}'.format(self.sprite.config['css_url'], context['sprite_filename'])

for r, ratio in context['ratios'].iteritems():
for r, ratio in context['ratios'].items():
ratio['sprite_path'] = '{0}{1}'.format(self.sprite.config['css_url'], ratio['sprite_filename'])

# Add cachebuster if required
Expand All @@ -174,7 +174,7 @@ def apply_cachebuster(path):

context['sprite_path'] = apply_cachebuster(context['sprite_path'])

for r, ratio in context['ratios'].iteritems():
for r, ratio in context['ratios'].items():
ratio['sprite_path'] = apply_cachebuster(ratio['sprite_path'])

return context
Expand Down
8 changes: 4 additions & 4 deletions glue/formats/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def populate_argument_parser(cls, parser):

group.add_argument("--img",
dest="img_dir",
type=unicode,
type=str,
default=os.environ.get('GLUE_IMG', True),
metavar='DIR',
help="Output directory for img files")
Expand All @@ -38,13 +38,13 @@ def populate_argument_parser(cls, parser):

group.add_argument("-p", "--padding",
dest="padding",
type=unicode,
type=str,
default=os.environ.get('GLUE_PADDING', '0'),
help="Force this padding in all images")

group.add_argument("--margin",
dest="margin",
type=unicode,
type=str,
default=os.environ.get('GLUE_MARGIN', '0'),
help="Force this margin in all images")

Expand All @@ -57,7 +57,7 @@ def populate_argument_parser(cls, parser):

group.add_argument("--ratios",
dest="ratios",
type=unicode,
type=str,
default=os.environ.get('GLUE_RATIOS', '1'),
help="Create sprites based on these ratios")

Expand Down
4 changes: 2 additions & 2 deletions glue/formats/jsonformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except ImportError:
from ordereddict import OrderedDict

from base import BaseJSONFormat
from .base import BaseJSONFormat


class JSONFormat(BaseJSONFormat):
Expand All @@ -29,7 +29,7 @@ def populate_argument_parser(cls, parser):
group.add_argument("--json-format",
dest="json_format",
metavar='NAME',
type=unicode,
type=str,
default=os.environ.get('GLUE_JSON_FORMAT', 'array'),
choices=['array', 'hash'],
help=("JSON structure format (array, hash)"))
Expand Down
2 changes: 1 addition & 1 deletion glue/formats/less.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from css import CssFormat
from .css import CssFormat


class LessFormat(CssFormat):
Expand Down
2 changes: 1 addition & 1 deletion glue/formats/scss.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from css import CssFormat
from .css import CssFormat


class ScssFormat(CssFormat):
Expand Down
7 changes: 6 additions & 1 deletion glue/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
import sys
import contextlib
from StringIO import StringIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO




def round_up(value):
Expand Down
4 changes: 2 additions & 2 deletions glue/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def save(self):
format = format_cls(sprite=sprite)
format.validate()
if format.needs_rebuild() or sprite.config['force']:
print "Format '{0}' for sprite '{1}' needs rebuild...".format(format_name, sprite.name)
print("Format '{0}' for sprite '{1}' needs rebuild...".format(format_name, sprite.name))
format.build()
else:
print "Format '{0}'' for sprite '{1}' already exists...".format(format_name, sprite.name)
print("Format '{0}'' for sprite '{1}' already exists...".format(format_name, sprite.name))
2 changes: 1 addition & 1 deletion glue/managers/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ def generate_hash(self):

def signal_handler(self, signal, frame):
""" Gracefully close the app if Ctrl+C is pressed."""
print 'You pressed Ctrl+C!'
print('You pressed Ctrl+C!')
sys.exit(0)
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@
]
},
zip_safe = False,
use_2to3=True
)