diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 91487d7..c384c02 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import os import shutil -from distutils.spawn import find_executable from . import util # Supported archive commands @@ -195,7 +194,7 @@ def find_archive_program (format, command): raise util.PatoolError("%s archive format `%s' is not supported" % (command, format)) # return the first existing program for program in programs: - exe = find_executable(program) + exe = util.find_program(program) if exe: if program == '7z' and format == 'rar' and not util.p7zip_supports_rar(): continue @@ -209,7 +208,7 @@ def find_encoding_program (program, encoding): no encoding program could be found""" if program in ('tar', 'star'): for enc_program in EncodingPrograms[encoding]: - found = find_executable(enc_program) + found = util.find_program(enc_program) if found: return found return None @@ -228,7 +227,7 @@ def list_formats (): print " %8s: %s" % (command, program), basename = os.path.basename(program) if format == 'tar': - encs = [x for x in ArchiveEncodings if find_executable(x)] + encs = [x for x in ArchiveEncodings if util.find_program(x)] if encs: print "(supported encodings: %s)" % ", ".join(encs), elif format == '7z': diff --git a/patoolib/util.py b/patoolib/util.py index a5176e7..f3894f7 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -20,6 +20,7 @@ import subprocess import mimetypes import tempfile import traceback +from distutils.spawn import find_executable mimedb = mimetypes.MimeTypes(strict=False) # add missing encodings and mimetypes @@ -103,3 +104,10 @@ def log_internal_error (out=sys.stderr): def p7zip_supports_rar (): """Determine if the RAR codec is installed for 7z program.""" return os.path.exists('/usr/lib/p7zip/Codecs/Rar29.so') + + +def find_program (program): + """Look for program in environment PATH variable.""" + # XXX memoize result of this function + path = os.environ['PATH'] + return find_executable(program, path=path) diff --git a/tests/__init__.py b/tests/__init__.py index 810e1fa..bb5f4b8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -18,7 +18,6 @@ import os import shutil import nose import patoolib -from distutils.spawn import find_executable basedir = os.path.dirname(__file__) datadir = os.path.join(basedir, 'data') @@ -86,7 +85,7 @@ def needs_program (program): """Decorator skipping test if given program is not available.""" def check_prog (f): def newfunc (*args, **kwargs): - if not find_executable(program): + if not patoolib.util.find_program(program): raise nose.SkipTest("program `%s' not available" % program) return f(*args, **kwargs) newfunc.func_name = f.func_name @@ -98,7 +97,7 @@ def needs_codec (program, codec): """Decorator skipping test if given program codec is not available.""" def check_prog (f): def newfunc (*args, **kwargs): - if not find_executable(program): + if not patoolib.util.find_program(program): raise nose.SkipTest("program `%s' not available" % program) if not find_codec(program, codec): raise nose.SkipTest("codec `%s' for program `%s' not available" % (codec, program))