
    g!;                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d d	lmZ  G d
 de      Zy)    N)apps)get_finders)staticfiles_storage)Tags)FileSystemStorage)BaseCommandCommandError)no_style)cached_propertyc                        e Zd ZdZdZej                  gZ fdZe	d        Z
d Zd Zd Zd Zdd	Zd
 Zd Zd Zd Zd Z xZS )Commandzc
    Copies or symlinks static files from different locations to the
    settings.STATIC_ROOT.
    z*Collect static files in a single location.c                     t        |   |i | g | _        g | _        g | _        g | _        t        | _        t               | _	        y N)
super__init__copied_filessymlinked_filesunmodified_filespost_processed_filesr   storager
   style)selfargskwargs	__class__s      /var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/staticfiles/management/commands/collectstatic.pyr   zCommand.__init__   sE    $)&)! "$&!*Z
    c                 Z    	 | j                   j                  d       y# t        $ r Y yw xY w)N FT)r   pathNotImplementedErrorr   s    r   localzCommand.local   s2    	LLb!  # 		s    	**c           	      2   |j                  ddddd       |j                  dddd	       |j                  d
ddg ddd       |j                  dddd       |j                  dddd       |j                  dddd       |j                  dddd       y )Nz	--noinputz
--no-inputstore_falseinteractivez-Do NOT prompt the user for input of any kind.)actiondesthelpz--no-post-processpost_processz$Do NOT post process collected files.z-iz--ignoreappendignore_patternsPATTERNz`Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.)r'   defaultr(   metavarr)   z-nz	--dry-run
store_truez+Do everything except modify the filesystem.)r'   r)   z-cz--clearz[Clear the existing files using the storage before trying to copy or link the original file.z-lz--linkz7Create a symbolic link to each file instead of copying.z--no-default-ignoreuse_default_ignore_patternszWDon't ignore the common private glob-style patterns (defaults to 'CVS', '.*' and '*~').)add_argument)r   parsers     r   add_argumentszCommand.add_arguments'   s     @ 	 	
 	 7	 	 	
 	": 	 		
 	>	 	 	
 	?	 	 	
 	J	 	 	
 	! .) 	 	
r   c                 T   |d   | _         |d   | _        |d   | _        |d   | _        |d   | _        |d   }|d   r"|t        j                  d      j                  z  }t        |D ch c]!  }t        j                  j                  |      # c}      | _        |d	   | _        y
c c}w )zA
        Set instance variables based on an options dict
        r&   	verbositylinkcleardry_runr,   r1   staticfilesr*   N)r&   r6   symlinkr8   r9   r   get_app_configr,   listosr    normpathr*   )r   optionsr,   ps       r   set_optionszCommand.set_options\   s     #=1 -vW%
y)!"3401t22=AQQQO#/$R/QRWW%5%5a%8/$RS#N3 %Ss   (&B%c                 6   | j                   r| j                  st        d      | j                  r| j	                  d       | j                   r| j
                  }n| j                  }i }t               D ]  }|j                  | j                        D ]k  \  }}t        |dd      r+t        j                  j                  |j                  |      }n|}||vr||f||<    ||||       V| j                  d|z  d       m  | j                   rt#        | j$                  d      r| j$                  j!                  || j&                  	      }|D ]  \  }}	}
t)        |
t*              r:| j,                  j/                  d
|z         | j,                  j/                          |
|
r6| j                  d|d|	dd       | j0                  j3                  |       | j                  d|z          | j4                  | j6                  z   | j8                  | j0                  dS )zx
        Perform the bulk of the work of collectstatic.

        Split off from handle() to facilitate testing.
        z&Can't symlink to a remote destination.r   prefixNzFound another file with the destination path '%s'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.   levelr*   )r9   zPost-processing '%s' failed!zPost-processed 'z' as ''   zSkipped post-processing '%s')modified
unmodifiedpost_processed)r;   r#   r	   r8   	clear_dir	link_file	copy_filer   r=   r,   getattrr>   r    joinrD   logr*   hasattrr   r9   
isinstance	Exceptionstderrwriter   r+   r   r   r   )r   handlerfound_filesfinderr    r   prefixed_path	processororiginal_pathprocessed_path	processeds              r   collectzCommand.collectk   s    <<

GHH::NN2<<nnGnnG!mF!'T-A-A!Bg7Hd3$&GGLL$FM$(M 3294K.D-9HH? BOO     "C $* ~!F11+t||1TI<E8~yi3KK%%&D}&TU KK%%'#OHH9FW   --44]CHH;mKL =F" ))D,@,@@//"77
 	
r   c                     | j                   di | dg}| j                  r|j                  d       |j                  d       | j                         r| j                  j
                  rl| j                  j
                  }|j                  d|z         | j                  j                  |      xr$ t        | j                  j                  |            }nd }|j                  d       d}| j                  rj|rh| j                  r|j                  d       n|j                  d       |j                  d	       t        d
j                  |            dk7  rt        d      | j                         }| j                  dk\  rmt!        |d         }t!        |d         }t!        |d         }d|d|dk(  rd
ndz   | j"                  rdnd|rd|z  nd
|d   rd|z  nd
|d   xr d|z  xs d
dz  S y )N
zGYou have activated the --dry-run option so no files will be modified.

zdYou have requested to collect static files at the destination
location as specified in your settingsz:

    %s

z.

Tz-This will DELETE ALL FILES in this location!
z$This will overwrite existing files!
zNAre you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: r   yesz"Collecting static files cancelled.rE   rJ   rK   rL   z]
%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s.zstatic files	symlinkedcopiedz to '%s'z, %s unmodifiedz, %s post-processed)modified_count
identifierr'   destinationrK   rL    )rB   r9   r+   is_local_storager   locationexistsanylistdirr&   r8   inputrQ   r	   r`   r6   lenr;   )	r   r@   messagedestination_pathshould_warn_user	collectedrg   unmodified_countpost_processed_counts	            r   handlezCommand.handle   s   #7#&<<NN 
 	5	

   "t||'<'<#||44NN,/??@#||223CD  $$%56J  $NN7## 0zzOPFGNN> RWWW%&%/"#GHHLLN	>>Q :!67N"9\#:;#&y1A'B#C C #1+^q5HrcR)-+85EJ!112 !. &(88 ./ E-0DD 	 r   c                 Z    | j                   |k\  r| j                  j                  |       yy)z"
        Small log helper
        N)r6   stdoutrW   )r   msgrG   s      r   rR   zCommand.log   s'     >>U"KKc" #r   c                 6    t        | j                  t              S r   )rT   r   r   r"   s    r   rk   zCommand.is_local_storage   s    $,,(9::r   c                    | j                   j                  |      sy| j                   j                  |      \  }}|D ]  }t        j                  j                  ||      }| j                  r| j                  d|z  d       F| j                  d|z  d       	 | j                   j	                  |      }t        j                  j                  |      s5t        j                  j                  |      rt        j                  |       | j                   j                  |        |D ]1  }| j                  t        j                  j                  ||             3 y# t        $ r | j                   j                  |       Y Gw xY w)zW
        Delete the given relative path using the destination storage backend.
        NPretending to delete '%s'rE   rF   Deleting '%s')r   rm   ro   r>   r    rQ   r9   rR   lexistsunlinkdeleter!   rM   )r   r    dirsfilesffpath	full_pathds           r   rM   zCommand.clear_dir   s#    ||""4(ll**40eAGGLLq)E||4u<AF50:	3 $ 1 1% 8I 77>>)49S		),++E2   ANN277<<a01  + /LL''./s   E$FFc                    | j                   j                  |      r<	 | j                   j                  |      }	 |j                  |      }| j                  rI| j                   j	                  |      }| j
                  t        j                  j                  |      z   }nd}|j                  d      |j                  d      k\  }|r@|r>|| j                  vr| j                  j                  |       | j                  d|z         y| j                  r| j                  d|z         y| j                  d|z         | j                   j!                  |       y# t        t        t        f$ r Y gw xY w# t        t        t        f$ r Y w xY w)zR
        Check if the target file should be deleted if it already exists.
        Tr   )microsecondzSkipping '%s' (not modified)Fr~   r   )r   rm   get_modified_timer#   r    r;   r>   islinkreplacer   r+   rR   OSErrorr!   AttributeErrorr9   r   )	r   r    r[   source_storagetarget_last_modifiedsource_last_modifiedr   can_skip_unmodified_filesfile_is_unmodifieds	            r   delete_filezCommand.delete_file  s|    <<}-%%'+||'E'Em'T$
