B
    ©0H[Õ  ã               @   s@   d dl mZmZ d dlmZmZ d dlmZ G dd„ deƒZdS )é    )ÚBaseCommandÚCommandError)ÚDEFAULT_DB_ALIASÚconnections)ÚMigrationLoaderc               @   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   sh   |j dddd� |j dd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
--databaseÚstoreÚdatabasezHNominates a database to synchronize. Defaults to the "default" database.)ÚactionÚdestÚdefaultr   z--listz-lÚstore_constÚformatÚlistz5Shows a list of all migrations and which are applied.)r   r   Ú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   úrC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\core\management\commands\showmigrations.pyÚadd_arguments	   s    

zCommand.add_argumentsc             O   sJ   |d | _ |d }t| }|d dkr6|  ||d ¡S |  ||d ¡S d S )NÚ	verbosityr   r   r   r   )r   r   Ú	show_planÚ	show_list)r   ÚargsÚoptionsÚdbÚ
connectionr   r   r   Úhandle#   s    
zCommand.handlec             C   sD   g }x |D ]}||j kr
| |¡ q
W |r@tdd t|ƒ¡ ƒ‚d S )NzNo migrations present for: %sz, )Úmigrated_appsÚappendr   ÚjoinÚsorted)r   ÚloaderÚ	app_namesZinvalid_appsÚapp_namer   r   r   Ú_validate_app_names/   s    

zCommand._validate_app_namesNc       
      C   s  t |dd�}|j}|r$|  ||¡ n
t|jƒ}xØ|D ]Ð}| j || jj¡ t	ƒ }xœ| 
|¡D ]Ž}xˆ| |¡D ]z}||krl|d |krl|d }	|j| jr°|	dt|j| jƒ 7 }	||jkrÌ| j d|	 ¡ n| j d|	 ¡ | |¡ qlW q\W |s4| j d| jj¡ q4W d	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 [ ] %sz (no migrations)N)r   Úgraphr.   r*   r'   ÚstdoutÚwriteÚstyleZMIGRATE_LABELÚsetÚ
leaf_nodesÚforwards_planZnodesZreplacesÚlenÚapplied_migrationsÚaddÚERROR)
r   r%   r,   r+   r0   r-   ZshownÚnodeZ	plan_nodeÚtitler   r   r   r!   7   s(    


zCommand.show_listc                s  t |ƒ}|j}ˆ r6|  |ˆ ¡ ‡ fdd„| ¡ D ƒ}n| ¡ }g }tƒ }xF|D ]>}x8| |¡D ]*}	|	|kr^|j|	 }
| |
¡ | |	¡ q^W qNW dd„ }xt|D ]l}
d}| j	dkr¸||
ƒ}|
j
|jkrè| j d|
j
d |
j
d	 |f ¡ qž| j d
|
j
d |
j
d	 |f ¡ qžW 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  ˆ kr|‘qS )r   r   )Ú.0Úkey)r,   r   r   ú
<listcomp>e   s    z%Command.show_plan.<locals>.<listcomp>c             S   s>   g }x"t | jƒD ]}| d|j ¡ qW |r:dd |¡ S dS )Nz%s.%sz	 ... (%s)z, Ú )r*   Úparentsr(   r>   r)   )r;   ÚoutÚparentr   r   r   Ú
print_depst   s    z%Command.show_plan.<locals>.print_depsr@   é   z[X]  %s.%s%sr   r/   z[ ]  %s.%s%sN)r   r0   r.   r5   r4   r6   Znode_mapr(   r9   r   r>   r8   r1   r2   )r   r%   r,   r+   r0   Útargetsr   ÚseenÚtargetZ	migrationr;   rD   Údepsr   )r,   r   r    [   s,    




$zCommand.show_plan)N)N)	Ú__name__Ú
__module__Ú__qualname__r   r   r&   r.   r!   r    r   r   r   r   r      s   
$r   N)	Zdjango.core.management.baser   r   Z	django.dbr   r   Zdjango.db.migrations.loaderr   r   r   r   r   r   Ú<module>   s   