ó
TR¹Nc           @   s  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 d  d l m Z d  d l m Z m Z m Z 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ÿÿÿÿN(   t   make_option(   t   settings(   t   serializers(   t   BaseCommand(   t   no_style(   t   connectionst   routert   transactiont   DEFAULT_DB_ALIAS(   t   get_apps(   t   productt   Commandc           B   sK   e  Z d  Z d Z e j e d d d d d d e d d	 ƒf Z d
 „  Z RS(   s.   Installs the named fixture(s) in the database.s   fixture [fixture ...]s
   --databaset   actiont   storet   destt   databaset   defaultt   helpsX   Nominates a specific database to load fixtures into. Defaults to the "default" database.c   *      O   sN  | j  d t ƒ } t | } t ƒ  |  _ t | j  d d ƒ ƒ } | j  d t ƒ } | j  d t ƒ } 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 rt j | d <n  g  } xT t ƒ  D]I } t | d ƒ r`x1 | j D] } | j | ƒ qFWq'| j | j ƒ q'Wg  | D]' } t j j t j j | ƒ d ƒ ^ q{} xÀ| D]¸} | j  d ƒ } t! | ƒ d k r | d | k r | d g } | d  } n | j" ƒ  } t! | ƒ d k r7| d } t# j$ ƒ  } nB d j | d  ƒ | d } } | t# j$ ƒ  k rs| g } n g  } | rš| d k räd | GHqänJ t% j& j' |  j j( d | | f ƒ ƒ t
 j) d | ƒ t
 j* d | ƒ d  St j j+ | ƒ r| g } n | t, t- j. ƒ d g } xH| D]@} | d k rGd | | ƒ GHn  t } xt/ | d  g | | ƒ D]ù} | \ } } } d j d „  | | | | g Dƒ ƒ } | d k rÇd | | ƒ | | f GHn  t j j | | ƒ }  | | }! y<|! |  d ƒ }" | rM|" j0 ƒ  |  j j( d | | | ƒ f ƒ GHt
 j) d | ƒ t
 j* d | ƒ d  S| d 7} d }# | d k r„d | | | | ƒ f GHn  y… t# j1 | |" d | ƒ}$ xV |$ D]N }% t2 j3 | |% j4 j5 ƒ r¦|# d 7}# |
 j6 |% j4 j5 ƒ |% j7 d | ƒ q¦q¦W|	 |# 7}	 t } Wn» t8 t9 f k
 r%‚  n¢ t: k
 rÆd d  l; }& |" j0 ƒ  t
 j) d | ƒ t
 j* d | ƒ | r{|& j< ƒ  nG t% j& j' |  j j( d |  d j |& j= t% j> t% j? t% j@ ƒ ƒ f ƒ ƒ d  SX|" j0 ƒ  |# d k r!t% j& j' |  j j( d | ƒ ƒ t
 j) d | ƒ t
 j* d | ƒ d  SWqft: k
 r^}' | d k r_d | | | | ƒ f GHq_qfXqfWq#Wq¯W|	 d k rÍ| jA jB |  j |
 ƒ }( |( rÍ| d k r©d GHn  x |( D] }) | jC |) ƒ q°WqÍn  | röt
 jD d | ƒ t
 j* d | ƒ n  |	 d k r| d k r7d GHq7n | d k r7d  |	 | f GHn  | rJ| j0 ƒ  n  d  S(!   NR   t	   verbosityi   t	   tracebackt   commiti    c         S   s   |  r d |  p d S(   Ns   '%s's   absolute path(    (   t   dirname(    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyt   <lambda>5   s    t   usingt   SingleZipReaderc           B   s   e  Z d  „  Z d „  Z RS(   c         _   sG   t  j j |  | | Ž t j rC t |  j ƒ  ƒ d k sC t d ‚ n  d  S(   Ni   s3   Zip-compressed fixtures must contain only one file.(   t   zipfilet   ZipFilet   __init__R   t   DEBUGt   lent   namelistt   AssertionError(   t   selft   argst   kwargs(    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyR   D   s    	c         S   s   t  j j |  |  j ƒ  d ƒ S(   Ni    (   R   R   t   readR   (   R    (    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyR#   H   s    (   t   __name__t
   __module__R   R#   (    (    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyR   C   s   	t   gzt   zipt   bz2t   __path__t   fixturest   .iÿÿÿÿs   Loading '%s' fixtures...sH   Problem installing fixture '%s': %s is not a known serialization format.t    s   Checking %s for fixtures...c         s   s   |  ] } | r | Vq d  S(   N(    (   t   .0t   p(    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pys	   <genexpr>‰   s    s    Trying %s for %s fixture '%s'...t   rs-   Multiple fixtures named '%s' in %s. Aborting.s#   Installing %s fixture '%s' from %s.s$   Problem installing fixture '%s': %s
s=   No fixture data found for '%s'. (File format may be invalid.)s   No %s fixture '%s' in %s.s   Resetting sequencess   No fixtures found.s)   Installed %d object(s) from %d fixture(s)(E   t   getR   R   R   t   stylet   intt   Falset   Truet   sett   cursorR   t   commit_unless_managedt   enter_transaction_managementt   managedR   R   t   filet   Nonet   gzipt   GzipFilet   has_bz2R(   t   BZ2FileR	   t   hasattrR)   t   appendt   __file__t   ost   patht   joinR   t   splitR   t   keysR   t   get_public_serializer_formatst   syst   stderrt   writet   ERRORt   rollbackt   leave_transaction_managementt   isabst   listR   t   FIXTURE_DIRSR
   t   closet   deserializeR   t   allow_syncdbt   objectt	   __class__t   addt   savet
   SystemExitt   KeyboardInterruptt	   ExceptionR   t	   print_exct   format_exceptiont   exc_typet	   exc_valuet   exc_tracebackt   opst   sequence_reset_sqlt   executeR   (*   R    t   fixture_labelst   optionsR   t
   connectionR   t   show_tracebackR   t   fixture_countt   object_countt   modelst   humanizeR6   R   t   compression_typest   app_module_pathst   appRD   t   app_fixturest   fixture_labelt   partst   compression_formatst   fixture_namet   formatst   formatt   fixture_dirst   fixture_dirt   label_foundt   comboR   t   compression_formatt	   file_namet	   full_patht   open_methodt   fixturet   objects_in_fixturet   objectst   objR   t   et   sequence_sqlt   line(    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyt   handle   s   
		

4"
	






	
	((	   R$   R%   R   R!   R   t   option_listR    R   R…   (    (    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyR      s   (   RI   RC   R<   R   t   optparseR    t   django.confR   t   django.coreR   t   django.core.management.baseR   t   django.core.management.colorR   t	   django.dbR   R   R   R   t   django.db.modelsR	   t   django.utils.itercompatR
   R(   R4   R>   t   ImportErrorR3   R   (    (    (    sU   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/loaddata.pyt   <module>   s"   "

