ó
TRšNc           @   s   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
 d  d l m Z m Z m Z d e f d     YZ d	 S(
   i˙˙˙˙(   t   make_option(   t   settings(   t
   AppCommandt   CommandError(   t   no_style(   t	   sql_reset(   t   connectionst   transactiont   DEFAULT_DB_ALIASt   Commandc           B   sr   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 e 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 reset. Defaults to the "default" database.sC   Executes ``sqlreset`` for the given app(s) in the current database.s   [appname ...]c         K   s  | j  d t  } t | } | j j d  d } t   |  _ t | |  j |  } | j  d  r t d | | j	 d f  } n d } | d k ry. | j
   } x | D] }	 | j |	  qŞ WWn6 t k
 rú }
 t j   t d | | |
 f   n Xt j   n d	 GHd  S(
   NR   t   .iţ˙˙˙R   sË   
You have requested a database reset.
This will IRREVERSIBLY DESTROY any data for
the "%s" application in the database "%s".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: t   NAMEt   yess:  Error: %s couldn't be reset. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run.
The full error: %ss   Reset cancelled.(   t   getR   R   t   __name__t   splitR   t   styleR   t	   raw_inputt   settings_dictt   cursort   executet	   ExceptionR   t   rollback_unless_managedR   t   commit_unless_managed(   t   selft   appt   optionst   usingt
   connectiont   app_namet   sql_listt   confirmR   t   sqlt   e(    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/reset.pyt
   handle_app   s(    

(   R   t
   __module__R   t   option_listR    t   TrueR   R   t   argst   output_transactionR*   (    (    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/reset.pyR	   	   s   N(   t   optparseR    t   django.confR   t   django.core.management.baseR   R   t   django.core.management.colorR   t   django.core.management.sqlR   t	   django.dbR   R   R   R	   (    (    (    sR   /home/panlixing/Python_Projects/gaeseries/django/core/management/commands/reset.pyt   <module>   s   