ó
i4Vdc           @  s¬  d  d l  m Z d  d l 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	 m
 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 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$ d  d l% m& Z& y d  d l' Z' e( Z) Wn e* k
 roe+ Z) n Xd e f d „  ƒ  YZ, d e j- f d „  ƒ  YZ. d „  Z/ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   product(   t   apps(   t   settings(   t   serializers(   t   ImproperlyConfigured(   t   BaseCommandt   CommandError(   t   no_style(   t   DEFAULT_DB_ALIASt   DatabaseErrort   IntegrityErrort   connectionst   routert   transaction(   t	   lru_cache(   t   upath(   t
   force_text(   t   cached_property(   t   glob_escapet   Commandc           B  sk   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z e j d d
 ƒ d „  ƒ Z
 e d „  ƒ Z d	 „  Z RS(   u.   Installs the named fixture(s) in the database.uc   No database fixture specified. Please provide the path of at least one fixture in the command line.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 d  d d ƒ| j  d d d	 d d d d t d d ƒd  S(   Nu   argst   metavaru   fixturet   nargsu   +t   helpu   Fixture labels.u
   --databaset   actionu   storet   destu   databaset   defaultuX   Nominates a specific database to load fixtures into. Defaults to the "default" database.u   --appu	   app_labelu,   Only look for fixtures in the specified app.u   --ignorenonexistentu   -iu
   store_trueu   ignoreu[   Ignores entries in the serialized data for fields that do not currently exist on the model.(   t   add_argumentR	   t   Nonet   False(   t   selft   parser(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyt   add_arguments&   s    c         O  s°   | j  d ƒ |  _ | j  d ƒ |  _ | j  d ƒ |  _ | j  d t ƒ |  _ | j  d ƒ |  _ t j d |  j ƒ  |  j	 | ƒ Wd  QXt j
 |  j ƒ r¬ t |  j j ƒ  n  d  S(   Nu   ignoreu   databaseu	   app_labelu
   hide_emptyu	   verbosityt   using(   t   gett   ignoreR!   t	   app_labelR   t
   hide_emptyt	   verbosityR   t   atomict   loaddatat   get_autocommitR   t   close(   R   t   fixture_labelst   options(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyt   handle3   s    c   
      C  sd  t  |  j } d |  _ d |  _ d |  _ t ƒ  |  _ t j ƒ  |  _	 i t
 d f d  6t j d f d 6t d f d 6|  _ t r• t j d f |  j d <n  x% | D] } |  j | ƒ rœ Pqœ qœ Wd  S| j ƒ  # x | D] } |  j | ƒ qÑ WWd  QXg  |  j D] } | j j ^ qø } y | j d | ƒ Wn& t k
 rL} d | f | _ ‚  n X|  j d k rØ| j j t ƒ  |  j ƒ } | rØ|  j d	 k rŸ|  j j  d
 ƒ n  | j! ƒ  % } x | D] }	 | j" |	 ƒ qµWWd  QXqØn  |  j d k r`|  j d k r|  j# rq`|  j |  j k r7|  j j  d |  j |  j f ƒ q`|  j j  d |  j |  j |  j f ƒ n  d  S(   Ni    u   rbu   gzu   ru   zipu   bz2t   table_namesu   Problem installing fixtures: %si   u   Resetting sequences
i   u)   Installed %d object(s) from %d fixture(s)u1   Installed %d object(s) (of %d) from %d fixture(s)($   R   R!   t   fixture_countt   loaded_object_countt   fixture_object_countt   sett   modelsR   t   get_public_serializer_formatst   serialization_formatst   openR   t   gzipt   GzipFilet   SingleZipReadert   compression_formatst   has_bz2t   bz2t   BZ2Filet   find_fixturest   constraint_checks_disabledt
   load_labelt   _metat   db_tablet   check_constraintst	   Exceptiont   argst   opst   sequence_reset_sqlR   R&   t   stdoutt   writet   cursort   executeR%   (
   R   R+   t
   connectiont   fixture_labelt   modelR.   t   et   sequence_sqlRJ   t   line(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR(   E   sR    			"c         C  s£  |  j  d k } x|  j | ƒ D]|\ } } } |  j t j j | ƒ ƒ \ } } } |  j | \ }	 }
 |	 | |
 ƒ } zöy±|  j d 7_ d } d } |  j  d k rÊ |  j j	 d | | t
 | ƒ f ƒ n  t j | | d |  j d |  j ƒ} xù | D]ñ } | d 7} t j |  j | j j ƒ rõ | d 7} |  j j | j j ƒ y: | j d |  j ƒ | ry|  j j	 d | d	 d
 ƒn  Wqæt t f k
 râ} d i | j j j d 6| j j j d 6| j j d 6t | ƒ d 6f | _ ‚  qæXqõ qõ W| r	| r	|  j j	 d
 ƒ n  |  j | 7_ |  j | 7_ Wn> t  k
 rh} t! | t" ƒ sbd | | f f | _ n  ‚  n XWd | j# ƒ  X| d k r t$ j% d | t& ƒ q q Wd S(   u9   
        Loads fixtures files for a given label.
        i   i   i    i   u#   Installing %s fixture '%s' from %s.R!   t   ignorenonexistentu   Processed %i object(s).t   endingu    uF   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': %sNu=   No fixture data found for '%s'. (File format may be invalid.)('   R&   R>   t
   parse_namet   ost   patht   basenameR:   R/   RH   RI   t   humanizeR   t   deserializeR!   R#   R   t   allow_migrate_modelt   objectt	   __class__R3   t   addt   saveR
   R   RA   R$   t   object_namet   pkR   RE   R0   R1   RD   t
   isinstanceR   R*   t   warningst   warnt   RuntimeWarning(   R   RM   t   show_progresst   fixture_filet   fixture_dirt   fixture_namet   _t   ser_fmtt   cmp_fmtt   open_methodt   modet   fixturet   objects_in_fixturet   loaded_objects_in_fixturet   objectst   objRO   (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR@   „   s^    $ 

	
t   maxsizec           sÄ  |  j  | ƒ \ ‰  } } |  j d g } | d k rH t |  j j ƒ  ƒ n | g } | d k ri t j ƒ  n | g } |  j d k r˜ |  j	 j
 d ˆ  ƒ n  t j j ˆ  ƒ rÔ t j j ˆ  ƒ g } t j j ˆ  ƒ ‰  np |  j } t j j t j j ˆ  ƒ k rDg  | D]' } t j j | t j j ˆ  ƒ ƒ ^ q} t j j ˆ  ƒ ‰  n  d „  t | | | ƒ Dƒ }	 t ‡  f d †  |	 Dƒ ƒ }
 g  } x!| D]} |  j d k r»|  j	 j
 d t | ƒ ƒ n  g  } t j j | ˆ  ƒ } xR t j t | ƒ d ƒ D]7 } t j j | ƒ |
 k rð| j | | ˆ  f ƒ qðqðW|  j d k rd| rd|  j	 j
 d ˆ  t | ƒ f ƒ n  t | ƒ d k r•t d	 ˆ  t | ƒ f ƒ ‚ n  | j | ƒ q‰W| sÀt j d
 ˆ  ƒ n  | S(   u8   
        Finds fixture files for a given label.
        i   u   Loading '%s' fixtures...c         s  s(   |  ] } d  j  d „  | Dƒ ƒ Vq d S(   u   .c         s  s   |  ] } | r | Vq d  S(   N(    (   t   .0t   ext(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pys	   <genexpr>Ö   s    N(   t   join(   Rt   t   combo(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pys	   <genexpr>Ö   s   c         3  s$   |  ] } d  j  ˆ  | f ƒ Vq d S(   u   .N(   Rv   (   Rt   t   suffix(   Rh   (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pys	   <genexpr>Ø   s    u   Checking %s for fixtures...u   *u   No fixture '%s' in %s.i   u-   Multiple fixtures named '%s' in %s. Aborting.u   No fixture named '%s' found.N(    RT   R!   R   t   listR:   t   keysR   R4   R&   RH   RI   RU   RV   t   isabst   dirnameRW   t   fixture_dirst   sept   normpathRv   R   R2   RX   t   globt   iglobR   t   appendt   lenR   t   extendRb   Rc   (   R   RM   Rj   Rk   t	   databasest   cmp_fmtst   ser_fmtsR}   t   dir_t   suffixest   targetst   fixture_filesRg   t   fixture_files_in_dirRV   t	   candidate(    (   Rh   sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR>   ¿   sJ    *!	1 c         C  s4  g  } t  j } t | ƒ t t | ƒ ƒ k r< t d ƒ ‚ n  xš t j ƒ  D]Œ } | j } t j	 j
 | j	 d ƒ } | | k r• t d | | f ƒ ‚ n  |  j r³ | |  j k r³ qI n  t j	 j | ƒ rI | j | ƒ qI qI W| j t | ƒ ƒ | j d ƒ g  | D]* } t t j	 j t j	 j | ƒ ƒ ƒ ^ q } | S(   uç   
        Return a list of fixture directories.

        The list contains the 'fixtures' subdirectory of each installed
        application, if it exists, the directories in FIXTURE_DIRS, and the
        current directory.
        u*   settings.FIXTURE_DIRS contains duplicates.u   fixturesuc   '%s' is a default fixture directory for the '%s' app and cannot be listed in settings.FIXTURE_DIRS.u    (   R   t   FIXTURE_DIRSRƒ   R2   R   R   t   get_app_configst   labelRU   RV   Rv   R$   t   isdirR‚   R„   Ry   R   t   abspatht   realpath(   R   t   dirsR}   t
   app_configR$   t   app_dirt   d(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR}   ÷   s&    			7c         C  sÜ   | j  d d ƒ } t | ƒ d k rN | d |  j k rN | d } | d  } n d } t | ƒ d k rº | d |  j k r | d } | d  } qÀ t d d j | d  ƒ | d f ƒ ‚ n d } d j | ƒ } | | | f S(   uX   
        Splits fixture name in name, serialization format, compression format.
        u   .i   i   iÿÿÿÿuH   Problem installing fixture '%s': %s is not a known serialization format.u    N(   t   rsplitRƒ   R:   R   R5   R   Rv   (   R   Rh   t   partsRk   Rj   t   name(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyRT     s    %

$N(   t   __name__t
   __module__R   t   missing_args_messageR    R-   R(   R@   R   R   R>   R   R}   RT   (    (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR   !   s   			?	;8R9   c           B  s   e  Z d  „  Z d „  Z RS(   c         O  sA   t  j j |  | | Ž t |  j ƒ  ƒ d k r= t d ƒ ‚ n  d  S(   Ni   u.   Zip-compressed fixtures must contain one file.(   t   zipfilet   ZipFilet   __init__Rƒ   t   namelistt
   ValueError(   R   RE   t   kwargs(    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR    4  s    c         C  s   t  j j |  |  j ƒ  d ƒ S(   Ni    (   Rž   RŸ   t   readR¡   (   R   (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR¤   9  s    (   R›   Rœ   R    R¤   (    (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyR9   2  s   	c         C  s   |  r d |  Sd S(   Nu   '%s'u   absolute path(    (   R|   (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyRX   =  s    (0   t
   __future__R    R€   R7   RU   Rb   Rž   t	   itertoolsR   t   django.appsR   t   django.confR   t   django.coreR   t   django.core.exceptionsR   t   django.core.management.baseR   R   t   django.core.management.colorR   t	   django.dbR	   R
   R   R   R   R   t   django.utilsR   t   django.utils._osR   t   django.utils.encodingR   t   django.utils.functionalR   t   django.utils.globR   R<   t   TrueR;   t   ImportErrorR   R   RŸ   R9   RX   (    (    (    sv   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.pyt   <module>   s6   .

ÿ 