ó
¸9^c           @   sh   d  d l  Z  d  d l 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˙˙˙˙N(   t   settings(   t   BaseCommandt   CommandError(   t   signalcommandt   Commandc           B   s2   e  Z d  Z e Z e Z d   Z e d    Z	 RS(   s$  Generates the SQL to create your database for you, as specified in settings.py
The envisioned use case is something like this:

    ./manage.py sqlcreate [--router=<routername>] | mysql -u <db_administrator> -p
    ./manage.py sqlcreate [--router=<routername>] | psql -U <db_administrator> -Wc         C   sj   t  t |   j |  | j d d d d d d d d d d	 | j d
 d d d d d d t d d d  S(   Ns   -Rs   --routert   actiont   storet   destt   routert   defaultt   helps:   Use this router-database other then defined in settings.pys   -Ds   --dropt
   store_truet   dropsC   If given, includes commands to drop any existing user and database.(   t   superR   t   add_argumentst   add_argumentt   False(   t   selft   parser(    (    sQ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/sqlcreate.pyR      s    c         O   s  | d } t  j j |  } | d  k r; t d |   n  | j d  j d  d } | j d  } | j d  } | j d  } | j d	  }	 t j   }
 |	 sŽ d
 }	 n  | d k rë t j	 j
 d  d | GHd | | |
 | f GHnŹ | d k rL| d rd | f GHd | f GHn  d | | f GHd | | f GHd | | f GHnK | d k rkt j	 j
 d  n, t j	 j
 d |  d | GHd | | f GHd  S(   NR   s   Unknown database router %st   ENGINEt   .i˙˙˙˙t   USERt   PASSWORDt   NAMEt   HOSTt	   localhostt   mysqlsł   -- WARNING!: https://docs.djangoproject.com/en/dev/ref/databases/#collation-settings
-- Please read this carefully! Collation will be set to utf8_bin to have case-sensitive data.
s7   CREATE DATABASE %s CHARACTER SET utf8 COLLATE utf8_bin;s=   GRANT ALL PRIVILEGES ON %s.* to '%s'@'%s' identified by '%s';t
   postgresqlt   postgresql_psycopg2t   postgisR   s   DROP DATABASE IF EXISTS %s;s   DROP USER IF EXISTS %s;s5   CREATE USER %s WITH ENCRYPTED PASSWORD '%s' CREATEDB;s4   CREATE DATABASE %s WITH ENCODING 'UTF-8' OWNER "%s";s*   GRANT ALL PRIVILEGES ON DATABASE %s TO %s;t   sqlite3sG   -- manage.py syncdb will automatically create a sqlite3 database file.
s6   -- Don't know how to handle '%s' falling back to SQL.
s   CREATE DATABASE %s;s*   GRANT ALL PRIVILEGES ON DATABASE %s to %s;(   R   R   R   (   R    t	   DATABASESt   gett   NoneR   t   splitt   sockett   gethostnamet   syst   stderrt   write(   R   t   argst   optionsR   t   dbinfot   enginet   dbusert   dbpasst   dbnamet   dbhostt   dbclient(    (    sQ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/sqlcreate.pyt   handle    s<    
			
	(
   t   __name__t
   __module__R
   R   t   requires_system_checkst   Truet   can_import_settingsR   R   R1   (    (    (    sQ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/sqlcreate.pyR      s
   	(
   R#   R%   t   django.confR    t   django.core.management.baseR   R   t"   django_extensions.management.utilsR   R   (    (    (    sQ   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/sqlcreate.pyt   <module>   s
   