3 .]N @ s d dl Z d dlZd dlZd dlZd dlZd dlZye W n ek rR ejZY nX ej d dkrje fZnee fZdd Z dddZdd Zdd d ZdS ) N c C sh t jj| }t jj|sdS t j|j}tjjdrZt j dkrZt |tjtjB tj B @ S t j|t jS )zChecks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. Fsunosr )ospathrealpathisfilestatst_modesysplatform startswithgetuidboolS_IXUSRS_IXGRPS_IXOTHaccessX_OK)r Zfpathmode r /usr/lib/python3.6/utils.pyis_executable_file s r c C sv t jj| dkrt| r| S |dkr*t j}|jd}|s>t j}|jt j}x&|D ]}t jj || }t|rP|S qPW dS )zThis takes a given filename; tries to find it in the environment path; then checks if it is executable. This returns the full path to the filename if found and executable. Otherwise this returns None. NPATH) r r dirnamer environgetdefpathsplitpathsepjoin)filenameenvpZpathlistr Zffr r r which0 s r$ c C s g }d}d}d}d}d}d}|}x| D ]} ||ks:||kr| dkrH|}q| dkrV|}q| d krd|}q| j r||krvq|j| d}|}q|| }|}q&||kr|| }|}q&||kr| dkr|}q|| }q&||kr&| d kr|}q&|| }q&W