
    3 d                         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	m
Z
mZ d dlmZ d dlZd dlmZ d dlmZ d dlmZmZ d	Z e
d
dd          Zd Z G d de          ZdS )    N)	find_spec)Path)copy2copystatignore_patternsmove)S_IWUSR)ScrapyCommand)
UsageError)render_templatefilestring_camelcase))
scrapy.cfg)${project_name}zsettings.py.tmpl)r   zitems.py.tmpl)r   zpipelines.py.tmpl)r   zmiddlewares.py.tmplz*.pyc__pycache__z.svnc                 r    t          j        |           j        }t          j        | |t          z             d S N)osstatst_modechmodOWNER_WRITE_PERMISSION)pathcurrent_permissionss     <lib/python3.11/site-packages/scrapy/commands/startproject.py_make_writabler      s2    '$--/HT&)??@@@@@    c                   `    e Zd ZdZdddZd Zd Zd Zdedefd	Z	d
 Z
edefd            ZdS )CommandFT)LOG_ENABLEDSPIDER_LOADER_WARN_ONLYc                     dS )Nz<project_name> [project_dir] selfs    r   syntaxzCommand.syntax#   s    --r   c                     dS )NzCreate new projectr"   r#   s    r   
short_desczCommand.short_desc&   s    ##r   c                     d }t          j        d|          st          d           n! ||          rt          d|d           ndS dS )Nc                 :    t          |           }|d uo|j        d uS r   )r   loader)module_namespecs     r   _module_existsz.Command._is_valid_name.<locals>._module_exists*   s&    [))Dt#?4(??r   z^[_a-zA-Z]\w*$z_Error: Project names must begin with a letter and contain only
letters, numbers and underscoreszError: Module z already existsTF)researchprint)r$   project_namer-   s      r   _is_valid_namezCommand._is_valid_name)   s    	@ 	@ 	@ y*L99 	:    ^L)) 	B<BBBCCCC4ur   srcdstc                    t           }d |                                D             } |||          }|                                s|                    d           |D ][}||v r||z  }||z  }|                                r|                     ||           <t          ||           t          |           \t          ||           t          |           dS )a  
        Since the original function always creates the directory, to resolve
        the issue a new function had to be created. It's a simple copy and
        was reduced for this case.

        More info at:
        https://github.com/scrapy/scrapy/pull/2005
        c                     g | ]	}|j         
S r"   )name).0xs     r   
<listcomp>z%Command._copytree.<locals>.<listcomp>C   s    ///A///r   T)parentsN)	IGNOREiterdirexistsmkdiris_dir	_copytreer   r   r   )	r$   r3   r4   ignorenamesignored_namesr7   srcnamedstnames	            r   rA   zCommand._copytree9   s     /////sE**zz|| 	$IIdI### 
	( 
	(D}$ DjGDjG~~ (w0000gw'''w''''csr   c                    t          |          dvrt                      |d         t          |          dk    rt          |d                   }nt          |d                   }|dz                                  r-d| _        t          d|                                            d S |                               s	d| _        d S |                     t          | j	                  |                                           t          |dz  |z             t          D ]:}t          |gfd|D             R  }t          |t                    	           ;t          d
 d| j	         d           t          d|                                 d           t          d           t          d|            t          d           d S )N)      r   rI   rH   r   z$Error: scrapy.cfg already exists in modulec              3   h   K   | ],}t          j        |                                         V  -dS ))r1   N)stringTemplate
substitute)r8   sr1   s     r   	<genexpr>zCommand.run.<locals>.<genexpr>q   sR         OA&&11|1LL     r   )r1   ProjectNamezNew Scrapy project 'z', using template directory 'z', created in:z    
z%You can start your first spider with:z    cd z(    scrapy genspider example example.com)lenr   r   r>   exitcoder0   resolver2   rA   templates_dirr   TEMPLATES_TO_RENDERr   r   )r$   argsoptsproject_dirpathstplfiler1   s         @r   runzCommand.runX   s'   t99F" 	,,Awt99> 	(tAw--KKtAw--K,&..00 	DMP9L9L9N9NPPQQQF""<00 	DMFtD.//1D1D1F1FGGG[8#[<%?@@@( 	 	E   "    G  ),\::    
 	3< 3 3"3 3 3	
 	
 	
 	.[((**...///5666%%%&&&899999r   returnc                     t          t          | j        d         pt          t          j        d         d          d                    S )NTEMPLATES_DIRr   	templatesproject)strr   settingsscrapy__path__r#   s    r   rV   zCommand.templates_dir   sD    o.W$vq7I;2W2W 
 
 	
r   N)__name__
__module____qualname__requires_projectdefault_settingsr%   r'   r2   r   rA   r]   propertyrc   rV   r"   r   r   r   r      s        ',NN. . .$ $ $   T     >*: *: *:X 
s 
 
 
 X
 
 
r   r   )r   r.   rL   importlib.utilr   pathlibr   shutilr   r   r   r   r   r	   r   re   scrapy.commandsr
   scrapy.exceptionsr   scrapy.utils.templater   r   rW   r<   r   r   r"   r   r   <module>rs      s,   				 				  $ $ $ $ $ $       9 9 9 9 9 9 9 9 9 9 9 9 2 2 2 2 2 2  ) ) ) ) ) ) ( ( ( ( ( ( G G G G G G G G  
-	8	8A A A
m
 m
 m
 m
 m
m m
 m
 m
 m
 m
r   