From f5ff57ff48baa0f746bf98476d965fb608a63316 Mon Sep 17 00:00:00 2001 From: Huluti Date: Thu, 7 Mar 2019 15:59:05 +0100 Subject: [PATCH 1/4] Just one return line fix --- trimage/trimage.py | 1 - 1 file changed, 1 deletion(-) diff --git a/trimage/trimage.py b/trimage/trimage.py index a32a1d5..2679924 100644 --- a/trimage/trimage.py +++ b/trimage/trimage.py @@ -4,7 +4,6 @@ import time import sys from os import listdir, path, remove, access, W_OK from shutil import copy - from optparse import OptionParser from multiprocessing import cpu_count from queue import Queue From d6118b520b2f9fd3ba23b33015cd23b6474064ed Mon Sep 17 00:00:00 2001 From: Huluti Date: Thu, 7 Mar 2019 16:09:21 +0100 Subject: [PATCH 2/4] Remove Windows options from setup.py --- setup.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index abb3796..cdf0490 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,8 @@ #!/usr/bin/env python3 -import sys -win=(sys.platform == "win32") -if win: - import py2exe - sys.path.append("trimage") - from distutils.core import setup + setup(name = "trimage", version = "1.0.5", description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files", @@ -23,17 +18,5 @@ setup(name = "trimage", ('share/man/man1', ['doc/trimage.1'])], scripts = ["bin/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.""", - requires = ["PyQt5"], - - #for py2exe - windows=[r'trimage\trimage.py'], - zipfile=None, - options={"py2exe":{ - "optimize":2, - "compressed":1, - "bundle_files":1, - "includes":["sip",], - "excludes":['email'], - }, - }, + requires = ["PyQt5"] ) From a3f417c43eaf97b6e914bebd5162e86838609bcc Mon Sep 17 00:00:00 2001 From: Huluti Date: Thu, 7 Mar 2019 16:10:19 +0100 Subject: [PATCH 3/4] setup.py: add a missing dependency in the long description --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cdf0490..dc8cfe3 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,6 @@ setup(name = "trimage", ('share/applications', ['desktop/trimage.desktop']), ('share/man/man1', ['doc/trimage.1'])], scripts = ["bin/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 advpng, jpegoptim, optipng and pngcrush, 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 = ["PyQt5"] ) From 5f5757f57576c71f0cdfad28ad7fe8415daa6c6b Mon Sep 17 00:00:00 2001 From: Huluti Date: Thu, 7 Mar 2019 16:45:55 +0100 Subject: [PATCH 4/4] Fix #28 --- trimage/trimage.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/trimage/trimage.py b/trimage/trimage.py index 2679924..a0f7092 100644 --- a/trimage/trimage.py +++ b/trimage/trimage.py @@ -4,6 +4,7 @@ import time import sys from os import listdir, path, remove, access, W_OK from shutil import copy + from optparse import OptionParser from multiprocessing import cpu_count from queue import Queue @@ -304,7 +305,7 @@ class ImageRow: """Build the information visible in the table image row.""" self.image = image d = { - 'shortname': lambda i: self.statusStr() % i.shortname, + 'filename_w_ext': lambda i: self.statusStr() % i.filename_w_ext, 'oldfilesizestr': lambda i: human_readable_size(i.oldfilesize) if i.compressed else "", 'newfilesizestr': lambda i: human_readable_size(i.newfilesize) @@ -315,7 +316,7 @@ class ImageRow: 'icon': lambda i: i.icon if i.compressed else waitingIcon, 'fullpath': lambda i: i.fullpath, #only used by cli } - names = ['shortname', 'oldfilesizestr', 'newfilesizestr', + names = ['filename_w_ext', 'oldfilesizestr', 'newfilesizestr', 'ratiostr', 'icon'] for i, n in enumerate(names): d[i] = d[n] @@ -345,13 +346,14 @@ class Image: self.valid = False self.reset() self.fullpath = fullpath + self.filename_w_ext = path.basename(self.fullpath) + self.filename, self.filetype = path.splitext(self.filename_w_ext) if path.isfile(self.fullpath) and access(self.fullpath, W_OK): - self.filetype = path.splitext(self.fullpath)[1][1:].lower() + self.filetype = self.filetype[1:].lower() if self.filetype == "jpg": self.filetype = "jpeg" if self.filetype in ["jpeg", "png"]: oldfile = QFileInfo(self.fullpath) - self.shortname = oldfile.fileName() self.oldfilesize = oldfile.size() self.icon = QIcon(self.fullpath) self.valid = True @@ -375,7 +377,8 @@ class Image: "png": "optipng" + exe + " -force -o7 '%(file)s'&&advpng" + exe + " -z4 '%(file)s' && pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time '%(file)s' '%(file)s.bak' && mv '%(file)s.bak' '%(file)s'" } # create a backup file - copy(self.fullpath, self.fullpath + '~') + backupfullpath = '/tmp/' + self.filename_w_ext + copy(self.fullpath, backupfullpath) try: retcode = call(runString[self.filetype] % {"file": self.fullpath}, shell=True, stdout=PIPE) @@ -387,11 +390,11 @@ class Image: # checks the new file and copy the backup if self.newfilesize >= self.oldfilesize: - copy(self.fullpath + '~', self.fullpath) + copy(backupfullpath, self.fullpath) self.newfilesize = self.oldfilesize # removes the backup file - remove(self.fullpath + '~') + remove(backupfullpath) else: self.failed = True self.compressing = False