a
    Ê[Ùf—  ã                   @   s\   d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ G dd„ deƒZdS )	é    N)Úapps)ÚBaseCommand)ÚDEFAULT_DB_ALIASÚconnections)ÚMigrationLoader)ÚMigrationRecorderc                   @   s<   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	d
„Zddd„ZdS )ÚCommandz6Shows all available migrations for the current projectc                 C   sd   |j dddd |j dtdd | ¡ }|j dd	d
dddd |j ddd
dddd |jdd d S )NÚ	app_labelÚ*z2App labels of applications to limit the output to.)ÚnargsÚhelpz
--databasezPNominates a database to show migrations for. Defaults to the "default" database.)Údefaultr   z--listz-lÚstore_constÚformatÚlistzƒShows a list of all migrations and which are applied. With a verbosity level of 2 or above, the applied datetimes will be included.)ÚactionÚdestÚconstr   z--planz-pÚplanz¶Shows all migrations in the order they will be applied. With a verbosity level of 2 or above all direct migration dependencies and reverse dependencies (run_before) will be included.)r   )Úadd_argumentr   Úadd_mutually_exclusive_groupÚset_defaults)ÚselfÚparserÚformats© r   ú€C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\django/core/management/commands/showmigrations.pyÚadd_arguments   s8    ýü	ùùzCommand.add_argumentsc                 O   sJ   |d | _ |d }t| }|d dkr6|  ||d ¡S |  ||d ¡S d S )NÚ	verbosityZdatabaser   r   r	   )r   r   Ú	show_planÚ	show_list)r   ÚargsÚoptionsÚdbÚ
connectionr   r   r   Úhandle8   s    
zCommand.handlec                 C   sh   d}|D ]L}zt  |¡ W q tyR } z | j t|ƒ¡ d}W Y d }~qd }~0 0 q|rdt d¡ d S )NFTé   )r   Zget_app_configÚLookupErrorÚstderrÚwriteÚstrÚsysÚexit)r   ÚloaderÚ	app_namesZhas_bad_namesÚapp_nameÚerrr   r   r   Ú_validate_app_namesD   s    zCommand._validate_app_namesNc                 C   sd  t |dd}t|ƒ}| ¡ }|j}|r4|  ||¡ n
t|jƒ}|D ]}| j || j	j
¡ tƒ }| |¡D ]Ü}	| |	¡D ]Ì}
|
|vrx|
d |krx|
d }|j|
 jr¼|dt|j|
 jƒ 7 }|j |
¡}|r*|
|v ràd| }n|d7 }d| }| jd	krt|d
ƒr|d|j d¡ 7 }| j |¡ n| j d| ¡ | |
¡ qxqj|sB| j d| j	j¡ qBdS )zh
        Show a list of all migrations on the system, or only those of
        some named apps.
        T)Zignore_no_migrationsr   é   z (%s squashed migrations)z [X] %sz- Run 'manage.py migrate' to finish recording.z [-] %sr&   Úappliedz (applied at %s)z%Y-%m-%d %H:%M:%Sz [ ] %sz (no migrations)N)r   r   Úapplied_migrationsÚgraphr1   ÚsortedZmigrated_appsÚstdoutr)   ÚstyleZMIGRATE_LABELÚsetÚ
leaf_nodesÚforwards_planÚnodesZreplacesÚlenÚgetr   Úhasattrr3   ÚstrftimeÚaddÚERROR)r   r$   r.   r-   ZrecorderZrecorded_migrationsr5   r/   ZshownÚnodeZ	plan_nodeÚtitleZapplied_migrationÚoutputr   r   r   r    O   sN    


ÿ
ÿÿÿÿzCommand.show_listc                    s  t |ƒ}|j}ˆ r6|  |ˆ ¡ ‡ fdd„| ¡ D ƒ}n| ¡ }g }tƒ }|D ]:}| |¡D ]*}	|	|vrZ|j|	 }
| |
¡ | |	¡ qZqLdd„ }|D ]l}
d}| j	dkr®||
ƒ}|
j
|jv rÞ| j d|
j
d |
j
d	 |f ¡ q”| j d
|
j
d |
j
d	 |f ¡ q”|s| j d| jj¡ dS )z
        Show all known migrations (or only those of the specified app_names)
        in the order they will be applied.
        c                    s   g | ]}|d  ˆ v r|‘qS )r   r   )Ú.0Úkey©r.   r   r   Ú
<listcomp>   ó    z%Command.show_plan.<locals>.<listcomp>c                 S   s:   g }t | jƒD ]}| d|j ¡ q|r6dd |¡ S dS )Nz%s.%sz	 ... (%s)z, Ú )r6   ÚparentsÚappendrG   Újoin)rC   ÚoutÚparentr   r   r   Ú
print_depsŸ   s    z%Command.show_plan.<locals>.print_depsrK   r&   z[X]  %s.%s%sr   r2   z[ ]  %s.%s%sz(no migrations)N)r   r5   r1   r:   r9   r;   Znode_maprM   rA   r   rG   r4   r7   r)   r8   rB   )r   r$   r.   r-   r5   Útargetsr   ÚseenÚtargetZ	migrationrC   rQ   Údepsr   rH   r   r   †   s0    


$$zCommand.show_plan)N)N)	Ú__name__Ú
__module__Ú__qualname__r   r   r%   r1   r    r   r   r   r   r   r   
   s   +
7r   )r+   Zdjango.appsr   Zdjango.core.management.baser   Z	django.dbr   r   Zdjango.db.migrations.loaderr   Zdjango.db.migrations.recorderr   r   r   r   r   r   Ú<module>   s   