a ~_@sdZddlZddlZddlmZGdddeZGdddeZGdd d eZGd d d eZ Gd d d eZ GdddeZ dS)zAccess to hooks.N) HookErrorc@seZdZdZddZdS)HookzGeneric hook object.cGst|jdS)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 N)NotImplementedErrorexecute)selfargsr//usr/lib/python3/dist-packages/dulwich/hooks.pyr"s z Hook.executeN)__name__ __module__ __qualname____doc__rrrrr rsrc@s"eZdZdZdddZddZdS) ShellHookzHook by executable file Implements standard githooks(5) [0]: [0] http://www.kernel.org/pub/software/scm/git/docs/githooks.html NcCs(||_||_||_||_||_||_dS)aSetup 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)namefilepathnumparampre_exec_callbackpost_exec_callbackcwd)rrpathrrrrrrr __init__7s zShellHook.__init__cGst||jkr*td|j|jt||f|jdur>|j|}zttj|jgt||j d}|dkr|j dur|j dg|Rtd|j|f|j dur|j dg|RWSWn.t y|j dur|j dg|RYn0dS)z Execute the hook with given argszeHook %s executed with wrong number of args. Expected %d. Saw %d. args: %sNrrz&Hook %s exited with non-zero status %d) lenrrrr subprocessZcallrlistrrOSError)rrZretrrr rSs&      zShellHook.execute)NNNr r r r rrrrrr r/s  rc@seZdZdZddZdS)PreCommitShellHookzpre-commit shell hookcCs(tj|dd}tj|d|d|ddS)Nhooksz pre-commitrrosrjoinrrr controldirrrrr roszPreCommitShellHook.__init__Nr r r r rrrrr rlsrc@seZdZdZddZdS)PostCommitShellHookzpost-commit shell hookcCs(tj|dd}tj|d|d|ddS)Nrz post-commitrrr r#rrr rxszPostCommitShellHook.__init__Nr%rrrr r&usr&c@seZdZdZddZdS)CommitMsgShellHookzqcommit-msg shell hook Args: args[0]: commit message Returns: new commit message or None c Cs:tj|dd}dd}dd}t|d|d|||dS)Nrz commit-msgcWsTddl}|\}}t|d}||dWdn1sD0Y|fS)Nrwb)tempfileZmkstempr!fdopenwrite)rr)fdrfrrr prepare_msgs  ,z0CommitMsgShellHook.__init__..prepare_msgcWs^|rLt|dd}|}Wdn1s00Yt|d|St|ddS)Nrrb)openreadr!unlink)Zsuccessrr-Znew_msgrrr clean_msgs &z.CommitMsgShellHook.__init__..clean_msgrr )rr$rr.r3rrr rs   zCommitMsgShellHook.__init__Nr%rrrr r'~sr'c@s eZdZdZddZddZdS)PostReceiveShellHookzpost-receive shell hookcCs*||_tj|dd}t|d|ddS)Nrz post-receiver)r$r!rr"rrr#rrr rszPostReceiveShellHook.__init__c Cstj|jsdSztj}|j|d<tj|jtj tj tj |d}d dd|D}| |\}}|j dkst|rd}||j ||f}t ||WSty} zt t| WYd} ~ n d} ~ 00dS)NZGIT_DIR)stdinstdoutstderrenv cSsg|]}d|qS) )r").0refrrr z0PostReceiveShellHook.execute..rz0post-receive exit code: %d stdout: %s stderr: %s)r!rexistsrenvironcopyr$rPopenPIPEr"Z communicate returncoderrrepr) rZ client_refsr8pZin_dataZout_dataZerr_dataZerr_fmterr_msgerrrrr rs*   zPostReceiveShellHook.executeNrrrrr r4sr4) r r!rZdulwich.errorsrobjectrrrr&r'r4rrrr s =  !