o
    8c                     @   sl   d dl Z d dlZd dlZddlmZ ddlmZ dZi Zdd Zdd	 Z	d
d Z
dd Zeddd ZdS )    N   )util)compatREVISION_SCRIPT_FILENAMEc                    s    fdd}|S )zA function decorator that will register that function as a write hook.

    See the documentation linked below for an example.

    .. versionadded:: 1.2.0

    .. seealso::

        :ref:`post_write_hooks_custom`


    c                    s   | t  < d S )N)	_registry)fnname P/var/www/html/gps/gps/lib/python3.10/site-packages/alembic/script/write_hooks.pydecorate   s   zregister.<locals>.decorater
   )r	   r   r
   r   r   register   s   r   c              
   C   sV   zt |  }W n ty% } ztjtd|  |d W Y d}~dS d}~ww |||S )a7  Invokes the formatter registered for the given name.

    :param name: The name of a formatter in the registry
    :param revision: A :class:`.MigrationRevision` instance
    :param options: A dict containing kwargs passed to the
        specified formatter.
    :raises: :class:`alembic.util.CommandError`
    z&No formatter with name '%s' registeredfrom_N)r   KeyErrorr   raise_r   CommandError)r	   revisionoptionshookker
   r
   r   _invoke"   s   	
r   c                    s   ddl m} | dd}|D ]Gsq fdd D }|d< z|d }W n  tyJ } ztjtd	f |d
 W Y d}~qd}~ww tj	d t
|| |dd qdS )z&Invoke hooks for a generated revision.   )_split_on_space_commahooks c                    s4   i | ]}| d  r|td d  | qS ).r   N)
startswithlen).0keyhook_configr	   r
   r   
<dictcomp>@   s    z_run_hooks.<locals>.<dictcomp>
_hook_nametypez.Key %s.type is required for post write hook %rr   NzRunning post write hook "%s"T)newline)baser   splitgetr   r   r   r   r   statusr   )pathr"   r   namesoptstype_r   r
   r!   r   
_run_hooks6   s>   	r/   c                    s:   t | vr
t d |  } tj| tjd} fdd|D }|S )zParse options from a string into a list.

    Also substitutes the revision script token with the actual filename of
    the revision script.

    If the revision script token doesn't occur in the options string, it is
    automatically prepended.
     )posixc                    s   g | ]}| t qS r
   )replaceREVISION_SCRIPT_TOKEN)r   optionr+   r
   r   
<listcomp>i   s    
z*_parse_cmdline_options.<locals>.<listcomp>)r3   shlexr(   r   is_posix)cmdline_options_strr+   cmdline_options_listr
   r5   r   _parse_cmdline_options[   s   	
r;   console_scriptsc           
   
   C   s   dd l }z|d }W n$ ty. } ztjtd|d |d f |d W Y d }~nd }~ww |d|}t|}|dd }|dd	}t	|| }	t
jtjd
d|jd|jf|j f g|	 |d d S )Nr   
entrypointz4Key %s.entrypoint is required for post write hook %rr$   r   r<   cwdr   r   z-czimport %s; %s()r   )r>   )pkg_resourcesr   r   r   r   r   iter_entry_pointsnextr)   r;   
subprocessrunsys
executablemodule_namejoinattrs)
r+   r   r?   entrypoint_namer   iter_implr>   r9   r:   r
   r
   r   r<   p   s<   

)r7   rB   rD   r   r   r   r3   r   r   r   r/   r;   r<   r
   r
   r
   r   <module>   s    %