
    `?ib>                         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 | _        g | _        g | _        t        | _	        t               | _        y N)super__init__copied_filessymlinked_filesunmodified_filespost_processed_filesskipped_filesdeleted_filesr   storager
   style)selfargskwargs	__class__s      /home/cursorai/projects/django-cronjob-utils/venv/lib/python3.12/site-packages/django/contrib/staticfiles/management/commands/collectstatic.pyr   zCommand.__init__   sU    $)&)! "$&!*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.   r3   staticfilesr,   N)r(   r8   symlinkr:   r;   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                    | j                   r| j                  st        d      | j                  r| j	                  d       | j                   r| j
                  }n| j                  }i }t               D ]  }|j                  | j                        D ]  \  }}t        |dd      r+t        j                  j                  |j                  |      }n|}||vr||f||<    ||||       V| j                  j!                  |       | j#                  d|z  d         | j$                  rt'        | j(                  d      r| j(                  j%                  || j*                  	      }|D ]  \  }}	}
t-        |
t.              r:| j0                  j3                  d
|z         | j0                  j3                          |
|
r6| j#                  d|d|	dd       | j4                  j!                  |       | j#                  d|z          | j6                  | j8                  z   | j:                  | j4                  | j                  | j<                  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,   )r;   zPost-processing '%s' failed!zPost-processed 'z' as ''zSkipped post-processing '%s')modified
unmodifiedpost_processedskippeddeleted)r=   r%   r	   r:   	clear_dir	link_file	copy_filer   r?   r.   getattrr@   r"   joinrF   r   r-   logr,   hasattrr   r;   
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.collectm   s
    <<

GHH::NN2<<nnGnnG!mF!'T-A-A!Bg7Hd3$&GGLL$FM$(M 3294K.D-9&&--m<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\  rt!        |d         }t!        |d         }t!        |d         }t!        |d         }	t!        |d         }
d|dkD  r|d|dk(  rd
nddn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   r	d|
z  dz  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.   rO   rK   rL   rM   rN   zs
%(deleted)s%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s%(skipped)s.r   z static filesz
 deleted, zstatic file	symlinkedcopiedz to '%s'z, %s unmodifiedz, %s post-processedz, %s skipped due to conflict)rO   modified_count
identifierr)   destinationrL   rM   rN    )rD   r;   r-   is_local_storager   locationexistsanylistdirr(   r:   inputrT   r	   rc   r8   lenr=   )r   rB   messagedestination_pathshould_warn_user	collecteddeleted_countrk   unmodified_countpost_processed_countskipped_counts              r   handlezCommand.handle   sk   #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	) 45M :!67N"9\#:;#&y1A'B#C 	) 45MN %q( %MQ,>bC&GI "0+^q5HrcR)-+85EJ!112 !. &(88 ./ E-0DD !+ 3]B1 : 5  r   c                 Z    | j                   |k\  r| j                  j                  |       yy)z"
        Small log helper
        N)r8   stdoutrZ   )r   msgrI   s      r   rU   zCommand.log   s'     >>U"KKc" #r   c                 6    t        | j                  t              S r   )rW   r   r   r$   s    r   ro   zCommand.is_local_storage  s    $,,(9::r   c                    | j                   j                  |      sy| j                   j                  |      \  }}|D ]  }t        j                  j                  ||      }| j                  r2| j                  d|z  d       | j                  j                  |       b| j                  d|z  d       | j                  j                  |       	 | j                   j	                  |      }t        j                  j                  |      s6t        j                  j                  |      rt        j                  |       | j                   j                  |       ! |D ]1  }| j                  t        j                  j                  ||             3 y# t        $ r | j                   j                  |       Y w xY w)zW
        Delete the given relative path using the destination storage backend.
        NPretending to delete '%s'rG   rH   Deleting '%s')r   rq   rs   r@   r"   rT   r;   rU   r   r-   lexistsunlinkdeleter#   rP   )r   r"   dirsfilesffpath	full_pathds           r   rP   zCommand.clear_dir	  sK    ||""4(ll**40eAGGLLq)E||4u<AF""))%050:""))%0	3 $ 1 1% 8I 77>>)49S		),++E2# $ ANN277<<a01  + /LL''./s   F$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        f$ r Y bw xY w# t        t        f$ r Y ww 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   rq   get_modified_timer%   r"   r=   r@   islinkreplacer   r-   rU   OSErrorr#   r;   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&  sx    <<}-%%'+||'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  !45  01 s"   E/ E E,+E,/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'rg   rH   zLinking '%s'rG   T)exist_okr   z2Symlinking is not supported in this platform (%s).)r   rU   r   r"   r;   r   r@   makedirsdirnamer   r   r=   r#   platformr	   r   r-   )r   r"   r^   r   source_pathr   r   es           r   rQ   zCommand.link_fileY  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'rg   rH   zCopying '%s'rG   )	r   rU   r   r"   r;   openr   saver-   )r   r"   r^   r   r   source_files         r   rR   zCommand.copy_file|  s    
 D---88DtKLLm^D$))$/<<HH.<AHFHH^k1H;$$T*k!!-= +  / +*s   CC)rG   )__name__
__module____qualname____doc__r+   r   r<   requires_system_checksr   r   r%   r6   rD   rc   r~   rU   ro   rP   r   rQ   rR   __classcell__)r   s   @r   r   r      sp    
 8D"../	   3
j4@
DN`#;2:1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   rn   r   r   <module>r      s.    	  : B # 7 A 1 3B0k B0r   