a
    Lcòf  ã                   @   sh   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
mZ d dlmZmZ G dd„ deƒZd	S )
é    )Úimport_module)Úapps)ÚBaseCommandÚCommandError)Úno_style)Úemit_post_migrate_signalÚ	sql_flush)ÚDEFAULT_DB_ALIASÚconnectionsc                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚCommandzuRemoves ALL DATA from the database, including data added during migrations. Does not achieve a "fresh install" state.)Úreset_sequencesÚallow_cascadeÚinhibit_post_migratec                 C   s(   |j dddddd� |j dtdd	� d S )
Nz	--noinputz
--no-inputÚstore_falseÚinteractivez:Tells Django to NOT prompt the user for input of any kind.)ÚactionÚdestÚhelpz
--databasezBNominates a database to flush. Defaults to the "default" database.)Údefaultr   )Úadd_argumentr	   )ÚselfÚparser© r   úb/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/management/commands/flush.pyÚadd_arguments   s    ûýzCommand.add_argumentsc              
   K   s.  |d }t | }|d }|d }| dd¡}| dd¡}| dd¡}tƒ | _t ¡ D ](}	ztd	|	jƒ W qT tyz   Y qT0 qTt	| j|||d
�}
|r¨t
d|jd  ƒ}nd}|dk�rz|j |
¡ W n< t�y } z"td|jd f ƒ|‚W Y d }~n
d }~0 0 |
�r*|�s*t|||ƒ n| j d¡ d S )NÚdatabaseÚ	verbosityr   r   Tr   Fr   z.management)r   r   zïYou have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the "%s" database,
and return each table to an empty state.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: ÚNAMEÚyesa.  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 sqlflush'. That's the SQL this command wasn't able to run.zFlush cancelled.)r
   Úgetr   Ústyler   Zget_app_configsr   ÚnameÚImportErrorr   ÚinputZsettings_dictÚopsZexecute_sql_flushÚ	Exceptionr   r   ÚstdoutÚwrite)r   Úoptionsr   Ú
connectionr   r   r   r   r   Z
app_configZsql_listZconfirmÚexcr   r   r   Úhandle   sP    üúÿ


úÿøzCommand.handleN)Ú__name__Ú
__module__Ú__qualname__r   Zstealth_optionsr   r+   r   r   r   r   r   
   s
   ÿr   N)Ú	importlibr   Zdjango.appsr   Zdjango.core.management.baser   r   Zdjango.core.management.colorr   Zdjango.core.management.sqlr   r   Z	django.dbr	   r
   r   r   r   r   r   Ú<module>   s   