
 X                 @   sf   d  d l  m Z d  d l m Z m Z d  d l m Z m Z d  d l m	 Z	 Gd d   d e  Z
 d S)    )unicode_literals)BaseCommandCommandError)DEFAULT_DB_ALIASconnections)MigrationLoaderc               @   sI   e  Z d  Z d Z d d   Z d d   Z d d d  Z d	 d
   Z d S)Commandz6Shows all available migrations for the current projectc             C   s   | j  d d d d d | j  d d d d	 d
 d t d d | j   } | j  d d d d d	 d d d d d | j  d d d d d	 d d d d d | j d d  d  S)N	app_labelnargs*helpz2App labels of applications to limit the output to.z
--databaseactionstoredestdatabasedefaultzHNominates a database to synchronize. Defaults to the "default" database.z--listz-lstore_constformatconstlistz5Shows a list of all migrations and which are applied.z--planz-pplanzShows 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.)add_argumentr   add_mutually_exclusive_groupset_defaults)selfparserformats r   \/home/ubuntu/projects/ifolica/build/django/django/core/management/commands/showmigrations.pyadd_arguments   s    zCommand.add_argumentsc             O   sV   | d |  _  | d } t | } | d d k r> |  j |  S|  j | | d  Sd  S)N	verbosityr   r   r   r	   )r    r   	show_plan	show_list)r   argsoptionsdb
connectionr   r   r   handle&   s    

zCommand.handleNc             C   s  t  | d d } | j } | r| g  } x- | D]% } | | j k r. | j |  q. q. W| r t d d j |    q n t | j  } x'| D]} |  j j | |  j	 j
  t   } x | j |  D] } x | j |  D] }	 |	 | k r |	 d | k r |	 d }
 | j |	 j r=|
 d t | j |	 j  7}
 n  |	 | j k rc|  j j d |
  n |  j j d	 |
  | j |	  q q Wq W| s |  j j d
 |  j	 j  q q Wd S)zi
        Shows a list of all migrations on the system, or only those of
        some named apps.
        Zignore_no_migrationsTzNo migrations present for: %sz, r      z (%s squashed migrations)z [X] %sz [ ] %sz (no migrations)N)r   graphZmigrated_appsappendr   joinsortedstdoutwritestyleZMIGRATE_LABELset
leaf_nodesforwards_planZnodesZreplaceslenapplied_migrationsaddERROR)r   r&   Z	app_namesloaderr)   Zinvalid_appsZapp_nameZshownnodeZ	plan_nodetitler   r   r   r"   2   s2    		
!zCommand.show_listc             C   sA  t  |  } | j } | j   } g  } t   } x^ | D]V } xM | j |  D]< } | | k rM | j | }	 | j |	  | j |  qM qM Wq7 Wd d   }
 x | D] }	 d } |  j d k r |
 |	  } n  |	 j	 | j
 k r|  j j d |	 j	 d |	 j	 d | f  q |  j j d |	 j	 d |	 j	 d | f  q Wd	 S)
zN
        Shows all known migrations in the order they will be applied
        c             S   sO   g  } x+ t  |  j  D] } | j d | j  q W| rK d d j |  Sd S)Nz%s.%sz	 ... (%s)z,  )r,   parentsr*   keyr+   )r8   outparentr   r   r   
print_depso   s    z%Command.show_plan.<locals>.print_depsr:      z[X]  %s.%s%sr   r(   z[ ]  %s.%s%sN)r   r)   r1   r0   r2   Znode_mapr*   r5   r    r<   r4   r-   r.   )r   r&   r7   r)   targetsr   seentargetZ	migrationr8   r?   depsr   r   r   r!   [   s&    		.zCommand.show_plan)__name__
__module____qualname__r   r   r'   r"   r!   r   r   r   r   r   	   s
   )r   N)
__future__r   Zdjango.core.management.baser   r   Z	django.dbr   r   Zdjango.db.migrations.loaderr   r   r   r   r   r   <module>   s   