File: //lib/python3.6/site-packages/certbot/_internal/__pycache__/hooks.cpython-36.pyc
3
گa�! � @ s� U d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z dd l
mZ dd
l
mZ ddl
m
Z
ddlmZ ddlm Z eje�Zejdd
�dd�Zeee d�dd�Zeedd�dd�Zejdd
�dd�Ze� Zee edd�dd�Zejdd
�dd�Zg Z ee edd�dd�Z!dd�d d!�Z"ejee edd"�d#d$�Z#ejee edd"�d%d&�Z$eee ee%dd'�d(d)�Z&eeed*�d+d,�Z'eee d-�d.d/�Z(dS )0z;Facilities for implementing hooks that call shell commands.� N)�List)�Optional)�Set)�
configuration)�errors)�util)�
filesystem)�misc)�os)�ops)�config�returnc C s4 t | jd� t | jd� t | jd� t | jd� dS )z#Check hook commands are executable.ZpreZpostZdeploy�renewN)�
validate_hook�pre_hook� post_hook�deploy_hook�
renew_hook)r � r �/usr/lib/python3.6/hooks.py�validate_hooks s r )� shell_cmdr
c C s. t j| �s"tj| � t j| �s"dS tjj| �S )z�Extract the program run by a shell command.
:param str shell_cmd: command to be executed
:returns: basename of command or None if the command isn't found
:rtype: str or None
N)r Z
exe_exists� plug_utilZpath_surgeryr
�path�basename)r r r r �_prog s
r )r � hook_namer
c C s\ | rX| j dd�d }t|�sXtjd }tjj|�r@dj||�}ndj|||�}tj|��dS )z�Check that a command provided as a hook is plausibly executable.
:raises .errors.HookCommandNotFound: if the command is not found
N� r �PATHz3{1}-hook command {0} exists, but is not executable.z>Unable to find {2}-hook command {0} in the PATH.
(PATH is {1})) �splitr r
�environr �exists�formatr ZHookCommandNotFound)r r �cmdr �msgr r r r - s
r c C sB | j dkr,| jr,xt| j�D ]}t|� qW | j}|r>t|� dS )a� Run pre-hooks if they exist and haven't already been run.
When Certbot is running with the renew subcommand, this function
runs any hooks found in the config.renewal_pre_hooks_dir (if they
have not already been run) followed by any pre-hook in the config.
If hooks in config.renewal_pre_hooks_dir are run and the pre-hook in
the config is a path to one of these scripts, it is not run twice.
:param configuration.NamespaceConfig config: Certbot settings
r N)�verb�directory_hooks�
list_hooksZrenewal_pre_hooks_dir�_run_pre_hook_if_necessaryr )r �hookr# r r r r ? s r )�commandr
c C s. | t krtjd| � ntd| � t j| � dS )z�Run the specified pre-hook if we haven't already.
If we've already run this exact command before, a message is logged
saying the pre-hook was skipped.
:param str command: pre-hook to be run
z*Pre-hook command already run, skipping: %szpre-hookN)�executed_pre_hooks�logger�info� _run_hook�add)r* r r r r( W s
r( c C sR | j }| jdkr@| jr2xt| j�D ]}t|� q"W |rNt|� n|rNtd|� dS )a� Run post-hooks if defined.
This function also registers any executables found in
config.renewal_post_hooks_dir to be run when Certbot is used with
the renew subcommand.
If the verb is renew, we delay executing any post-hooks until
:func:`run_saved_post_hooks` is called. In this case, this function
registers all hooks found in config.renewal_post_hooks_dir to be
called followed by any post-hook in the config. If the post-hook in
the config is a path to an executable in the post-hook directory, it
is not scheduled to be run twice.
:param configuration.NamespaceConfig config: Certbot settings
r z post-hookN)r r% r&