Merge branch 'master' of git://github.com/kalmi/Trimage

Conflicts:
	src/trimage/trimage.py
This commit is contained in:
Kilian Valkhof 2010-04-21 12:23:38 +02:00
commit 7cf707d5a3
9 changed files with 31 additions and 74 deletions

View file

@ -1,5 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys
win=(sys.platform == "win32")
if win:
import py2exe
sys.path.append("src/trimage")
from distutils.core import setup from distutils.core import setup
setup(name = "trimage", setup(name = "trimage",
@ -11,8 +17,7 @@ setup(name = "trimage",
license = "MIT license", license = "MIT license",
package_dir = {'trimage' : 'src/trimage'}, package_dir = {'trimage' : 'src/trimage'},
packages = ["trimage", packages = ["trimage",
"trimage.hurry", "trimage.filesize",
"trimage.hurry.filesize",
"trimage.ThreadPool",], "trimage.ThreadPool",],
package_data = {"trimage" : ["pixmaps/*.*"] }, package_data = {"trimage" : ["pixmaps/*.*"] },
data_files=[('share/icons/hicolor/scalable/apps', ['desktop/trimage.svg']), data_files=[('share/icons/hicolor/scalable/apps', ['desktop/trimage.svg']),
@ -20,4 +25,16 @@ setup(name = "trimage",
scripts = ["trimage"], scripts = ["trimage"],
long_description = """Trimage is a cross-platform GUI and command-line interface to optimize image files via optipng, advpng and jpegoptim, depending on the filetype (currently, PNG and JPG files are supported). It was inspired by imageoptim. All image files are losslessy compressed on the highest available compression levels. Trimage gives you various input functions to fit your own workflow: A regular file dialog, dragging and dropping and various command line options.""", long_description = """Trimage is a cross-platform GUI and command-line interface to optimize image files via optipng, advpng and jpegoptim, depending on the filetype (currently, PNG and JPG files are supported). It was inspired by imageoptim. All image files are losslessy compressed on the highest available compression levels. Trimage gives you various input functions to fit your own workflow: A regular file dialog, dragging and dropping and various command line options.""",
requires = ["PyQt4 (>=4.4)"], requires = ["PyQt4 (>=4.4)"],
#for py2exe
windows=[r'src\trimage\trimage.py'],
zipfile=None,
options={"py2exe":{
"optimize":2,
"compressed":1,
"bundle_files":1,
"includes":["sip",],
"excludes":['email'],
},
},
) )

View file

@ -0,0 +1 @@
http://pypi.python.org/pypi/hurry.filesize

View file

@ -0,0 +1,2 @@
from filesize import size
from filesize import traditional, alternative, verbose, iec, si

View file

@ -1,7 +0,0 @@
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

View file

@ -1,47 +0,0 @@
hurry.filesize
==============
hurry.filesize a simple Python library that can take a number of bytes and
returns a human-readable string with the size in it, in kilobytes (K),
megabytes (M), etc.
The default system it uses is "traditional", where multipliers of 1024
increase the unit size::
>>> from hurry.filesize import size
>>> size(1024)
'1K'
An alternative, slightly more verbose system::
>>> from hurry.filesize import alternative
>>> size(1, system=alternative)
'1 byte'
>>> size(10, system=alternative)
'10 bytes'
>>> size(1024, system=alternative)
'1 KB'
A verbose system::
>>> from hurry.filesize import verbose
>>> size(10, system=verbose)
'10 bytes'
>>> size(1024, system=verbose)
'1 kilobyte'
>>> size(2000, system=verbose)
'1 kilobyte'
>>> size(3000, system=verbose)
'2 kilobytes'
>>> size(1024 * 1024, system=verbose)
'1 megabyte'
>>> size(1024 * 1024 * 3, system=verbose)
'3 megabytes'
You can also use the SI system, where multipliers of 1000 increase the unit
size::
>>> from hurry.filesize import si
>>> size(1000, system=si)
'1K'

View file

@ -1,4 +0,0 @@
from hurry.filesize.filesize import size
from hurry.filesize.filesize import traditional, alternative, verbose, iec, si

View file

@ -1,7 +0,0 @@
import unittest, doctest
def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt'),
doctest.DocTestSuite('hurry.filesize.filesize'),
))

14
src/trimage/trimage.py Executable file → Normal file
View file

@ -9,7 +9,7 @@ from optparse import OptionParser
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from hurry.filesize import * from filesize import *
from imghdr import what as determinetype from imghdr import what as determinetype
from Queue import Queue from Queue import Queue
@ -210,18 +210,19 @@ class StartQT4(QMainWindow):
def checkapps(self): def checkapps(self):
"""Check if the required command line apps exist.""" """Check if the required command line apps exist."""
exe=".exe" if (sys.platform=="win32") else ""
status = False status = False
retcode = self.safe_call("jpegoptim --version") retcode = self.safe_call("jpegoptim"+exe+" --version")
if retcode != 0: if retcode != 0:
status = True status = True
sys.stderr.write("[error] please install jpegoptim") sys.stderr.write("[error] please install jpegoptim")
retcode = self.safe_call("optipng -v") retcode = self.safe_call("optipng"+exe+" -v")
if retcode != 0: if retcode != 0:
status = True status = True
sys.stderr.write("[error] please install optipng") sys.stderr.write("[error] please install optipng")
retcode = self.safe_call("advpng --version") retcode = self.safe_call("advpng"+exe+" --version")
if retcode != 0: if retcode != 0:
status = True status = True
sys.stderr.write("[error] please install advancecomp") sys.stderr.write("[error] please install advancecomp")
@ -360,9 +361,10 @@ class Image:
file)" file)"
self.reset() self.reset()
self.compressing=True self.compressing=True
exe=".exe" if (sys.platform=="win32") else ""
runString = { runString = {
"jpeg": u"jpegoptim -f --strip-all '%(file)s'", "jpeg": u"jpegoptim"+exe+" -f --strip-all '%(file)s'",
"png": u"optipng -force -o7 '%(file)s'&&advpng -z4 '%(file)s'"} "png" : u"optipng"+exe+" -force -o7 '%(file)s'&&advpng"+exe+" -z4 '%(file)s'"}
try: try:
retcode = call(runString[self.filetype] % {"file": self.fullpath}, retcode = call(runString[self.filetype] % {"file": self.fullpath},
shell=True, stdout=PIPE) shell=True, stdout=PIPE)