File: //usr/lib/python3/dist-packages/django/core/management/__pycache__/templates.cpython-310.pyc
o
3�aU5 � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl m
Z
d dlZd dlm
Z
d dlmZmZ d dlmZ d dlmZmZ d dlmZ d d lmZ G d
d� de�ZdS )� N)�
import_module)�urlretrieve)�settings)�BaseCommand�CommandError)�handle_extensions)�Context�Engine)�archive)�get_docs_versionc @ sl e Zd ZdZg Zg d�ZdZdd� Zddd�Zd d
� Z ddd
�Z
dd� Zdd� Zdd� Z
dd� Zdd� ZdS )�TemplateCommanda�
Copy either a Django application layout template or a Django project
layout template into the specified directory.
:param style: A color style object (see django.core.management.color).
:param app_or_project: The string 'app' or 'project'.
:param name: The name of the application or project.
:param directory: The directory to which the template should be copied.
:param options: The additional variables passed to project or app templates
)�http�https�ftp))z.py-tplz.pyc C s^ |j ddd� |j dddd� |j dd d� |j d
ddd
dgdd� |j dddd
g dd� d S )N�namez#Name of the application or project.)�help� directory�?zOptional destination directory)�nargsr z
--templatez*The path or URL to load the template from.z--extensionz-e�
extensions�append�pyztThe file extension(s) to render (default: "py"). Separate multiple extensions with commas, or use -e multiple times.)�dest�action�defaultr z--namez-n�filesz_The file name(s) to render. Separate multiple file names with commas, or use -n multiple times.)�add_argument)�self�parser� r �B/usr/lib/python3/dist-packages/django/core/management/templates.py�
add_arguments( s �
�zTemplateCommand.add_argumentsNc # K sv || _ |dkr dnd| _g | _|d | _| �|� |d u rJtj�t�� |�}zt� |� W n@ t
y: td| �� tyI } zt|��d }~ww |dkrX| �tj�
|�d� tj�tj�|��}tj�|�sntd| ��tt|d ��}g }|d D ]} |�td
d� | �d��� q|| jd
kr�| j�d|d�|�f � | j�d|d�|�f � d| }
d| }d| }d| }
d�dd� |�� D ��}ti |�|
||||
|dt� dtji�dd�}tjs�t�� t� � | �!|d |�}t"|�d }t�#|�D �]\}}}||d � }|�$|
|�}|�rtj�||�}tj |dd� |d d � D ]}|�%d ��s1|d!k�r6|�&|� �q$|D ]�}|�'d"��rD�q:tj�||�}tj�|||�$|
|��}| j(D ]\}}|�'|��rq|d t"|� � | } n�qZtj�|��r�td#|| j|f ��|�'|��s�||v �r�t)|d$d%��}|�*� }W d � n 1 �s�w Y t+� �,|�} | �-|�}t)|d&d$d%��
}!|!�|� W d � n 1 �s�w Y nt.�/||� | jd
k�r�| j�d'| � zt.�0||� | �1|� W �q: t�y | j2�d(| | j3j4� Y �q:w q�| j�r7| jd
k�r| j�d)� | jD ]}"tj�5|"��r0t�&|"� �q t.�6|"� �q d S d S )*N�app�an�a� verbosityz'%s' already existsr zBDestination directory '%s' does not exist, please create it first.r r c S s | � � S �N)�strip)�xr r r �<lambda>V s z(TemplateCommand.handle.<locals>.<lambda>�,� z/Rendering %s template files with extensions: %sz, z.Rendering %s template files with filenames: %sz%s_namez%s_templatez%s_directoryzcamel_case_%s_name� c s s � | ] }|d kr|V qdS )�_Nr )�.0r( r r r � <genexpr>d s � z)TemplateCommand.handle.<locals>.<genexpr>�docs_version�django_versionF)�
autoescape�template� T)�exist_ok�.�__pycache__)z.pyoz.pycz .py.classz_%s already exists. Overlaying %s %s into an existing directory won't replace conflicting files.zutf-8)�encoding�wzCreating %szkNotice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.zCleaning up temporary files.)7�app_or_project�a_or_an�paths_to_remover% �
validate_name�os�path�join�getcwd�makedirs�FileExistsErrorr �OSError�basename�abspath�
expanduser�exists�tupler �extend�map�split�stdout�write�titler r �django�__version__r �
configured� configure�setup�handle_template�len�walk�replace�
startswith�remove�endswith�rewrite_template_suffixes�open�readr �from_string�render�shutil�copyfile�copymode�make_writeable�stderr�style�NOTICE�isfile�rmtree)#r r: r �target�options�top_dir�er �extra_files�file� base_name�base_subdir�base_directory�camel_case_name�camel_case_value�context�template_dir�
prefix_length�root�dirsr � path_rest�relative_dir�
target_dir�dirname�filename�old_path�new_path�
old_suffix�
new_suffix�
template_file�contentr3 �new_file�path_to_remover r r �handle: s�
���
�������
�
������
�
���
���,
�zTemplateCommand.handlec C s� |du rt j�tjd d|�S |�d�r|dd� }t j�|�}t j�|�}t j�|�r.|S | � |�r9| �
|�}nt j�|�}t j�|�rJ| �
|�S td| j|f ��)z�
Determine where the app or project templates are.
Use django.__path__[0] as the default because the Django install
directory isn't known.
Nr �confzfile://� zcouldn't handle %s template %s.)r>