�
�"Kb� � � � d Z ddlZddlZddlZddlZddlZd� Z G d� de� � Ze dk r( ej
eej dd� � � � � dS dS )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 �L � t � � }|� | � � d S )N)� FlockTool�Dispatch)�args�executors �0/usr/lib/python3/dist-packages/gyp/flock_tool.py�mainr s% � �
�[�[�(�
���D������ c �$ � e Zd ZdZd� Zd� Zd� ZdS )r z(This class emulates the 'flock' command.c � � t |� � dk rt d� � �d| � |d � � z } t | |� � |dd� � dS )z(Dispatches a string command to a method.� zNot enough argumentszExec%sr N)�len� Exception�_CommandifyName�getattr)�selfr �methods r r zFlockTool.Dispatch sa � �
�4�y�y�1�}�}��,�-�-�-�
��,�,�T�!�W�5�5�
5�F��G�D�&���4����8�$�$�$�$r
c �R � |� � � � dd� � S )z<Transforms a tool name like copy-info-plist to CopyInfoPlist�-� )�title�replace)r �name_strings r r zFlockTool._CommandifyName s$ � ������&�&�s�B�/�/�/r
c
� � t j |t j t j z t j z d� � }t
j � d� � r&t j dt j dddddd� � }n%t j dt j dddddd� � }t j
|t j |� � t j |� � 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�ops r � ExecFlockzFlockTool.ExecFlock# s� � �
���2�;�r�{�2�2�:�=�u� E� E�B�
�|���u�%�%� C� �;�y�%�-��A�q�!�Q��B�B�b�b��;�y�%�-��A�q�!�Q��B�B�b� �K��E�M�2�&�&�&��?�8�$�$�$r
N)�__name__�
__module__�__qualname__�__doc__r r r1 � r
r r r sG � � � � � �0�0�%� %� %�0� 0� 0�%� %� %� %� %r
r �__main__r
)r5 r( r r& |