bgUjddlmZddlmZddlmZddlmZddlZddlZddl Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddlmZddlmZddlmZddlmZddlmZGddZGddedZGddZddZedkr edSdS)) annotations)ArgumentParser) Namespace) ConfigParserN)Any)cast)Dict)Mapping)Optional)overload)TextIO)Union) TypedDict) __version__)command)util)compatceZdZUdZdddejdejdfd4dZdZ d e d < dZ de d< dZ de d< ej dZd5dZej dZd6dZe d7d8d Zed9d"Zed:d%Z d;dd*Zd?d,Z d;d@d.ZedAd/Ze d;dBd0Zd;d1Zej dCd3ZdS)DConfiga_ 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 ``ConfigParser()`` 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` Nalembicfile_"Union[str, os.PathLike[str], None] ini_sectionstr output_bufferOptional[TextIO]stdoutr cmd_optsOptional[Namespace] config_argsMapping[str, Any] attributesOptional[dict]returnNonec||_||_||_||_||_t ||_|r|j|dSdS)z Construct a new :class:`.Config`N) config_file_nameconfig_ini_sectionrrrdictr!r#update)selfrrrrrr!r#s E/opt/cloudlinux/venv/lib64/python3.11/site-packages/alembic/config.py__init__zConfig.__init__dsh!&"-*    ,,  / O " ": . . . . . / /r(r)ciS)aA 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,s r-r#zConfig.attributess $ r/textc|rt||z}nt|}tj|j|dfi|jdS)aRender 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. This is a no-op when the``quiet`` messaging option is enabled. e.g.:: >>> config.print_stdout('Some text %s', 'arg') Some Text arg  N)rrwrite_outstreamrmessaging_opts)r,r3argoutputs r- print_stdoutzConfig.print_stdoutsP  YY_FFYYF T[&$NN$:MNNNNNr/cR|jrBtjtj|j}nd}||jd<t |j}|jr||jgn||j |S)aReturn 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(ospathabspathdirnamer!rread add_sectionr))r,r= file_configs r-rDzConfig.file_configs   7??27??43H#I#IJJDDD#' "4#344   =   d34 5 5 5 5  # #D$; < < <r/cddl}tjtj|j}tj|dS)zReturn the directory where Alembic setup templates are found. This method is used by the alembic ``init`` and ``list_templates`` commands. rN templates)rr>r?r@rA__file__join)r,r package_dirs r-get_template_directoryzConfig.get_template_directorysG goobgoog6F&G&GHH w||K555r/.namedefaultOptional[Dict[str, str]]cdSNr1r,rKrLs r- get_sectionzConfig.get_section  r/Dict[str, str]cdSrOr1rPs r-rQzConfig.get_sectionrRr/Mapping[str, str](Union[Dict[str, str], Mapping[str, str]]cdSrOr1rPs r-rQzConfig.get_sectionrRr/Optional[Mapping[str, str]]c|j|s|St|j|S)zReturn all the configuration options from a given .ini file section as a dictionary. If the given section does not exist, the value of ``default`` is returned, which is expected to be a dictionary or other mapping. )rD has_sectionr*itemsrPs r-rQzConfig.get_sectionsA++D11 ND$**400111r/valuec>||j||dS)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,rKr\s r-set_main_optionzConfig.set_main_options%  7uEEEEEr/cF|j|j|dSrO)rD remove_optionr))r,rKs r-remove_main_optionzConfig.remove_main_options$ &&t'>EEEEEr/sectionc|j|s|j||j|||dS)aSet 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)rDrZrCset)r,rcrKr\s r-r^zConfig.set_section_optionsU(++G44 2   ( ( 1 1 1 WdE22222r/ Optional[str]c|j|s tjd|jd|d|j||r|j||S|S)z9Return an option from the given section of the .ini file.zNo config file z found, or file has no '[z ]' section)rDrZr CommandErrorr( has_optionget)r,rcrKrLs r-get_section_optionzConfig.get_section_option-s++G44 ##$($9$9$9777D    & &w 5 5 #''66 6Nr/cdSrOr1rPs r-get_main_optionzConfig.get_main_option;s r/cdSrOr1rPs r-rmzConfig.get_main_option?rRr/c:||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. )rkr)rPs r-rmzConfig.get_main_optionEs&&t'>gNNNr/MessagingOptionsc |tttjdt |jddiS)zThe messaging options.quietF)rrpr immutabledictgetattrrr2s r-r7zConfig.messaging_optsOs?   '$-%@@A     r/)rrrrrrrr rr r!r"r#r$r%r&)r3rr%r&)r%r).)rKrrLr&r%rM)rKrrLrSr%rS)rKrrLrUr%rVrO)rKrrLrXr%rX)rKrr\rr%r&)rKrr%r&)rcrrKrr\rr%r&)rcrrKrrLrfr%rf)rKrrLrr%r)rKrrLrfr%rf)r%rp)__name__ __module__ __qualname____doc__sysrrrsr.r__annotations__r(r)memoized_propertyr#r:rDrJr rQr_rbr^rkrmr7r1r/r-rrsFFT59$*.(,););)=)=%)/////(%)H(((( <@????2""""" &OOOO. , 6 6 6 6),    X    X    X AE 2 2 2 2 2FFFF"FFFF33332AE        X 26    X OOOO       r/rceZdZUded<dS)rpboolrrN)rurvrwrzr1r/r-rprpZsKKKKKr/rpF)totalc0eZdZdddZddZdd Zdd ZdS) CommandLineNprogrfr%r&c0||dSrO)_generate_args)r,rs r-r.zCommandLine.__init___s D!!!!!r/c J fd}t|}|dddtz|ddttjd d d |d dtdd |ddd|ddd|dddd|}tj ddii dttDD]y tj ra j ddkrO jd krCtj }|d!I|dd"t#|d! }|dt#|d! d}n|dd"d}g} vr fd#|D} j}|rXg} |d$D]?} | sn(| | @ng} | j d%| & | ||  ||f'{||_dS)(Nc `idddtdtdfddd ttd fd d tddfddttd fddttd fddtddfddtddfddttd fd!d"ttd# fd$d%ttd& fd'd(d)tdd*fd+d,tdd-fd.d/tdd0fd1d2d3td4d5fd6d7d8tdd9fd:d;tdd<fd=d>tdd?f}d@dAdBdC}|D]-}||vr'||}|dDdE|dE}}|j|i|.|D]t}|dFks| vr> ||dFkr, dFdG|dFHJ |||IudS)JNtemplatez-tz --templategenericz"Setup template for use with 'init')rLtypehelpmessagez-mz --messagez%Message string to use with 'revision')rrsqlz--sql store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionrtagz--tagz@head to base new revision on.splicez--splicez6Allow a non-head revision as the 'head' to splice onto depends_onz --depends-onappendzNSpecify 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 revisionverbosez-vz --verbosezUse more verbose outputresolve_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-rangestorez1Specify a revision range; format is [start]:[end]indicate_currentz-iz--indicate-currentzIndicate the current revisionpurgez--purgez7Unconditionally erase the version table before stampingpackagez --packagezFWrite empty __init__.py files to the environment and version locationszlocation of scripts directoryzrevision identifierz/one or more revisions, or 'heads' for all heads) directoryrevision revisionsrr+)nargsrr)r*r add_argumentrj) fnparser positionalkwargs kwargs_optspositional_helpr8argskwpositional_translations subparsers r- add_optionsz/CommandLine._generate_args..add_optionscs<H  ) AH 'NH"+(#H4 15HD 3EHT+0UHd"'@eHt )uHD$ '!EHT$ '!UHd 3LMMMeHn',+J)oH|$+0!}HN!&2OH`#(+<%aHp+*qH@+<AHKT=1NO  5 5+%%&s+D#AbDz48"D'F'4444! O O;&&444/3C8KGG**#!,00==+ **3_5H5H5M5M*NNNN O Or/rz --versionversionz %%(prog)s %s)rrz-cz--configALEMBIC_CONFIGz alembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")rrLrz-nz--namerz6Name of section in .ini file to use for Alembic configz-xrzlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingrz --raiseerrrz!Raise a full stack trace on errorz-qz--quietzDo not log to std output.rrc8g|]}tt|Sr1)rtr).0ns r- z.CommandLine._generate_args..0s"===177A&&===r/r_zalembic.commandrcHg|]}||Sr1)rj)rrKrrs r-rz.CommandLine._generate_args..@s>""" 0377dCC"""r/r5 r)cmd)rrrrr>environrjadd_subparsersrstampdirinspect isfunctionrurvrinspect_getfullargspeclenrxsplitstripr add_parserrH set_defaultsr)r,rrr subparsersspecrkwarghelp_ help_textlinerrrs @@@r-rzCommandLine._generate_argsbsYa Oa Oa Oa Oa Oa OF T***  >K3O       JNN#3]CCD       L      ;      4      ,    **,, #*=:{2K"L==G ===$ D$ DB"2&&# DKNc))M%6664R887&!%ac$q'll]):!;J GSa\\MOO4EE!%aJE000"""""$."""J  # "I % D 1 1;;#zz||;!E%,,TZZ\\:::: "I&11Kchhy&9&92  B :u===&&B E+B&CCC r/configroptionsrcj\}}} ||gfd|DRifd|DdS#tj$r7}jrtjt |fi|jYd}~dSd}~wwxYw)Nc2g|]}t|dSrOrtrkrs r-rz'CommandLine.run_cmd..]s%@@@''1d++@@@r/c4i|]}|t|dSrOrrs r- z'CommandLine.run_cmd..^s'???A1ggq$//???r/)rrrhraiseerrerrrr7)r,rrrrres ` r-run_cmdzCommandLine.run_cmdWs ' J : B @@@@Z@@@   @??????        : : : :Q996#8999999999  :s$4A:,A55A:c|j|}t|ds|jddSt |j|j|}|||dS)Nrztoo few arguments)rrr)r parse_argshasattrerrorrrrKr)r,argvrcfgs r-mainzCommandLine.mainfs+((..w&& ' K  1 2 2 2 2 2n#L C LLg & & & & &r/rO)rrfr%r&)rrrrr%r&)rurvrwr.rrrr1r/r-rr^sn"""""ssssj : : : : ' ' ' ' ' 'r/rc Nt||dS)z(The console runner function for Alembic.r)rN)rr)rrrs r-rrus,TT*****r/__main__)NN) __future__rargparserr configparserrrr>rytypingrrr r r r r rtyping_extensionsrr<rrrrrrprrrur1r/r-rs""""""######%%%%%% ''''''} } } } } } } } @ yT'T'T'T'T'T'T'T'n++++  zDFFFFFr/