ó
®â0_c           @   sX  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z 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 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  d l# m$ Z$ d  d l% m& Z& d e f d „  ƒ  YZ' d S(   iÿÿÿÿN(   t	   takewhile(   t   apps(   t   settings(   t   BaseCommandt   CommandError(   t   DEFAULT_DB_ALIASt   connectionst   router(   t	   Migration(   t   MigrationAutodetector(   t   MigrationLoader(   t   InteractiveMigrationQuestionert   MigrationQuestionert!   NonInteractiveMigrationQuestioner(   t   ProjectState(   t   get_migration_name_timestamp(   t   MigrationWriter(   t   RemovedInDjango20Warning(   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" ƒ| j  d# d	 d
 d d$ 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_codesn   Exit with error code 1 if no changes needing migrations are found. Deprecated, use the --check option instead.s   --checkt   check_changessD   Exit with a non-zero status if model changes are missing migrations.(   t   add_argumentt   Falset   Truet   None(   t   selft   parser(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyt   add_arguments   s2    	c      	      s2  | d |  _  | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d |  _ | d } |  j r t j d	 t	 ƒ n  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 ƒ} t
 d „  t j ƒ  Dƒ ƒ } t j rQt n t g } x] t | ƒ D]O }	 t |	 ‰ ˆ j d d k rgt ‡ f d †  | Dƒ ƒ rg| j ˆ ƒ qgqgW| j ƒ  }
 ˆ  rë‡  f d †  t  |
 ƒ Dƒ }
 n  |
 r-|  j r-d j! d „  |
 j" ƒ  Dƒ ƒ } t# d | ƒ ‚ n  |  j rQ|
 rQ|  j$ j d ƒ d  S|  j rp|
 rp|  j% | |
 ƒ S|  j r”t& d ˆ  d |  j ƒ } n t' d ˆ  d |  j ƒ } t( | j) ƒ  t* j+ t ƒ | ƒ } |  j r0ˆ  sët# d ƒ ‚ n  d „  ˆ  Dƒ } | j, d | d | j- d |  j ƒ } |  j. | ƒ d  S| j/ d | j- d ˆ  pKd  d ˆ  pWd  d |  j ƒ } | s|  j  d k rït0 ˆ  ƒ d k rª|  j$ j d ˆ  j1 ƒ  ƒ qït0 ˆ  ƒ d k rÜ|  j$ j d  d! j! ˆ  ƒ ƒ qï|  j$ j d" ƒ n  |  j r.t j d ƒ q.n# |  j. | ƒ | r.t j d ƒ n  d  S(#   Nt	   verbosityR#   R   R    R!   R%   R&   R'   s?   The --exit option is deprecated in favor of the --check option.s5   App '%s' could not be found. Is it in INSTALLED_APPS?i   t   ignore_no_migrationsc         s   s   |  ] } | j  Vq d  S(   N(   t   label(   t   .0t   config(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys	   <genexpr>c   s    t   ENGINEs   django.db.backends.dummyc         3   sL   |  ]B } t  j | ƒ j ƒ  D]& } t j ˆ  j | d  | j j ƒVq q d S(   t
   model_nameN(   R   t   get_app_configt
   get_modelsR   t   allow_migratet   aliast   _metat   object_name(   R2   R   t   model(   t
   connection(    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys	   <genexpr>j   s   c            s+   i  |  ]! \ } } | ˆ  k r | | “ q S(    (    (   R2   R   t   conflict(   t
   app_labels(    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys
   <dictcomp>w   s   	 	s   ; c         s   s.   |  ]$ \ } } d  d j  | ƒ | f Vq d S(   s   %s in %ss   , N(   t   join(   R2   t   appt   names(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys	   <genexpr>}   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   (   R2   RA   (    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys
   <dictcomp>¡   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(2   R/   R#   R   R    R!   RG   R&   t   warningst   warnR   t   setR   R6   t   LookupErrort   addt   stderrt   writet   syst   exitR
   R+   R*   t   get_app_configsR   t   DATABASE_ROUTERSR   R   t   sortedt   settings_dictt   anyt   check_consistent_historyt   detect_conflictsR   R@   t   itemsR   t   stdoutt   handle_mergeR   R   R	   t   project_stateR   t	   from_appst   arrange_for_graphRF   t   write_migration_filesRE   t   lent   pop(   R,   R?   t   optionsR'   t   bad_app_labelsR   t   loadert   consistency_check_labelst   aliases_to_checkR9   t	   conflictst   name_strt
   questionert   autodetectorRE   (    (   R?   R=   sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyt   handleA   s¤    
	
	
				
				 	c         C   sZ  i  } xM| j  ƒ  D]?\ } } |  j d k rU |  j j |  j j d | ƒ d ƒ n  xú| D]ò} t | ƒ } |  j d k r"y t j j	 | j ƒ } Wn t
 k
 r² | j } n X| j d ƒ rÎ | j } n  |  j j d |  j j | ƒ f ƒ x. | j D]  } |  j j d | j ƒ  ƒ qû Wn  |  j sût j j | j ƒ }	 | j | ƒ s»t j j |	 ƒ sqt j |	 ƒ n  t j j |	 d ƒ }
 t j j |
 ƒ s®t |
 d ƒ j ƒ  n  t | | <n  | j ƒ  } t j | j d d	 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
