Util: Improve Windows support in find_command()

This commit is contained in:
Thomas Perl 2011-11-05 21:22:21 +01:00
parent c3456cd327
commit a2c2bafa7b
1 changed files with 15 additions and 6 deletions

View File

@ -915,22 +915,31 @@ def get_real_url(url):
return url
def find_command( command):
def find_command(command):
"""
Searches the system's PATH for a specific command that is
executable by the user. Returns the first occurence of an
executable binary in the PATH, or None if the command is
executable binary in the PATH, or None if the command is
not available.
On Windows, this also looks for "<command>.bat" and
"<command>.exe" files if "<command>" itself doesn't exist.
"""
if 'PATH' not in os.environ:
return None
for path in os.environ['PATH'].split( os.pathsep):
command_file = os.path.join( path, command)
if os.path.isfile( command_file) and os.access( command_file, os.X_OK):
for path in os.environ['PATH'].split(os.pathsep):
command_file = os.path.join(path, command)
if gpodder.win32 and not os.path.exists(command_file):
for extension in ('.bat', '.exe'):
cmd = command_file + extension
if os.path.isfile(cmd):
command_file = cmd
break
if os.path.isfile(command_file) and os.access(command_file, os.X_OK):
return command_file
return None
idle_add_handler = None