o
    Uh8                     @   s   d Z ddlZddlZddlmZ G dd dZG dd deZG d	d
 d
eZG dd deZG dd deZ	G dd deZ
dS )zAccess to hooks.    N   )	HookErrorc                   @   s   e Zd ZdZdd ZdS )HookzGeneric hook object.c                 G   s
   t | j)zExecute the hook with the given args.

        Args:
          args: argument list to hook
        Raises:
          HookError: hook execution failure
        Returns:
          a hook may return a useful value
        )NotImplementedErrorexecute)selfargs r	   a/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/hooks.pyr   !   s   

zHook.executeN)__name__
__module____qualname____doc__r   r	   r	   r	   r
   r      s    r   c                   @   s,   e Zd ZdZ			d	d	ddZdd ZdS )
	ShellHookzHook by executable file.

    Implements standard githooks(5) [0]:

    [0] http://www.kernel.org/pub/software/scm/git/docs/githooks.html
    Nreturnc                 C   s(   || _ || _|| _|| _|| _|| _dS )a  Setup shell hook definition.

        Args:
          name: name of hook for error messages
          path: absolute path to executable file
          numparam: number of requirements parameters
          pre_exec_callback: closure for setup before execution
            Defaults to None. Takes in the variable argument list from the
            execute functions and returns a modified argument list for the
            shell hook.
          post_exec_callback: closure for cleanup after execution
            Defaults to None. Takes in a boolean for hook success and the
            modified argument list and returns the final hook return value
            if applicable
          cwd: working directory to switch to when executing the hook
        N)namefilepathnumparampre_exec_callbackpost_exec_callbackcwd)r   r   pathr   r   r   r   r	   r	   r
   __init__6   s   
zShellHook.__init__c              	   G   s  t || jkrtd| j d| j dt | d| | jdur%| j| }zCtjtj	| j
| jgt|| jd}|dkrW| jdurL| jdg|R   td| j d| | jdurf| jd	g|R  W S W dS  ty   | jdur| jdg|R   Y dS Y dS w )
z!Execute the hook with given args.zHook z. executed with wrong number of args. Expected z. Saw z. args: Nr   r   z exited with non-zero status r   )lenr   r   r   r   
subprocesscallosr   relpathr   r   listr   OSError)r   r   retr	   r	   r
   r   X   s,   "




zShellHook.execute)NNNr   Nr   r   r   r   r   r   r	   r	   r	   r
   r   .   s    
"r   c                   @      e Zd ZdZdddZdS )PreCommitShellHookzpre-commit shell hook.r   Nc                 C   s(   t j|dd}tj| d|d|d d S )Nhooksz
pre-commitr   r   r   r   joinr   r   )r   r   
controldirr   r	   r	   r
   r   t      zPreCommitShellHook.__init__r"   r   r   r   r   r   r	   r	   r	   r
   r%   q       r%   c                   @   r$   )PostCommitShellHookzpost-commit shell hook.r   Nc                 C   s(   t j|dd}tj| d|d|d d S )Nr&   zpost-commitr   r   r'   r   r)   r   r	   r	   r
   r   }   r*   zPostCommitShellHook.__init__r"   r+   r	   r	   r	   r
   r-   z   r,   r-   c                   @   r$   )CommitMsgShellHookzcommit-msg shell hook.r   Nc              	   C   s:   t j|dd}dd }dd }t| d|d||| d S )Nr&   z
commit-msgc                  W   sX   dd l }| \}}t|d}|| d  W d    |fS 1 s$w   Y  |fS )Nr   wb)tempfilemkstempr   fdopenwrite)r   r1   fdr   fr	   r	   r
   prepare_msg   s   
z0CommitMsgShellHook.__init__.<locals>.prepare_msgc                 W   s^   | r&t |d d}| }W d    n1 sw   Y  t|d  |S t|d  d S )Nr   rb)openreadr   unlink)successr   r6   new_msgr	   r	   r
   	clean_msg   s   
z.CommitMsgShellHook.__init__.<locals>.clean_msgr   r'   )r   r)   r   r7   r>   r	   r	   r
   r      s   
zCommitMsgShellHook.__init__r"   r+   r	   r	   r	   r
   r/      r,   r/   c                   @   s"   e Zd ZdZdddZdd ZdS )	PostReceiveShellHookzpost-receive shell hook.r   Nc                 C   s,   || _ tj|dd}tj| d|dd d S )Nr&   zpost-receiver   )r   r   )r)   r   r   r(   r   r   r.   r	   r	   r
   r      s   zPostReceiveShellHook.__init__c           
   
   C   s   t j| js	d S zEt j }| j|d< tj| jtj	tj	tj	|d}d
dd |D }||\}}|jdks:|rLd}||j||f }t|dd	|W S  tya }	 ztt|	|	d }	~	ww )
NGIT_DIR)stdinstdoutstderrenv   
c                 S   s   g | ]}d  |qS )    )r(   ).0refr	   r	   r
   
<listcomp>   s    z0PostReceiveShellHook.execute.<locals>.<listcomp>r   s0   post-receive exit code: %d
stdout:
%s
stderr:
%szutf-8backslashreplace)r   r   existsr   environcopyr)   r   PopenPIPEr(   communicate
returncoder   decoder    repr)
r   client_refsrD   pin_dataout_dataerr_dataerr_fmterr_msgerrr	   r	   r
   r      s.   

	zPostReceiveShellHook.executer"   r#   r	   r	   r	   r
   r?      s    
r?   )r   r   r   errorsr   r   r   r%   r-   r/   r?   r	   r	   r	   r
   <module>   s   C		