%+9+K+KD+Q(
 zz$(LL$5$5m$D	 !LL277>>)+DD51 591)=)E)E$% *F *-55!5D*E& *.G(0E0EE 1188G!?$!FG$||4t;<  4/0##M2E  !4nE  0.A s"   E4 E E10E14F
Fc                    || j                   v r| j                  d|z        S | j                  |||      sy|j                  |      }| j                  r| j                  d|z  d       n| j                  d|z  d       | j
                  j                  |      }t        j                  t        j                  j                  |      d	       	 t        j                  j                  |      rt        j                  |       t        j                  ||       || j                   vr| j                   j!                  |       yy# t        $ r! d
dl}t        d|j                         z        t        $ r}t        |      d}~ww xY w)z*
        Attempt to link ``path``
        z&Skipping '%s' (already linked earlier)NzPretending to link '%s'rE   rF   zLinking '%s'rI   T)exist_okr   z2Symlinking is not supported in this platform (%s).)r   rR   r   r    r9   r   r>   makedirsdirnamer   r   r;   r!   platformr	   r   r+   )r   r    r[   r   source_pathr   r   es           r   rN   zCommand.link_fileE  sQ   
 D00088DtKLLm^D$))$/<<HH.<AHFHH^k1H;))-8IKK	2TB&77??9-IIi(

;	2  4 44  ''6 5 ' "%'/'8'8':;   &"1o%&s   A
E 1F7FFc                    || j                   v r| j                  d|z        S | j                  |||      sy|j                  |      }| j                  r| j                  d|z  d       nL| j                  d|z  d       |j                  |      5 }| j                  j                  ||       ddd       | j                   j                  |       y# 1 sw Y   %xY w)z7
        Attempt to copy ``path`` with storage
        z&Skipping '%s' (already copied earlier)NzPretending to copy '%s'rE   rF   zCopying '%s'rI   )	r   rR   r   r    r9   openr   saver+   )r   r    r[   r   r   source_files         r   rO   zCommand.copy_fileh  s    
 D---88DtKLLm^D$))$/<<HH.<AHFHH^k1H;$$T*k!!-= +  / +*s   CC)rI   )__name__
__module____qualname____doc__r)   r   r:   requires_system_checksr   r   r#   r4   rB   r`   rx   rR   rk   rM   r   rN   rO   __classcell__)r   s   @r   r   r      so    
 8D"../   3
j4=
~AF#;261f!7F0r   r   )r>   django.appsr   "django.contrib.staticfiles.findersr   "django.contrib.staticfiles.storager   django.core.checksr   django.core.files.storager   django.core.management.baser   r	   django.core.management.colorr
   django.utils.functionalr   r   rj   r   r   <module>r      s.    	  : B # 7 A 1 3n0k n0r   