o
    uvXj±  ã                   @   s\   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m	Z	 G dd„ deƒZ
dd„ ZdS )	é    N)Ú
AppCommand)Úcolor_style)Ú_make_writeableÚsignalcommandc                       s4   e Zd ZdZdZ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.FTc                    sR   t 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_commandÚ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   )Úsuperr   Úadd_argumentsÚadd_argument)ÚselfÚparser©Ú	__class__© úq/var/www/html/myproject/venv/lib/python3.10/site-packages/django_extensions/management/commands/create_command.pyr      s   ýþ
þzCommand.add_argumentsc                 K   s   |}t d|jfi |¤Ž d S )NÚcommand_template)Úcopy_templateÚpath)r   ÚargsÚoptionsÚappr   r   r   Úhandle_app_config%   s   zCommand.handle_app_config)
Ú__name__Ú
__module__Ú__qualname__r   Úrequires_system_checksÚcan_import_settingsr   r   r    Ú__classcell__r   r   r   r   r      s    r   c                 K   s`  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… }|rbtj 	tj ||¡¡sb|	sbt 
tj ||¡¡ t|ƒD ]\}}| d¡rr||= qf|D ]·}| d¡s�| d¡r‚qutj ||¡}tj ||| d|¡¡ d¡}tj 	|¡r¼tj |||¡ d¡}tj 	|¡r¼|
dkr»t|d| ƒƒ qu|
dkrÈt|d| ƒƒ t|dƒ�4}| ¡ }| d|¡}| d|¡}|	sút|dƒ�}| |¡ W d  ƒ n1 sõw   Y  W d  ƒ n	1 �sw   Y  |	�s,zt ||¡ t|ƒ W qu t�y+   tj d| ¡ Y quw quq:dS )z=Copy the specified template directory to the copy_to locationr   NÚERRORc                 S   ó   | S ©Nr   ©Úxr   r   r   Ú<lambda>0   ó    zcopy_template.<locals>.<lambda>ÚSUCCESSc                 S   r(   r)   r   r*   r   r   r   r,   1   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)Útemplate_nameÚcopy_tor   r7   Ústyler'   r.   r   r   r/   r0   Útemplate_dirÚdÚsubdirsÚfilesÚrelative_dirÚiÚsubdirÚfÚpath_oldÚpath_newÚfp_origÚdataÚfp_newr   r   r   r   +   sd   
€ÿ€ûÿüìør   )r9   rL   rI   Údjango.core.management.baser   Údjango.core.management.colorr   Ú"django_extensions.management.utilsr   r   r   r   r   r   r   r   Ú<module>   s   