s   __init__.pyt   wt   encodings   utf-8Ni   s   Full migrations file '%s':s   %s
(   RZ   R/   R[   RP   t   stylet   MIGRATE_HEADINGR   t   ost   patht   relpatht
   ValueErrort
   startswitht   MIGRATE_LABELt
   operationst   describeR   t   dirnamet   gett   isdirt   mkdirR@   t   isfilet   opent   closeR*   t	   as_stringt   iot   filename(   R,   RE   t   directory_createdR   t   app_migrationst	   migrationt   writert   migration_stringt	   operationt   migrations_directoryt	   init_patht   fh(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyR`   Å   s@    '#!	c      	      s§  |  j  r t ƒ  } n t d i t d 6ƒ } xu| j ƒ  D]g\ } } 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 |  j p»d t  ƒ  f } | | | ƒ } t! | ƒ } |  j" sIt# j$ | j% d d d ƒ } | j | j& ƒ  ƒ Wd QX|  j d k rœ|  j j d | j% ƒ qœqŸ|  j d k rŸ|  j j |  j j d | j' ƒ d ƒ |  j j d | j& ƒ  ƒ qŸ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(    (   R2   t   item(   t   seq(    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys	   <genexpr>
  s    i   (   t   all(   R   (    (   R   sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyt   all_items_equal	  s    c         s   s   |  ] } d  Vq d S(   i   N(    (   R2   t   common_ancestor_generation(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/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_migrationRw   (   R2   t   node_appt	   node_name(   Re   (    sP   /tmp/pip-unpacked-wheel-BAJOf3/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+   (   R2   t   x(    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pys	   <genexpr>(  s    i   R   t   dependenciess   %04i_%ss   merge_%sRm   Rn   s   utf-8Ns   
Created new merge migration %si   s    Full merge migrations file '%s':s   
s   %s
((   R#   R   R   R*   RZ   R“   RF   t   forwards_planR   t   ancestryt   appendR   t   sumR    Rt   t   brancht   merged_operationsR/   R[   RP   Ro   Rp   Rv   R%   Rx   R   R	   t   parse_numbert   maxt   typeR   RG   R   R   R   R   R~   Rr   R€   R‚   (   R,   Re   Rh   Rj   R   t   migration_namest   merge_migrationsRG   R…   t   migR‘   t   mt   merge_migrations_generationst   common_ancestor_countt   migrations_opsRˆ   t   numberst   biggest_numbert   subclasst   new_migrationR†   R‹   (    (   Re   sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyR\   ó   sd    	"	"	 #%"
)	(   t   __name__t
   __module__R   R.   Rl   R`   R\   (    (    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyR      s
   	$	„	.((   R   Rq   RQ   RJ   t	   itertoolsR    t   django.appsR   t   django.confR   t   django.core.management.baseR   R   t	   django.dbR   R   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.utilsR   t   django.db.migrations.writerR   t   django.utils.deprecationR   t   django.utils.sixR   t   django.utils.six.movesR   R   (    (    (    sP   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/makemigrations.pyt   <module>   s&   