ó
TRšNc           @   s¸   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 m Z d  d l m Z d  d l m Z m Z d  d l m Z d	 e f d
     YZ d S(   i˙˙˙˙(   t   make_option(   t   settings(   t   connectionst   transactiont   modelst   DEFAULT_DB_ALIAS(   t   call_command(   t   NoArgsCommandt   CommandError(   t   no_style(   t	   sql_flusht   emit_post_sync_signal(   t   import_modulet   Commandc           B   sf   e  Z e j e d  d d d d d e d d e d d d	 d d
 d e d d f Z d Z d   Z RS(   s	   --noinputt   actiont   store_falset   destt   interactivet   defaultt   helps:   Tells Django to NOT prompt the user for input of any kind.s
   --databaset   storet   databasesB   Nominates a database to flush. Defaults to the "default" database.s.   Executes ``sqlflush`` on the current database.c         K   s  | j  d t  } t | } t | j  d d   } | j  d  } t   |  _ x6 t j D]+ } y t d |  WqY t	 k
 r qY XqY Wt
 |  j | d t } | rŔ t d | j d  } n d	 } | d	 k ry. | j   }	 x | D] }
 |	 j |
  qč WWn@ t k
 rB} t j d
 |  t d | j d | f   n Xt j d
 |  t t j   | | |  | j   } | | d <t d d |  n d GHd  S(   NR   t	   verbosityi   R   s   .managementt   only_djangos˙   You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the %r database,
and return each table to the state it was in after syncdb.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: t   NAMEt   yest   usingsD  Database %s couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: %st   loaddatat   initial_datas   Flush cancelled.(   t   getR   R   t   intR	   t   styleR   t   INSTALLED_APPSR   t   ImportErrorR
   t   Truet	   raw_inputt   settings_dictt   cursort   executet	   ExceptionR   t   rollback_unless_managedR   t   commit_unless_managedR   R   t
   get_modelst   copyR   (   t   selft   optionst   dbt
   connectionR   R   t   app_namet   sql_listt   confirmR%   t   sqlt   et   kwargs(    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/flush.pyt   handle_noargs   s<    

(	   t   __name__t
   __module__R   t   option_listR    R"   R   R   R6   (    (    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/flush.pyR      s   N(   t   optparseR    t   django.confR   t	   django.dbR   R   R   R   t   django.core.managementR   t   django.core.management.baseR   R   t   django.core.management.colorR	   t   django.core.management.sqlR
   R   t   django.utils.importlibR   R   (    (    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/flush.pyt   <module>   s   "