ó
ø¢TQc           @  sZ  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m 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 m Z m Z 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  y d  d l! Z! e" Z# Wn e$ k
 r?e% Z# n Xd e f d „  ƒ  YZ& d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   make_option(   t   settings(   t   serializers(   t   BaseCommandt   CommandError(   t   no_style(   t   connectionst   routert   transactiont   DEFAULT_DB_ALIASt   IntegrityErrort   DatabaseError(   t   get_apps(   t
   force_text(   t   upath(   t   productt   Commandc           B  so   e  Z d  Z d Z e j e d d d d d d e d d	 ƒe d
 d d d d d d e d d ƒf Z d „  Z	 RS(   u.   Installs the named fixture(s) in the database.u   fixture [fixture ...]u
   --databaset   actionu   storet   destu   databaset   defaultt   helpuX   Nominates a specific database to load fixtures into. Defaults to the "default" database.u   --ignorenonexistentu   -iu
   store_trueu   ignoreu[   Ignores entries in the serialized data for fields that do not currently exist on the model.c   .      O  s  | j  d ƒ } | j  d ƒ } t | } t | ƒ sC t d ƒ ‚ n  t | j  d ƒ ƒ } | j  d ƒ } | j  d t ƒ } d }	 d }
 d } t ƒ  } d „  } | j ƒ  } | rå t j	 d	 | ƒ t j
 d	 | ƒ t j t d	 | ƒn  d
 t j f d „  ƒ  Y} i t d  6t j d 6| d 6} t r2t j | d <n  g  } x` t ƒ  D]U } t | d ƒ rx= | j D] } | j t | ƒ ƒ qaWqB| j t | j ƒ ƒ qBWg  | D]' } t j j t j j | ƒ d ƒ ^ q¢} yî| j ƒ  €xx| D]p} | j  d ƒ } t | ƒ d k r7| d | k r7| d g } | d  } n | j! ƒ  } t | ƒ d k rn| d } t" j# ƒ  } nB d j | d  ƒ | d } } | t" j# ƒ  k rª| g } n g  } | rÜ| d k rò|  j$ j% d | ƒ qòn t d | | f ƒ ‚ t j j& | ƒ r| g } n | t' t( j) ƒ d g } x)| D]!} | d k r`|  j$ j% d | | ƒ ƒ n  t* } xét+ | d  g | | ƒ D]Ï} | \ } } }  d j d „  | | | |  g Dƒ ƒ }! | d k rë|  j$ j% d | | ƒ |! | f ƒ n  t j j | |! ƒ }" | |  }# y |# |" d ƒ }$ WnC t, k
 rb| d k rN|  j$ j% d | | | | ƒ f ƒ qNqXz¾yy| rŽt d | | | ƒ f ƒ ‚ n  |	 d 7}	 d }% d }& | d k rÖ|  j$ j% d | | | | ƒ f ƒ n  t" j- | |$ d	 | d  | ƒ}' xÍ |' D]Å }( |% d 7}% t. j/ | |( j0 j1 ƒ rû|& d 7}& | j2 |( j0 j1 ƒ y |( j3 d	 | ƒ WqÀt4 t5 f k
 r¼}) d! i |( j0 j6 j7 d" 6|( j0 j6 j8 d# 6|( j0 j9 d$ 6t: |) ƒ d% 6f |) _; ‚  qÀXqûqûW|
 |& 7}
 | |% 7} t } Wn> t< k
 r}) t= |) t ƒ sd& |" |) f f |) _; n  ‚  n XWd  |$ j> ƒ  X|% d k rt d' | ƒ ‚ qqWq1WqæWWd  QXg  | D] }* |* j6 j? ^ qg}+ y | j@ d( |+ ƒ Wn& t< k
 r»}) d) |) f |) _; ‚  n XWnX tA tB f k
 rÙ‚  n? t< k
 r}) | rt jC d	 | ƒ t jD d	 | ƒ n  ‚  n X|
 d k r…| jE jF tG ƒ  | ƒ }, |, r…| d k ra|  j$ j% d* ƒ n  x |, D] }- | jH |- ƒ qhWq…n  | r®t jI d	 | ƒ t jD d	 | ƒ n  | d k r| |
 k rã|  j$ j% d+ |
 |	 f ƒ q|  j$ j% d, |
 | |	 f ƒ n  | r| j> ƒ  n  d  S(-   Nu   ignoreu   databaseuc   No database fixture specified. Please provide the path of at least one fixture in the command line.u	   verbosityu	   tracebacku   commiti    c         S  s   |  r d |  Sd S(   Nu   '%s'u   absolute path(    (   t   dirname(    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyt   <lambda>G   s    t   usingt   SingleZipReaderc           B  s   e  Z d  „  Z d „  Z RS(   c         _  sJ   t  j j |  | | Ž t j rF t |  j ƒ  ƒ d k sF t d ƒ ‚ n  d  S(   Ni   u3   Zip-compressed fixtures must contain only one file.(   t   zipfilet   ZipFilet   __init__R   t   DEBUGt   lent   namelistt   AssertionError(   t   selft   argst   kwargs(    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyR   V   s    	c         S  s   t  j j |  |  j ƒ  d ƒ S(   Ni    (   R   R   t   readR   (   R!   (    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyR$   Z   s    (   t   __name__t
   __module__R   R$   (    (    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyR   U   s   	u   gzu   zipu   bz2u   __path__u   fixturesu   .i   iÿÿÿÿi   u   Loading '%s' fixtures...uH   Problem installing fixture '%s': %s is not a known serialization format.u    u   Checking %s for fixtures...c         s  s   |  ] } | r | Vq d  S(   N(    (   t   .0t   p(    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pys	   <genexpr>›   s    i   u    Trying %s for %s fixture '%s'...u   ru   No %s fixture '%s' in %s.u-   Multiple fixtures named '%s' in %s. Aborting.u#   Installing %s fixture '%s' from %s.t   ignorenonexistentuF   Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)su	   app_labelu   object_nameu   pku	   error_msgu#   Problem installing fixture '%s': %su=   No fixture data found for '%s'. (File format may be invalid.)t   table_namesu   Problem installing fixtures: %su   Resetting sequences
u)   Installed %d object(s) from %d fixture(s)u1   Installed %d object(s) (of %d) from %d fixture(s)(J   t   getR   R   R   t   intt   Truet   sett   cursorR	   t   commit_unless_managedt   enter_transaction_managementt   managedR   R   t   opent   Nonet   gzipt   GzipFilet   has_bz2t   bz2t   BZ2FileR   t   hasattrt   __path__t   appendR   t   __file__t   ost   patht   joinR   t   constraint_checks_disabledt   splitt   keysR   t   get_public_serializer_formatst   stdoutt   writet   isabst   listR   t   FIXTURE_DIRSt   FalseR   t   IOErrort   deserializeR   t   allow_syncdbt   objectt	   __class__t   addt   saveR   R   t   _metat	   app_labelt   object_namet   pkR   R"   t	   Exceptiont
   isinstancet   closet   db_tablet   check_constraintst
   SystemExitt   KeyboardInterruptt   rollbackt   leave_transaction_managementt   opst   sequence_reset_sqlR   t   executet   commit(.   R!   t   fixture_labelst   optionst   ignoreR   t
   connectiont	   verbosityt   show_tracebackRb   t   fixture_countt   loaded_object_countt   fixture_object_countt   modelst   humanizeR/   R   t   compression_typest   app_module_pathst   appR?   t   app_fixturest   fixture_labelt   partst   compression_formatst   fixture_namet   formatst   formatt   fixture_dirst   fixture_dirt   label_foundt   combot   databaset   compression_formatt	   file_namet	   full_patht   open_methodt   fixturet   objects_in_fixturet   loaded_objects_in_fixturet   objectst   objt   et   modelR*   t   sequence_sqlt   line(    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyt   handle)   s$   
		

4"

 





(
   R%   R&   R   R"   R   t   option_listR   R
   RJ   RŠ   (    (    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyR      s   ('   t
   __future__R    t   sysR>   R5   R   t   optparseR   t	   tracebackt   django.confR   t   django.coreR   t   django.core.management.baseR   R   t   django.core.management.colorR   t	   django.dbR   R   R	   R
   R   R   t   django.db.modelsR   t   django.utils.encodingR   t   django.utils._osR   t	   itertoolsR   R8   R-   R7   t   ImportErrorRJ   R   (    (    (    sA   ../Django//lib/python/django/core/management/commands/loaddata.pyt   <module>   s*   .

