ó
i4Vdc           @   sô   d  d l  Z  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 d  d l m Z d  d l m Z m Z m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t	   takewhile(   t   apps(   t   BaseCommandt   CommandError(   t	   Migration(   t   MigrationAutodetector(   t   MigrationLoader(   t   InteractiveMigrationQuestionert   MigrationQuestionert!   NonInteractiveMigrationQuestioner(   t   ProjectState(   t   MigrationWriter(   t	   iteritems(   t   zipt   Commandc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s"   Creates new migration(s) for apps.c         C   s
  | j  d d d d d d d ƒ| j  d d	 d
 d d d t d d ƒ| j  d d	 d
 d d d t d d ƒ| j  d d	 d
 d d d t d d ƒ| j  d d d	 d d d d t d d ƒ| j  d d d	 d d d d d  d d ƒ| j  d d  d	 d
 d d! d t d d" ƒd  S(#   Nt   argst   metavart	   app_labelt   nargst   *t   helps2   Specify the app label(s) to create migrations for.s	   --dry-runt   actiont
   store_truet   destt   dry_runt   defaultsC   Just show what migrations would be made; don't actually write them.s   --merget   merges%   Enable fixing of migration conflicts.s   --emptyt   emptys   Create an empty migration.s	   --noinputs
   --no-inputt   store_falset   interactives:   Tells Django to NOT prompt the user for input of any kind.s   -ns   --namet   storet   names$   Use this name for migration file(s).s   -es   --exitt	   exit_codesB   Exit with error code 1 if no changes needing migrations are found.(   t   add_argumentt   Falset   Truet   None(   t   selft   parser(    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyt   add_arguments   s    !!c      	      s•  | j  d ƒ |  _ | j  d ƒ |  _ | j  d t ƒ |  _ | j  d t ƒ |  _ | j  d t ƒ |  _ | j  d ƒ |  _ | j  d t ƒ |  _ t	 ˆ  ƒ ‰  t	 ƒ  } x@ ˆ  D]8 } y t
 j | ƒ Wq¦ t k
 rÝ | j | ƒ q¦ Xq¦ W| rx" | D] } |  j j d | ƒ qï Wt j d	 ƒ n  t d  d
 t ƒ} | j ƒ  } ˆ  r`‡  f d †  t | ƒ Dƒ } n  | r¢|  j r¢d j d „  | j ƒ  Dƒ ƒ } t d | ƒ ‚ n  |  j rÆ| rÆ|  j j d ƒ d  S|  j rå| rå|  j | | ƒ S|  j r	t d ˆ  d |  j ƒ } n t d ˆ  d |  j ƒ } t | j ƒ  t  j! t
 ƒ | ƒ }	 |  j r¥ˆ  s`t d ƒ ‚ n  d „  ˆ  Dƒ }
 |	 j" d |
 d | j# d |  j ƒ }
 |  j$ |
 ƒ d  S|	 j% d | j# d ˆ  pÀd  d ˆ  pÌd  d |  j ƒ }
 |
 s„|  j d k rdt& ˆ  ƒ d k r|  j j d ˆ  j' ƒ  ƒ qdt& ˆ  ƒ d k rQ|  j j d d j ˆ  ƒ ƒ qd|  j j d ƒ n  |  j r}t j d ƒ q„d  Sn  |  j$ |
 ƒ d  S(   Nt	   verbosityR   R   R   R   R   R    s5   App '%s' could not be found. Is it in INSTALLED_APPS?i   t   ignore_no_migrationsc            s+   i  |  ]! \ } } | ˆ  k r | | “ q S(    (    (   t   .0R   t   conflict(   t
   app_labels(    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys
   <dictcomp>J   s   	 	s   ; c         s   s.   |  ]$ \ } } d  d j  | ƒ | f Vq d S(   s   %s in %ss   , N(   t   join(   R*   t   appt   names(    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys	   <genexpr>P   s   sŒ   Conflicting migrations detected; multiple leaf nodes in the migration graph: (%s).
To fix them run 'python manage.py makemigrations --merge's   No conflicts detected to merge.t   specified_appss:   You must supply at least one app label when using --empty.c         S   s%   i  |  ] } t  d  | ƒ g | “ q S(   t   custom(   R   (   R*   R.   (    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys
   <dictcomp>t   s   	t   changest   grapht   migration_namet   trim_to_appst   convert_appsi   s   No changes detected in app '%s's    No changes detected in apps '%s's   ', 's   No changes detected((   t   getR(   R   R"   R   R   R   R4   R    t   setR   t   get_app_configt   LookupErrort   addt   stderrt   writet   syst   exitR   R$   R#   t   detect_conflictsR   R-   t   itemsR   t   stdoutt   handle_mergeR   R	   R   t   project_stateR
   t	   from_appst   arrange_for_graphR3   t   write_migration_filesR2   t   lent   pop(   R%   R,   t   optionst   bad_app_labelsR   t   loadert	   conflictst   name_strt
   questionert   autodetectorR2   (    (   R,   s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyt   handle(   sˆ    					
				 	c         C   s  i  } xö| j  ƒ  D]è\ } } |  j d k rU |  j j |  j j d | ƒ d ƒ n  x£| D]›} t | ƒ } |  j d k rÔ |  j j d |  j j | j ƒ f ƒ x. | j	 D]  } |  j j d | j
 ƒ  ƒ q­ Wn  |  j s¤t j j | j ƒ } | j | ƒ smt j j | ƒ s#t j | ƒ n  t j j | d ƒ }	 t j j |	 ƒ s`t |	 d ƒ j ƒ  n  t | | <n  | j ƒ  }
 t | j d ƒ  } | j |
 ƒ Wd	 QXq\ |  j d
 k r\ |  j j |  j j d | j ƒ d ƒ |  j j d | j ƒ  ƒ q\ q\ Wq Wd	 S(   sN   
        Takes a changes dict and writes them out as migration files.
        i   s   Migrations for '%s':s   
s     %s:
s	       - %s
s   __init__.pyt   wt   wbNi   s   Full migrations file '%s':s   %s
(   RA   R(   RB   R=   t   stylet   MIGRATE_HEADINGR   t   MIGRATE_LABELt   filenamet
   operationst   describeR   t   ost   patht   dirnameR7   t   isdirt   mkdirR-   t   isfilet   opent   closeR#   t	   as_string(   R%   R2   t   directory_createdR   t   app_migrationst	   migrationt   writert	   operationt   migrations_directoryt	   init_patht   migration_stringt   fh(    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyRG   ˜   s4    '&!	c      	      s‚  |  j  r t ƒ  } n t d i t d 6ƒ } xP| j ƒ  D]B\ } } g  } xn | D]f } ˆ  j | | ƒ } g  ˆ  j j | | f ƒ D] }	 |	 d | j k r‚ |	 ^ q‚ | _	 | j
 | ƒ qQ Wd „  }
 t g  | D] } | j	 ^ qÎ Œ  } t d „  t |
 | ƒ Dƒ ƒ } | st d | ƒ ‚ n  xI | D]A } | j	 | | _ ‡  f d †  | j Dƒ } t | g  ƒ | _ q%W|  j d k rþ|  j j |  j j d | ƒ ƒ xb | D]W } |  j j |  j j d	 | j ƒ ƒ x+ | j D]  } |  j j d
 | j ƒ  ƒ qÓWq Wn  | j | ƒ r8 g  | D] } t j | j ƒ ^ q} y t d „  | Dƒ ƒ } Wn t k
 red } n Xt d t f i g  | D] } | | j f ^ q|d 6ƒ } | d | d | ƒ } t | ƒ } |  j  s$t! | j" d ƒ  } | j | j# ƒ  ƒ Wd QX|  j d k rw|  j j d | j" ƒ qwqz|  j d k rz|  j j |  j j d | j$ ƒ d ƒ |  j j d | j# ƒ  ƒ qzq8 q8 Wd S(   sŠ   
        Handles merging together conflicted migrations interactively,
        if it's safe; otherwise, advises on how to fix it.
        t   defaultst	   ask_mergei    c            s   t  ‡  f d †  ˆ  d Dƒ ƒ S(   Nc         3   s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R*   t   item(   t   seq(    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys	   <genexpr>Ó   s    i   (   t   all(   Ro   (    (   Ro   s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyt   <lambda>Ó   t    c         s   s   |  ] } d  Vq d S(   i   N(    (   R*   t   common_ancestor_generation(    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys	   <genexpr>Õ   s    s$   Could not find common ancestor of %sc         3   s*   |  ]  \ } } ˆ  j  | | ƒ j Vq d  S(   N(   t   get_migrationRX   (   R*   t   node_appt	   node_name(   RL   (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys	   <genexpr>Ü   s   s
   Merging %ss     Branch %ss	       - %s
c         s   s!   |  ] } | d  k	 r | Vq d  S(   N(   R$   (   R*   t   x(    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pys	   <genexpr>ð   s    i   R   t   dependenciess
   %04i_mergeRS   Ns   
Created new merge migration %si   s    Full merge migrations file '%s':s   
s   %s
(%   R   R   R   R#   RA   Rt   R3   t   forwards_planR   t   ancestryt   appendR   t   sumR    t
   ValueErrort   brancht   merged_operationsR(   RB   R=   RT   RU   RV   R   RY   Rm   R   t   parse_numbert   maxt   typeR   R   R   R`   R[   Rb   RW   (   R%   RL   RM   RO   R   t   migration_namest   merge_migrationsR4   Re   t   migt   all_items_equalt   mt   merge_migrations_generationst   common_ancestor_countt   migrations_opsRg   t   numberst   biggest_numbert   subclasst   new_migrationRf   Rk   (    (   RL   s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyRC   ¾   s^    	"	"	 #%"
)	(   t   __name__t
   __module__R   R'   RQ   RG   RC   (    (    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyR      s
   		p	&(   RZ   R>   t	   itertoolsR    t   django.appsR   t   django.core.management.baseR   R   t   django.db.migrationsR   t!   django.db.migrations.autodetectorR   t   django.db.migrations.loaderR   t   django.db.migrations.questionerR   R   R	   t   django.db.migrations.stateR
   t   django.db.migrations.writerR   t   django.utils.sixR   t   django.utils.six.movesR   R   (    (    (    s|   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/makemigrations.pyt   <module>   s   