B
M!V - @ s d dl Z ddlmZ ddlmZ ddlmZ ddlmZ dd Z d$d
dZ
d%ddZd&ddZd'ddZ
d(ddZdd Zd)ddZd*ddZd+ddZd,ddZd-d d!Zd"d# ZdS ). N )ScriptDirectory)EnvironmentContext)util)autogeneratec
C st | d xPt| D ]>}ttj| |d}t|}W dQ R X | d|| qW | d | d dS )zList available templateszAvailable templates:
ZREADMENz%s - %sz1
Templates are used via the 'init' command, e.g.:z,
alembic init --template generic ./scripts)print_stdoutoslistdirget_template_directoryopenpathjoinnext)configZtempnameZreadmeZsynopsis r @/opt/alt/python37/lib/python3.7/site-packages/alembic/command.pylist_templates s
r genericc
C s8 t |t jrtd| t j| |}t |t jsJtd| tdt j | t j
| t j|d}tdt j | t j
| t|}xt |D ]~}t j||}|dkrt j | j
}t |t jrtd| n|j|||d qt j|rt j||} ||| qW td| d S )
z#Initialize a new scripts directory.zDirectory %s already existszNo such template %rzCreating directory %sversionszalembic.ini.makoz File %s already exists, skipping)Zscript_locationzNPlease edit configuration/connection/logging settings in %r before proceeding.N)r accessF_OKr CommandErrorr r
r
Zstatusabspathmakedirsr r Zconfig_file_namemsgZ_generate_templateisfileZ
_copy_file)
r Z directorytemplateZtemplate_dirr scriptZfile_Z file_pathZconfig_fileZoutput_filer r r init s:
r Fheadc
s t | }
t||||||||| d }t| |
| t| d}|rfd}|rXtd fdd}
n |rx fdd}
n|rtd|rt | |
|
| j
d |
W d
Q R X dd D }t
|d
kr|d S |S d
S )zCreate a new revision file.) messager sqlr splicebranch_labelversion_pathrev_id
depends_onZrevision_environmentTz7Using --sql with --autogenerate does not make any sensec s | | g S )N)Zrun_autogenerate)revcontext)revision_contextr r retrieve_migrations` s z%revision.<locals>.retrieve_migrationsc s | | g S )N)Zrun_no_autogenerate)r'