ó
¸9^c           @   s   d  d l  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 d  d l m Z d e f d	     YZ d S(
   i˙˙˙˙N(   t   settings(   t   BaseCommandt   CommandError(   t   TEST_DATABASE_PREFIX(   t   input(   t   parse_mysql_cnf(   t   signalcommandt   Commandc           B   s&   e  Z d  Z d   Z e d    Z RS(   s%   Drops test database for this project.c         C   sß   t  t |   j |  | j d d d d d d t d d | j d	 d
 d d d d d d  d d | j d d d d d d d d  d d | j d d d d d d d d  d d | j d d d d d d d d d d d  S(   Ns	   --noinputt   actiont   store_falset   destt   interactivet   defaultt   helps:   Tells Django to NOT prompt the user for input of any kind.s   -Us   --usert   storet   users=   Use another user for the database then defined in settings.pys   -Ps
   --passwordt   passwordsA   Use another password for the database then defined in settings.pys   -Ds   --dbnamet   dbnames5   Use another database name then defined in settings.pys   -Rs   --routert   routers:   Use this router-database other then defined in settings.py(   t   superR   t   add_argumentst   add_argumentt   Truet   None(   t   selft   parser(    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/drop_test_database.pyR      s     c         O   s  | d } t  j j |  } | d k r; t d |   n  | j d  j d  d } d } } } }	 }
 | d k r t |  \ } } } }	 }
 n  | d pł | j d	  pł | } | d
 pŇ | j d  pŇ | } y | d d } Wn t k
 r d } n X| d k r-t | d p&| j d  } n  | d k sE| d k rTt d   n  | j d  pf|	 }	 | j d  p{|
 }
 | d } | d r¨t	 d | f  } n d } | d k rĂd GHd S| d. k r*d d l
 } y7 t j d |  | j j |  r| j |  n  Wqŕt k
 r&d SXnś| d/ k rÓd d l } i | d 6| d 6} |	 j d  rr|	 | d <n
 |	 | d <|
 rt |
  | d <n  | j |   } d  | } t j d! | d"  | j |  n| d0 k rĐd d l } i d& d' 6} | r| | d <n  | r| | d
 <n  |	 r1|	 | d <n  |
 rD|
 | d <n  | j |   } | j d(  | j   } d) | } t j d! | d"  y | j |  Wqŕ| j k
 rĚ} t j d* t |   d SXn t d+ |   | d, k sö| d rţd- GHn  d S(1   s$   Drop test database for this project.R   s   Unknown database router %st   ENGINEt   .i˙˙˙˙t    t   mysqlR   t   USERR   t   PASSWORDt   TESTt   NAMER   s?   You need to specify DATABASE_NAME in your Django settings file.t   HOSTt   PORTt	   verbosityR   sť   
You have requested to drop the test database.
This will IRREVERSIBLY DESTROY
ALL data in the database "%s".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: t   yess   Reset cancelled.Nt   sqlite3t
   spatialites   Unlinking %s databaset   passwdt   /t   unix_sockett   hostt   ports   DROP DATABASE IF EXISTS `%s`s   Executing: "t   "t
   postgresqlt   postgresql_psycopg2t   postgist	   template1t   databasei    s   DROP DATABASE IF EXISTS "%s";s	   Error: %ss   Unknown database engine %si   s   Reset successful.(   R&   R'   (   R   (   R.   R/   R0   (   R    t	   DATABASESt   getR   R   t   splitR   t   KeyErrorR   R   t   ost   loggingt   infot   patht   isfilet   unlinkt   OSErrort   MySQLdbt
   startswitht   intt   connectt   queryt   psycopg2t   set_isolation_levelt   cursort   executet   ProgrammingErrort	   exceptiont   str(   R   t   argst   optionsR   t   dbinfot   engineR   R   t   database_namet   database_hostt   database_portR$   t   confirmR7   t   Databaset   kwargst
   connectiont
   drop_queryt   conn_paramsRE   t   e(    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/drop_test_database.pyt   handle'   s    

 





(   t   __name__t
   __module__R   R   R   RX   (    (    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/drop_test_database.pyR      s   	(   R8   t   django.confR    t   django.core.management.baseR   R   t    django.db.backends.base.creationR   t	   six.movesR   t"   django_extensions.management.mysqlR   t"   django_extensions.management.utilsR   R   (    (    (    sZ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/drop_test_database.pyt   <module>   s   