ó
®â0_c           @   s¨   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 d  d l m Z m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   OrderedDict(   t   apps(   t   serializers(   t   BaseCommandt   CommandError(   t   parse_apps_and_model_labels(   t   DEFAULT_DB_ALIASt   routert   ProxyModelWarningc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyR      s   t   Commandc           B   s    e  Z d  Z d „  Z d „  Z RS(   s„   Output the contents of the database as a fixture of the given format (using each model's default manager unless --all is specified).c         C   sa  | j  d d d d d d d ƒ| 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 d	 g  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) ƒ| j  d* d+ d	 d  d d, d d- ƒd  S(.   Nt   argst   metavars   app_label[.ModelName]t   nargst   *t   helpsH   Restricts dumped data to the specified app_label or app_label.ModelName.s   --formatt   defaultt   jsont   destt   formats7   Specifies the output serialization format for fixtures.s   --indentt   indentt   types>   Specifies the indent level to use when pretty-printing output.s
   --databaset   actiont   storet   databasesX   Nominates a specific database to dump fixtures from. Defaults to the "default" database.s   -es	   --excludet   excludet   appendsh   An app_label or app_label.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).s   --natural-foreignt
   store_truet   use_natural_foreign_keyss/   Use natural foreign keys if they are available.s   --natural-primaryt   use_natural_primary_keyss/   Use natural primary keys if they are available.s   -as   --allt   use_base_managers–   Use Django's base manager to dump all models stored in the database, including those that would otherwise be filtered or modified by a custom manager.s   --pkst   primary_keyss…   Only dump objects with given primary keys. Accepts a comma-separated list of keys. This option only works when you specify one model.s   -os   --outputt   outputs.   Specifies file to which the output is written.(   t   add_argumentt   Nonet   intR   t   False(   t   selft   parser(    (    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyt   add_arguments   s>    c            s7  | d } | d } | d ‰ | d } | d } | d } | d } | d }	 | d	 ‰ | d
 }
 |
 r• g  |
 j  d ƒ D] } | j ƒ  ^ qz ‰ n g  ‰ t | ƒ \ ‰ ‰ t | ƒ d k rù ˆ rÔ t d ƒ ‚ n  t ‡ f d †  t j ƒ  Dƒ ƒ ‰  nÅt | ƒ d k r ˆ r t d ƒ ‚ n  t ƒ  ‰  x’| D]Š} yï | j  d ƒ \ } } y t j | ƒ } Wn% t	 k
 rˆ} t t
 | ƒ ƒ ‚ n X| j d  k s¤| ˆ k rªw0n  y | j | ƒ } Wn' t	 k
 ræt d | | f ƒ ‚ n Xˆ  j | g  ƒ } | d  k	 r$| | k r$| j | ƒ q$n  Wq0t k
 r¹ˆ rJt d ƒ ‚ n  | } y t j | ƒ } Wn% t	 k
 rŠ} t t
 | ƒ ƒ ‚ n X| j d  k s0| ˆ k r¬q0n  d  ˆ  | <q0Xq0W| t j ƒ  k ry t j | ƒ Wn t j k
 r÷n Xt d | ƒ ‚ n  t ‡  ‡ ‡ ‡ ‡ f d † } yØ d  |  j _ d  } d } | rŠ|  j j ƒ  rŠ| d d k rŠ|  j } t | d t ƒ ƒ } n  | rŸt | d ƒ n d  } zD t j | | ƒ  d | d | d |	 d | pØ|  j d | d | ƒWd  | rÿ| j ƒ  n  XWn/ t k
 r2} | r‚  n  t d | ƒ ‚ n Xd  S(   NR   R   R   R   R!   t	   tracebackR   R   R   R    t   ,i    s,   You can only use --pks option with one modelc         3   s6   |  ], } | j  d  k	 r | ˆ  k r | d  f Vq d  S(   N(   t   models_moduleR#   (   t   .0t
   app_config(   t   excluded_apps(    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pys	   <genexpr>[   s    i   t   .s   Unknown model: %s.%ss    Unknown serialization format: %sc         3   s)  t  j ˆ  j ƒ  ƒ } x| D]} | ˆ k r4 q n  | j j rr | j j | k rr t j d | j j d t	 ƒn  | j j r t
 j ˆ | ƒ r ˆ r£ | j } n	 | j } | j ˆ ƒ j | j j j ƒ } ˆ rè | j d ˆ ƒ } n  |  r| j ƒ  j ƒ  Vq!x | j ƒ  D] } | VqWq q Wd S(   s•   
            Collate the objects to be serialized. If count_only is True, just
            count the number of objects to be serialized.
            s,   %s is a proxy model and won't be serialized.t   categoryt   pk__inN(   R   t   sort_dependenciest   itemst   _metat   proxyt   proxy_for_modelt   warningst   warnt   labelR   R   t   allow_migrate_modelt   _base_managert   _default_managert   usingt   order_byt   pkt   namet   filtert   countt   iterator(   t
   count_onlyt   modelst   modelt   objectst   querysett   obj(   t   app_listt   excluded_modelsR    R   R=   (    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyt   get_objects   s&    
	!t	   verbosityRD   t   wt   streamt   progress_outputt   object_counts    Unable to serialize database: %s(   t   splitt   stripR   t   lenR   R    R   t   get_app_configst   get_app_configt   LookupErrort   strR+   R#   t	   get_modelt
   setdefaultR   t
   ValueErrorR   t   get_public_serializer_formatst   get_serializert   SerializerDoesNotExistR%   t   stdoutt   endingt   isattyt   sumt   Truet   opent	   serializet   closet	   Exception(   R&   t
   app_labelst   optionsR   R   t   excludesR!   t   show_tracebackR   R   t   pksR?   R9   t	   app_labelt   model_labelR-   t   eRF   t   app_list_valueRL   RP   RQ   RO   (    (   RJ   R.   RK   R    R   R=   sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyt   handleD   sœ    









+"	%	(   R	   R
   R   R(   Rq   (    (    (    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyR      s   	/(   R7   t   collectionsR    t   django.appsR   t   django.coreR   t   django.core.management.baseR   R   t   django.core.management.utilsR   t	   django.dbR   R   t   WarningR   R   (    (    (    sJ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/dumpdata.pyt   <module>   s   