Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 import os
00011 
00012 
00013 
00014 
00015 
00016 
00017 def which(program):
00018     '''
00019       Wrapper around the command line 'which' program.
00020 
00021       @return path to the program or None if it doesnt exist.
00022       @rtype str or None
00023     '''
00024     def is_exe(fpath):
00025         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
00026 
00027     fpath, unused_fname = os.path.split(program)
00028     if fpath:
00029         if is_exe(program):
00030             return program
00031     else:
00032         for path in os.environ["PATH"].split(os.pathsep):
00033             path = path.strip('"')
00034             exe_file = os.path.join(path, program)
00035             if is_exe(exe_file):
00036                 return exe_file
00037 
00038     return None