![]() |
#16 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Quote:
|
|
![]() |
![]() |
![]() |
#17 | |||
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
Code:
elif (filename.lower().endswith('.jpg') or filename.lower().endswith('.jpeg')) : # get correct arguments if iswindows: exe_path = os.path.join(SCRIPT_DIR,'win', 'jpegtran.exe') elif isosx: exe_path = os.path.join(SCRIPT_DIR,'osx','jpegtran') else: exe_path = 'jpegtran' args = [exe_path] args.append("-optimize") args.append("-progressive") args.append("-copy") args.append("none") args.append("-outfile") args.append(filename) args.append(filename) In fact, you can use libjpeg's version 9 executable with either syntax. Which is I guess why Toxaris used the old syntax. Quote:
Because I am pretty sure both are untrue. Also, on my machine, using the libjpeg version 9 syntax with libjpeg-turbo (or mozjpeg) does exactly what I expect -- it immediately returns a failure: Code:
jpegtran: only one input file usage... Quote:
mozjpeg and libjpeg-turbo are both equally NOT libjpeg. .... I suppose the real question is, why are you using subprocess.call(list(args), shell=True) subprocess.call(args) works fine without any other changes. (Don't use a shell. Minor nit: don't convert a list into a list) |
|||
![]() |
![]() |
![]() |
#18 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Updated version which includes a preference file to chose another version of jpegtran and the usage of wine.
|
![]() |
![]() |
![]() |
#19 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,731
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
I then executed the same command line that the plugin uses: Code:
jpegtran -optimize -progressive -copy none -outfile /tmp/tmp2RD8h1/image.JPG /tmp/tmp2RD8h1/image.JPG Did you install the ImageOptimizer plugin on your machine and does it work with libjpeg-turbo? |
|
![]() |
![]() |
![]() |
#20 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Again, it works fine once I fixed the plugin.
The problem is that subprocess.Popen expects either:
Passing a list to the shell means it tries to execute "jpegtran" and pass the additional arguments as arguments to the shell itself, not jpegtran. And yes, when you run Code:
jpegtran Why on earth does it specifically need a shell? The plugin isn't using shell builtins, pipes, variable expansion, tilde expansion, or shell globbing. Plus it is now vulnerable to shell injection (not that this is the easiest way to mess with someone's computer and make them run malicious commands, but still, it's the theory of the thing...) Last edited by eschwartz; 02-03-2016 at 11:01 AM. |
![]() |
![]() |
![]() |
#21 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,731
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
|
![]() |
![]() |
![]() |
#22 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Code:
def OptiWrapper(*args): # execute optimizer program # list(args) is a no-op, since it is already a list... ret = call(list(args), shell=True) return ret args is a list, and shell=True These conditions cannot both be true. Either use: Code:
def OptiWrapper(*args): # execute optimizer program ret = call(args) return ret Code:
def OptiWrapper(*args): # execute optimizer program # this actually requires a lot more checking of proper shell # quoting/escaping than I display here ret = call(' '.join(args), shell=True) return ret See the python docs: https://docs.python.org/3/library/su...en-constructor Quote:
EDIT: useless nit #2 Why define a special function as a wrapper for subprocess.call, when it is used only once and adds no particular value other than turning on the shell and doing list --> list conversion? It was staring me in the face while looking at the source of the hanging... Last edited by eschwartz; 02-03-2016 at 11:22 AM. |
|
![]() |
![]() |
![]() |
#23 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
The shell=True is indeed a mistake which was entered during the testing process. I apparently forgot to remove it. On Windows it does not cause an issue...
A small update where this is corrected. The reason why I used a sub for the wrapper is simple. It is easier for updates if this is already split. I agree that it seems silly for one command only, but that is the current situation. |
![]() |
![]() |