î
à^Q\“  ã               @   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 Gd d „  d e ƒ Z	 d S)é    N)Úsettings)ÚBaseCommandÚCommandError)Úsignalcommandc                   sF   e  Z d  Z d Z d Z d Z ‡  f d d †  Z e d d „  ƒ Z ‡  S)ÚCommanda$  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> -WFTc                sj   t  t |  ƒ j | ƒ | j d d d d d d d d d d	 ƒ| j d
 d d d d d d d d d ƒd  S)Nz-Rz--routerÚactionÚstoreÚdestÚrouterÚdefaultÚhelpz:Use this router-database other then defined in settings.pyz-Dz--dropÚ
store_trueÚdropFzCIf given, includes commands to drop any existing user and database.)Úsuperr   Úadd_argumentsÚadd_argument)ÚselfÚparser)Ú	__class__© ú`/var/www/dbchiro/venv/build/django-extensions/django_extensions/management/commands/sqlcreate.pyr      s    zCommand.add_argumentsc             O   sÒ  | j  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 ƒ t
 d | ƒ t
 d | | |
 | f ƒ nÔ | d k ry| j  d ƒ r:t
 d | f ƒ t
 d | f ƒ n  t
 d | | f ƒ t
 d | | f ƒ t
 d | | f ƒ nU | d k r˜t j j	 d ƒ n6 t j j	 d | ƒ t
 d | ƒ t
 d | | f ƒ d  S)Nr
   zUnknown database router %sZENGINEÚ.é   ÚUSERZPASSWORDÚNAMEZHOSTÚ	localhostZmysqlz³-- 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.
z7CREATE DATABASE %s CHARACTER SET utf8 COLLATE utf8_bin;z=GRANT ALL PRIVILEGES ON %s.* to '%s'@'%s' identified by '%s';Ú
postgresqlÚpostgresql_psycopg2r   zDROP DATABASE IF EXISTS %s;zDROP USER IF EXISTS %s;z5CREATE USER %s WITH ENCRYPTED PASSWORD '%s' CREATEDB;z4CREATE DATABASE %s WITH ENCODING 'UTF-8' OWNER "%s";z*GRANT ALL PRIVILEGES ON DATABASE %s TO %s;Zsqlite3zG-- manage.py syncdb will automatically create a sqlite3 database file.
z6-- Don't know how to handle '%s' falling back to SQL.
zCREATE DATABASE %s;z)GRANT ALL PRIVILEGES ON DATABASE %s to %séÿÿÿÿ)r   r   )Úgetr   Z	DATABASESr   ÚsplitÚsocketÚgethostnameÚsysÚstderrÚwriteÚprint)r   ÚargsÚoptionsr
   ZdbinfoZengineZdbuserZdbpassZdbnameZdbhostZdbclientr   r   r   Úhandle   s<    		zCommand.handle)	Ú__name__Ú
__module__Ú__qualname__r   Zrequires_system_checksZcan_import_settingsr   r   r)   r   r   )r   r   r      s
   
r   )
r!   r#   Zdjango.confr   Zdjango.core.management.baser   r   Z"django_extensions.management.utilsr   r   r   r   r   r   Ú<module>   s
   