a
    ÆZEgÄ  ã                   @   sh   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ G dd„ deƒZdd	„ ZdS )
é    N)ÚList)Ú
AppCommand)Úcolor_style)Ú_make_writeableÚsignalcommandc                       sB   e Zd ZU dZg Zee ed< dZ‡ fdd„Z	e
dd„ ƒZ‡  ZS )ÚCommandzfCreates a Django management command directory structure for the given app name in the app's directory.Úrequires_system_checksTc                    sN   t ƒ  |¡ |jddddddd� |jdd	dd
ddd� |jddddd� d S )Nz--namez-nÚstoreÚcommand_nameÚsamplez*The name to use for the management command)ÚactionÚdestÚdefaultÚhelpz--basez-bÚbase_commandZBasezdThe base class used for implementation of this command. Should be one of Base, App, Label, or NoArgsz	--dry-runÚ
store_trueFz Do not actually create any files)r   r   r   )ÚsuperÚadd_argumentsÚadd_argument)ÚselfÚparser©Ú	__class__© úm/var/www/sistema_ama/venv/lib/python3.9/site-packages/django_extensions/management/commands/create_command.pyr      s    ýþþzCommand.add_argumentsc                 K   s   |}t d|jfi |¤Ž d S )NZcommand_template)Úcopy_templateÚpath)r   ÚargsÚoptionsZappr   r   r   Úhandle_app_config&   s    zCommand.handle_app_config)Ú__name__Ú
__module__Ú__qualname__r   r   r   ÚstrÚ__annotations__Zcan_import_settingsr   r   r   Ú__classcell__r   r   r   r   r      s   
r   c                 K   sn  ddl }tƒ }t|ddd„ ƒ}t|ddd„ ƒ}|d d	|d
   }}|d }	|d }
tj |jd d| ¡}t |¡D �]ò\}}}|t|ƒd d… }|rÆtj 	tj ||¡¡sÆ|	sÆt 
tj ||¡¡ t|ƒD ]\}}| d¡rÎ||= qÎ|D �]x}| d¡sì| d¡�r
qìtj ||¡}tj ||| d|¡¡ d¡}tj 	|¡�r‚tj |||¡ d¡}tj 	|¡�r‚|
dkrìt|d| ƒƒ qì|
dk�rœt|d| ƒƒ t|dƒ�l}| ¡ }| d|¡}| d|¡}|	�st|dƒ�}| |¡ W d  ƒ n1 �sú0    Y  W d  ƒ n1 �s0    Y  |	sìzt ||¡ t|ƒ W qì t�yd   tj d| ¡ Y qì0 qìqtdS )z=Copy the specified template directory to the copy_to locationr   NÚERRORc                 S   s   | S ©Nr   ©Úxr   r   r   Ú<lambda>1   ó    zcopy_template.<locals>.<lambda>ÚSUCCESSc                 S   s   | S r'   r   r(   r   r   r   r*   2   r+   r
   z	%sCommandr   Údry_runÚ	verbosityÚconfé   Ú.)z.pycz.pyo)z	.DS_StoreÚ__pycache__r   z.tmplz%s already existsz%sÚrz{{ command_name }}z{{ base_command }}ÚwzlNotice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.
)Údjango_extensionsr   ÚgetattrÚosr   ÚjoinÚ__path__ÚwalkÚlenÚexistsÚmkdirÚ	enumerateÚ
startswithÚendswithÚreplaceÚrstripÚprintÚopenÚreadÚwriteÚshutilÚcopymoder   ÚOSErrorÚsysÚstderr)Ztemplate_nameZcopy_tor   r5   Ústyler&   r,   r
   r   r-   r.   Ztemplate_dirÚdÚsubdirsÚfilesZrelative_dirÚiÚsubdirÚfZpath_oldZpath_newZfp_origÚdataZfp_newr   r   r   r   ,   sT    


Jr   )r7   rJ   rG   Útypingr   Zdjango.core.management.baser   Zdjango.core.management.colorr   Z"django_extensions.management.utilsr   r   r   r   r   r   r   r   Ú<module>   s   