o
    p.aÕ  ã                   @   sl   d Z ddlZddlZddlZddlZddlZdd„ ZG dd„ deƒZe	dkr4e 
eejdd… ƒ¡ dS dS )	z…These functions are executed via gyp-flock-tool when using the Makefile
generator.  Used on systems that don't have a built-in flock.é    Nc                 C   s   t ƒ }| | ¡ d S )N)Ú	FlockToolÚDispatch)ÚargsÚexecutor© r   ú0/usr/lib/python3/dist-packages/gyp/flock_tool.pyÚmain   s   r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   z(This class emulates the 'flock' command.c                 C   s@   t |ƒdk r
tdƒ‚d|  |d ¡ }t| |ƒ|dd… Ž  dS )z(Dispatches a string command to a method.é   zNot enough argumentszExec%sr   N)ÚlenÚ	ExceptionÚ_CommandifyNameÚgetattr)Úselfr   Úmethodr   r   r   r      s   zFlockTool.Dispatchc                 C   s   |  ¡  dd¡S )z<Transforms a tool name like copy-info-plist to CopyInfoPlistú-Ú )ÚtitleÚreplace)r   Úname_stringr   r   r   r      s   zFlockTool._CommandifyNamec              
   G   sx   t  |t jt jB t jB d¡}tj d¡r"t 	dt
jdddddd¡}nt 	dt
jdddddd¡}t
 
|t
j|¡ t |¡S )z5Emulates the most basic behavior of Linux's flock(1).i¶  ÚaixÚhhIllqqr   Úhhllhhl)ÚosÚopenÚO_WRONLYÚO_NOCTTYÚO_CREATÚsysÚplatformÚ
startswithÚstructÚpackÚfcntlÚF_WRLCKÚF_SETLKÚ
subprocessÚcall)r   ÚlockfileÚcmd_listÚfdÚopr   r   r   Ú	ExecFlock#   s   
zFlockTool.ExecFlockN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r+   r   r   r   r   r      s
    r   Ú__main__r	   )r/   r"   r   r    r%   r   r   Úobjectr   r,   ÚexitÚargvr   r   r   r   Ú<module>   s    ÿ