o
    8c`L                     @   s   d dl mZ d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ G d	d
 d
eZG dd deZdddZedkrNe  dS dS )    )ArgumentParserN   )__version__)command)util)compat)SafeConfigParserc                   @   s   e Zd ZdZdddejde dfddZdZ		 dZ
	 dZ	 ejdd Zdd	 Zejd
d Zdd ZdddZdd Zdd Zdd ZdddZdddZdS )Configac  Represent an Alembic configuration.

    Within an ``env.py`` script, this is available
    via the :attr:`.EnvironmentContext.config` attribute,
    which in turn is available at ``alembic.context``::

        from alembic import context

        some_param = context.config.get_main_option("my option")

    When invoking Alembic programatically, a new
    :class:`.Config` can be created by passing
    the name of an .ini file to the constructor::

        from alembic.config import Config
        alembic_cfg = Config("/path/to/yourapp/alembic.ini")

    With a :class:`.Config` object, you can then
    run Alembic commands programmatically using the directives
    in :mod:`alembic.command`.

    The :class:`.Config` object can also be constructed without
    a filename.   Values can be set programmatically, and
    new sections will be created as needed::

        from alembic.config import Config
        alembic_cfg = Config()
        alembic_cfg.set_main_option("script_location", "myapp:migrations")
        alembic_cfg.set_main_option("sqlalchemy.url", "postgresql://foo/bar")
        alembic_cfg.set_section_option("mysection", "foo", "bar")

    .. warning::

       When using programmatic configuration, make sure the
       ``env.py`` file in use is compatible with the target configuration;
       including that the call to Python ``logging.fileConfig()`` is
       omitted if the programmatic configuration doesn't actually include
       logging directives.

    For passing non-string values to environments, such as connections and
    engines, use the :attr:`.Config.attributes` dictionary::

        with engine.begin() as connection:
            alembic_cfg.attributes['connection'] = connection
            command.upgrade(alembic_cfg, "head")

    :param file\_: name of the .ini file to open.
    :param ini_section: name of the main Alembic section within the
     .ini file
    :param output_buffer: optional file-like input buffer which
     will be passed to the :class:`.MigrationContext` - used to redirect
     the output of "offline generation" when using Alembic programmatically.
    :param stdout: buffer where the "print" output of commands will be sent.
     Defaults to ``sys.stdout``.

    :param config_args: A dictionary of keys and values that will be used
     for substitution in the alembic config file.  The dictionary as given
     is **copied** to a new one, stored locally as the attribute
     ``.config_args``. When the :attr:`.Config.file_config` attribute is
     first invoked, the replacement variable ``here`` will be added to this
     dictionary before the dictionary is passed to ``SafeConfigParser()``
     to parse the .ini file.

    :param attributes: optional dictionary of arbitrary Python keys/values,
     which will be populated into the :attr:`.Config.attributes` dictionary.

     .. seealso::

        :ref:`connection_sharing`

    Nalembicc                 C   s@   || _ || _|| _|| _|| _t|| _|r| j| dS dS )z Construct a new :class:`.Config`N)	config_file_nameconfig_ini_sectionoutput_bufferstdoutcmd_optsdictconfig_args
attributesupdate)selffile_ini_sectionr   r   r   r   r    r   D/var/www/html/gps/gps/lib/python3.10/site-packages/alembic/config.py__init__W   s   
zConfig.__init__c                 C   s   i S )a  A Python dictionary for storage of additional state.


        This is a utility dictionary which can include not just strings but
        engines, connections, schema objects, or anything else.
        Use this to pass objects into an env.py script, such as passing
        a :class:`sqlalchemy.engine.base.Connection` when calling
        commands from :mod:`alembic.command` programmatically.

        .. seealso::

            :ref:`connection_sharing`

            :paramref:`.Config.attributes`

        r   )r   r   r   r   r      s   zConfig.attributesc                 G   s2   |r
t || }nt |}t| j|d dS )a\  Render a message to standard out.

        When :meth:`.Config.print_stdout` is called with additional args
        those arguments will formatted against the provided text,
        otherwise we simply output the provided text verbatim.

        e.g.::

            >>> config.print_stdout('Some text %s', 'arg')
            Some Text arg

        
N)r   	text_typer   write_outstreamr   )r   textargoutputr   r   r   print_stdout   s   
zConfig.print_stdoutc                 C   s^   | j rtjtj| j }nd}|| jd< t| j}| j r'|| j g |S || j	 |S )a  Return the underlying ``ConfigParser`` object.

        Direct access to the .ini file is available here,
        though the :meth:`.Config.get_section` and
        :meth:`.Config.get_main_option`
        methods provide a possibly simpler interface.

         here)
r   ospathabspathdirnamer   r   readadd_sectionr   )r   r"   file_configr   r   r   r)      s   

zConfig.file_configc                 C   s,   ddl }tjtj|j}tj|dS )zReturn the directory where Alembic setup templates are found.

        This method is used by the alembic ``init`` and ``list_templates``
        commands.

        r   N	templates)r
   r#   r$   r%   r&   __file__join)r   r
   package_dirr   r   r   get_template_directory   s   zConfig.get_template_directoryc                 C   s    | j |s|S t| j |S )zfReturn all the configuration options from a given .ini file section
        as a dictionary.

        )r)   has_sectionr   itemsr   namedefaultr   r   r   get_section   s   zConfig.get_sectionc                 C   s   |  | j|| dS )a:  Set an option programmatically within the 'main' section.

        This overrides whatever was in the .ini file.

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)set_section_optionr   )r   r2   valuer   r   r   set_main_option   s   zConfig.set_main_optionc                 C   s   | j | j| d S N)r)   remove_optionr   )r   r2   r   r   r   remove_main_option   s   zConfig.remove_main_optionc                 C   s,   | j |s| j | | j ||| dS )a  Set an option programmatically within the given section.

        The section is created if it doesn't exist already.
        The value here will override whatever was in the .ini
        file.

        :param section: name of the section

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)r)   r/   r(   set)r   sectionr2   r6   r   r   r   r5      s   zConfig.set_section_optionc                 C   s@   | j |std| j|f | j ||r| j ||S |S )z9Return an option from the given section of the .ini file.z6No config file %r found, or file has no '[%s]' section)r)   r/   r   CommandErrorr   
has_optionget)r   r<   r2   r3   r   r   r   get_section_option  s   zConfig.get_section_optionc                 C   s   |  | j||S )zReturn an option from the 'main' section of the .ini file.

        This defaults to being a key from the ``[alembic]``
        section, unless the ``-n/--name`` flag were used to
        indicate a different section.

        )r@   r   r1   r   r   r   get_main_option  s   zConfig.get_main_optionr8   )__name__
__module____qualname____doc__sysr   r   immutabledictr   r   r   r   memoized_propertyr   r    r)   r.   r4   r7   r:   r5   r@   rA   r   r   r   r   r	      s8    J





r	   c                   @   s0   e Zd Zd
ddZdd Zdd Zd
dd	ZdS )CommandLineNc                 C   s   |  | d S r8   )_generate_args)r   progr   r   r   r     s   zCommandLine.__init__c                    s  fdd}t |d}|jdddt d |jdd	ttjd
ddd |jddtddd |jdddd |jdddd | }tj	ddiidd t
tD D ] t r܈ jd dkr܈ jdkrt }|d  r|d d!t|d    }|d t|d   d  }n
|d d!d  }g } v r fd"d|D } j}|rg }	|d#D ]}
|
 s n|	|
  qnd$}	|j jd%|	d&| || j ||fd' qS|| _d S )(Nc           	   	      s  i dddt dtddfddd	t td
dfddt dddfddt tddfddt tddfddt dddfddt dddfddt td dfd!d"t td#dfd$d%t td&dfd'd(d)t dd*dfd+d,t dd-dfd.d/t dd0dfd1d2d3t d4d5dfd6d7d8t dd9dfd:d;t dd<dfd=d>t dd?df}d@dAdBdC}|D ]}||v r|| }|dDdE |dE }}|j|i | q|D ](}|dFks|  v r |  | dFkrjdFdG|dFdH qɈj|||dI qd S )JNtemplatez-tz
--templategenericz"Setup template for use with 'init')r3   typehelpmessagez-mz	--messagez%Message string to use with 'revision')rN   rO   sqlz--sql
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionrO   tagz--tagz<Arbitrary 'tag' name - can be used by custom env.py scripts.headz--headzCSpecify head revision or <branchname>@head to base new revision on.splicez--splicez6Allow a non-head revision as the 'head' to splice onto
depends_onz--depends-onappendzNSpecify one or more revision identifiers which this revision should depend on.rev_idz--rev-idz9Specify a hardcoded revision id instead of generating oneversion_pathz--version-pathz2Specify specific path from config for version filebranch_labelz--branch-labelz3Specify a branch label to apply to the new revisionverbosez-vz	--verbosezUse more verbose outputresolve_dependenciesz--resolve-dependenciesz+Treat dependency versions as down revisionsautogeneratez--autogeneratezgPopulate revision script with candidate migration operations, based on comparison of database to model.	rev_rangez-rz--rev-rangestorez1Specify a revision range; format is [start]:[end]indicate_currentz-iz--indicate-currentzIndicate the current revisionpurgez--purgez7Unconditionally erase the version table before stampingpackagez	--packagezFWrite empty __init__.py files to the environment and version locationszlocation of scripts directoryzrevision identifierz/one or more revisions, or 'heads' for all heads)	directoryrevision	revisionsr   rg   +)nargsrO   rO   )r   stradd_argumentr?   )	fnparser
positionalkwargskwargs_optspositional_helpr   argskw)positional_translations	subparserr   r   add_options   sL  
"*2:BJR
W^gpx   z/CommandLine._generate_args.<locals>.add_optionsrK   z	--versionversionz%%(prog)s %s)rT   rz   z-cz--configALEMBIC_CONFIGzalembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")rN   r3   rO   z-nz--namer
   z6Name of section in .ini file to use for Alembic configz-xrY   zlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingrS   z
--raiseerrrR   z!Raise a full stack trace on errorrf   rg   c                 S   s   g | ]}t t|qS r   )getattrr   ).0nr   r   r   
<listcomp>  s    z.CommandLine._generate_args.<locals>.<listcomp>r   _zalembic.command   r   c                    s   g | ]
}   ||qS r   )r?   )r}   r2   )rn   rv   r   r   r     s    r   r!    rk   )cmd)r   rm   r   rl   r#   environr?   add_subparsersr   stampdirinspect
isfunctionrB   rC   r   inspect_getargspeclenrE   splitstriprY   
add_parserr,   set_defaultsro   )r   rK   rx   ro   
subparsersspecrp   kwarghelp_	help_textliner   )rn   rv   rw   r   rJ     s    
$


zCommandLine._generate_argsc              
      s    j \}}}z||g fdd|D R i t fdd|D  W d S  tjyC } z jr1 tt| W Y d }~d S d }~ww )Nc                    s   g | ]}t  |d qS r8   r|   r}   koptionsr   r   r     s    z'CommandLine.run_cmd.<locals>.<listcomp>c                 3   s     | ]}|t  |d fV  qd S r8   r   r   r   r   r   	<genexpr>  s    z&CommandLine.run_cmd.<locals>.<genexpr>)r   r   r   r=   raiseerrerrrl   )r   configr   rn   rp   r   er   r   r   run_cmd  s   zCommandLine.run_cmdc                 C   sH   | j |}t|ds| j d d S t|j|j|d}| || d S )Nr   ztoo few arguments)r   r   r   )ro   
parse_argshasattrerrorr	   r   r2   r   )r   argvr   cfgr   r   r   main  s   
zCommandLine.mainr8   )rB   rC   rD   r   rJ   r   r   r   r   r   r   rI     s    
 prI   c                 K   s   t |dj| d dS )z(The console runner function for Alembic.ry   )r   N)rI   r   )r   rK   rq   r   r   r   r   ,  s   r   __main__)NN)argparser   r   r#   rF   r!   r   r   r   r   util.compatr   objectr	   rI   r   rB   r   r   r   r   <module>   s&        

