Replace ImageShow.which() with stdlib

Co-Authored-By: Jon Dufresne <jon.dufresne@gmail.com>
This commit is contained in:
Hugo 2019-10-12 21:40:11 +03:00
parent 23fa3c6979
commit 3dac6e2c62

View File

@ -12,6 +12,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
import os import os
import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
@ -145,16 +146,6 @@ else:
# unixoids # unixoids
def which(executable):
path = os.environ.get("PATH")
if not path:
return None
for dirname in path.split(os.pathsep):
filename = os.path.join(dirname, executable)
if os.path.isfile(filename) and os.access(filename, os.X_OK):
return filename
return None
class UnixViewer(Viewer): class UnixViewer(Viewer):
format = "PNG" format = "PNG"
options = {"compress_level": 1} options = {"compress_level": 1}
@ -183,7 +174,7 @@ else:
command = executable = "display" command = executable = "display"
return command, executable return command, executable
if which("display"): if shutil.which("display"):
register(DisplayViewer) register(DisplayViewer)
class EogViewer(UnixViewer): class EogViewer(UnixViewer):
@ -191,7 +182,7 @@ else:
command = executable = "eog" command = executable = "eog"
return command, executable return command, executable
if which("eog"): if shutil.which("eog"):
register(EogViewer) register(EogViewer)
class XVViewer(UnixViewer): class XVViewer(UnixViewer):
@ -203,7 +194,7 @@ else:
command += " -name %s" % quote(title) command += " -name %s" % quote(title)
return command, executable return command, executable
if which("xv"): if shutil.which("xv"):
register(XVViewer) register(XVViewer)
if __name__ == "__main__": if __name__ == "__main__":