o
    /h                     @   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                       sD   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 )CommandzJCreates a Django management command directory structure for the given app 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_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   )superadd_argumentsadd_argument)selfparser	__class__ o/var/www/html/env_mimamsha/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_config0   s   zCommand.handle_app_config)__name__
__module____qualname__r   r   r   str__annotations__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rqutj||}tj|||d|d}tj	|rtj|||d}tj	|r|
dkrt|d|  qu|
dkrt|d|  t|d4}| }|d|}|d|}|	st|d}|| W d   n1 sw   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>;       zcopy_template.<locals>.<lambda>SUCCESSc                 S   r+   r,   r   r-   r   r   r   r/   <   r0   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    r:   styler*   r1   r
   r   r2   r3   template_dirdsubdirsfilesrelative_dirisubdirfpath_oldpath_newfp_origdatafp_newr   r   r   r   6   s|   

r   )r<   rO   rL   typingr   django.core.management.baser   django.core.management.colorr   "django_extensions.management.utilsr   r   r   r   r   r   r   r   <module>   s   )