Skip to content
Browse files

Changed all files to use 4spaces instead of 2spaces

  • Loading branch information...
1 parent a6ca937 commit 9d1e82479e3ee9f2132c305281a789a43aeaabd3 Josh Benham committed May 22, 2012
Showing with 114 additions and 126 deletions.
  1. +11 −12 setup.py
  2. +6 −7 squish/colors.py
  3. +43 −52 squish/core.py
  4. +8 −7 squish/helpers.py
  5. +6 −7 squish/optimize.py
  6. +39 −40 squish/statistics.py
  7. +1 −1 squish_r
View
23 setup.py
@@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-
-# vim: sw=2 ts=2
from setuptools import setup, find_packages
with open('README.md') as f:
- readme = f.read()
+ readme = f.read()
with open('LICENSE') as f:
- license = f.read()
+ license = f.read()
setup(
- name='squish',
- version='0.0.1',
- description='Simple image optimization tool',
- long_description=readme,
- author='Josh Benham',
- author_email='joshbenham@gmail.com',
- url='https://github.com/joshbenham/squish',
- license=license,
- packages=find_packages(exclude=('tests', 'docs'))
+ name='squish',
+ version='0.0.1',
+ description='Simple image optimization tool',
+ long_description=readme,
+ author='Josh Benham',
+ author_email='joshbenham@gmail.com',
+ url='https://github.com/joshbenham/squish',
+ license=license,
+ packages=find_packages(exclude=('tests', 'docs'))
)
View
13 squish/colors.py
@@ -1,18 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
-# vim: sw=2 ts=2
from clint.textui import colored
def e(s):
- """Color: Error"""
- return colored.red(s)
+ """Color: Error"""
+ return colored.red(s)
def s(s):
- """Color: Success"""
- return colored.green(s)
+ """Color: Success"""
+ return colored.green(s)
def p(s):
- """Color: Primary"""
- return colored.cyan(s)
+ """Color: Primary"""
+ return colored.cyan(s)
View
95 squish/core.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
-# vim: sw=2 ts=2
import sys
@@ -14,71 +13,63 @@
class Core:
- def main(self):
- self._check_dependencies()
+ def main(self):
+ self._check_dependencies()
- if not args.get(0) or not len(args.files) or "--help" in args.flags:
- self._show_help()
+ if not args.get(0) or not len(args.files) or "--help" in args.flags:
+ self._show_help()
- if "--watch" not in args.flags:
- self._iterate_over_files()
+ if "--watch" not in args.flags:
+ self._iterate_over_files()
- # Iterate over the files and apply optimizations
- def _iterate_over_files(self):
+ # Iterate over the files and apply optimizations
+ def _iterate_over_files(self):
+ stats = Statistics()
- stats = Statistics()
+ for file in args.files:
- for file in args.files:
+ if isimage(file):
+ stats.pre(file)
+ if "--lossy" in args.flags:
+ Optimize.lossy(file)
+ if "--lossless" in args.flags:
+ Optimize.lossless(file)
+ stats.post(file)
- if isimage(file):
+ if "--stats" in args.flags:
+ stats.show()
- stats.pre(file)
- if "--lossy" in args.flags:
- Optimize.lossy(file)
+ # Check to see if all the dependencies have been installed
+ def _check_dependencies(self):
+ imgmin = exists('imgmin')
+ image_optim = exists('image_optim')
- if "--lossless" in args.flags:
- Optimize.lossless(file)
+ if not imgmin or not image_optim:
+ puts(p('Dependencies have not been installed:'))
- stats.post(file)
+ with indent(3):
+ message = 'imgmin - https://github.com/rflynn/imgmin'
+ message = s('' + message) if imgmin else e('' + message)
+ puts(message)
- if "--stats" in args.flags:
- stats.show()
+ message = 'image_optim - http://rubygems.org/gems/image_optim'
+ message = s('' + message) if image_optim else e('' + message)
+ puts(message)
+ sys.exit(1)
- # Check to see if all the dependencies have been installed
- def _check_dependencies(self):
+ # Show the use the help system
+ def _show_help(self):
+ puts(e("Usage: %s [options] <file/folder>" % sys.argv[0]))
- imgmin = exists('imgmin')
- image_optim = exists('image_optim')
+ with indent(3):
+ puts(p("--help ") + "Show the help system")
+ puts(p("--lossy ") + "Apply a lossy optimization on the image(s)")
+ puts(p("--lossless ") + "Apply a lossless optimization on the image(s)")
+ puts(p("--watch ") + "Watch a folder and apply optimizations straight up")
+ puts(p("--stats ") + "Show stats of the optimizations")
- if not imgmin or not image_optim:
- puts(p('Dependencies have not been installed:'))
-
- with indent(3):
- message = 'imgmin - https://github.com/rflynn/imgmin'
- message = s('' + message) if imgmin else e('' + message)
- puts(message)
-
- message = 'image_optim - http://rubygems.org/gems/image_optim'
- message = s('' + message) if image_optim else e('' + message)
- puts(message)
-
- sys.exit(1)
-
-
- # Show the use the help system
- def _show_help(self):
-
- puts(e("Usage: %s [options] <file/folder>" % sys.argv[0]))
-
- with indent(3):
- puts(p("--help ") + "Show the help system")
- puts(p("--lossy ") + "Apply a lossy optimization on the image(s)")
- puts(p("--lossless ") + "Apply a lossless optimization on the image(s)")
- puts(p("--watch ") + "Watch a folder and apply optimizations straight up")
- puts(p("--stats ") + "Show stats of the optimizations")
-
- sys.exit(1)
+ sys.exit(1)
View
15 squish/helpers.py
@@ -1,18 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
-# vim: sw=2 ts=2
import envoy
from PIL import Image
def exists(string):
- return envoy.run("which %s" % string).status_code == 0
+ """Check to see if file exists"""
+ return envoy.run("which %s" % string).status_code == 0
def isimage(file):
- try:
- Image.open(file)
- return True
- except IOError:
- return False
+ """Check to see if image exists"""
+ try:
+ Image.open(file)
+ return True
+ except IOError:
+ return False
View
13 squish/optimize.py
@@ -1,16 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
-# vim: sw=2 ts=2
import envoy
class Optimize:
- @staticmethod
- def lossy(file):
- envoy.run("imgmin %s %s" % (file, file))
+ @staticmethod
+ def lossy(file):
+ envoy.run("imgmin %s %s" % (file, file))
- @staticmethod
- def lossless(file):
- envoy.run("image_optim %s" % file)
+ @staticmethod
+ def lossless(file):
+ envoy.run("image_optim %s" % file)
View
79 squish/statistics.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
-# vim: sw=2 ts=2
import os
@@ -11,54 +10,54 @@
class Statistics:
- # Total files
- files = 0
+ # Total files
+ files = 0
- # File types
- pngs = 0
- jpgs = 0
- gifs = 0
+ # File types
+ pngs = 0
+ jpgs = 0
+ gifs = 0
- # Total size
- preSize = 0
- postSize = 0
+ # Total size
+ preSize = 0
+ postSize = 0
- def pre(self, file):
- self._baseCalculations(file)
- self.preSize += self._getFileSize(file)
+ def pre(self, file):
+ self._baseCalculations(file)
+ self.preSize += self._getFileSize(file)
- def post(self, file):
- self.postSize += self._getFileSize(file)
+ def post(self, file):
+ self.postSize += self._getFileSize(file)
- def show(self):
- puts(p("Statistics:"))
+ def show(self):
+ puts(p("Statistics:"))
- with indent(3):
- puts("Total Files: %s (PNGs %s/JPGs %s/GIFs %s)" % (
- s(self.files),
- s(self.pngs),
- s(self.jpgs),
- s(self.gifs)
- ))
- puts("Original File/Folder Size: %s" % s(round(self.preSize, 2)))
- puts("New File/Folder Size: %s" % s(round(self.postSize, 2)))
- puts("Savings of: %s%%" % s(self._getSavings()))
+ with indent(3):
+ puts("Total Files: %s (PNGs %s/JPGs %s/GIFs %s)" % (
+ s(self.files),
+ s(self.pngs),
+ s(self.jpgs),
+ s(self.gifs)
+ ))
+ puts("Original File/Folder Size: %s" % s(round(self.preSize, 2)))
+ puts("New File/Folder Size: %s" % s(round(self.postSize, 2)))
+ puts("Savings of: %s%%" % s(self._getSavings()))
- def _getSavings(self):
- return round(100 - ((100 * self.postSize) / self.preSize), 2)
+ def _getSavings(self):
+ return round(100 - ((100 * self.postSize) / self.preSize), 2)
- def _getFileSize(self, file):
- return os.stat(file).st_size / 1024.0
+ def _getFileSize(self, file):
+ return os.stat(file).st_size / 1024.0
- def _baseCalculations(self, file):
- self.files += 1
- stream = Image.open(file)
+ def _baseCalculations(self, file):
+ self.files += 1
+ stream = Image.open(file)
- if stream.format == "PNG":
- self.pngs += 1
+ if stream.format == "PNG":
+ self.pngs += 1
- if stream.format == "JPG":
- self.jpgs += 1
+ if stream.format == "JPG":
+ self.jpgs += 1
- if stream.format == "GIF":
- self.gifs += 1
+ if stream.format == "GIF":
+ self.gifs += 1
View
2 squish_r
@@ -5,5 +5,5 @@ from squish.core import Core
if __name__ == "__main__":
- Core().main()
+ Core().main()

1 comment on commit 9d1e824

@richo
richo commented on 9d1e824 May 22, 2012

\o/

Please sign in to comment.
Something went wrong with that request. Please try again.