
    Bj                        d Z ddlmZ ddlZddlZddlZddlmZ  ee      j                         j                  d   Zg dZg dZddZdd	Zdd
ZddZedk(  r e e             y)z
Apache readiness checker for My Daneshyar.

Run this before uploading/deploying to an Apache server. It checks the Laravel
public entry point, Vite build output, critical writable folders, and common
production safety settings.
    )annotationsN)Path   )artisanzcomposer.jsonzpackage.jsonzvendor/autoload.phpzpublic/index.phpzpublic/.htaccesszpublic/manifest.webmanifestzpublic/service-worker.js)	app	bootstrapconfigdatabasepublic	resourcesroutesstoragebootstrap/cachec                    t         dz  } i }| j                         s|S | j                  dd      j                         D ]~  }|j	                         }|r|j                  d      sd|vr+|j                  dd      \  }}|j	                         j	                  d      j	                  d	      ||j	                         <    |S )
N.envzutf-8ignore)encodingerrors#=r   "')ROOTexists	read_text
splitlinesstrip
startswithsplit)env_pathvalueslinestrippedkeyvalues         scripts/apache_ready_check.pyread_envr'   -   s    f}HF??""GH"EPPR B::<8..s3s(7J^^C+
U#kkm11#6<<SAsyy{B M    c                l    | j                         syt        j                  | t        j                        S )NF)r   osaccessW_OK)paths    r&   is_writabler.   <   s#    ;;=99T277##r(   c                &    t        d|  d|        y )N[z] )print)statusmessages     r&   reportr4   B   s    	AfXRy
!"r(   c                    d} d}t        dt         d       t        D ]=  }t        |z  j                         rt	        d| d       *| dz  } t	        d| d       ? t
        D ]=  }t        |z  j                         rt	        d| d	       *| dz  } t	        d| d
       ? t        dz  dz  dz  }|j                         rt	        dd       n| dz  } t	        dd       t        dz  }|j                         rt	        dd       t               }|j                  dd      j                         }|j                  dd      j                         }|dv rt	        dd       n| dz  } t	        dd       |dk(  rt	        dd       n#|dz  }t	        dd       n|dz  }t	        dd       t        dz  dz  }	|	j                         r| dz  } t	        dd       nt	        dd       dD ]:  }
t        |
z  }t        |      rt	        d|
 d        '|dz  }t	        d|
 d!       < t        d"z  }|j                         r|dz  }t	        dd#       nt	        dd$       t        d%       t        d&t        dz          t        d'|  d(| d)       | rdS dS )*Nr   zChecking Apache readiness for: 
OKz existsr   FAILz is missingz/ existsz/ is missingr   buildzmanifest.jsonz!public/build/manifest.json existsz8public/build/manifest.json is missing; run npm run buildr   z.env exists	APP_DEBUG APP_ENV)false0offnozAPP_DEBUG is disabledz'APP_DEBUG should be false in production
productionzAPP_ENV is productionWARNzAPP_ENV is not productionz:.env is missing; create it on the server from .env.examplez2public/.env exists and must be removed immediatelyzNo .env file inside public/)r   r   z/ is writable by current userz(/ may not be writable by Apache/PHP usernode_moduleszFnode_modules exists; do not upload it unless you intentionally need itznode_modules is absentz#
Apache DocumentRoot must point to:z  z	
Result: z failure(s), z warning(s))r1   r   CRITICAL_FILESr   r4   CRITICAL_DIRSis_dirr'   getlowerr.   )failureswarnings	file_pathdir_pathbuild_manifestenv_fileenv	app_debugapp_env
public_envwritable_dirr-   rC   s                r&   mainrT   F   s   HH	+D6
45# 6	9$$&4I;g./MH6i[456 " 68O##%4H:X./MH6hZ|456 H_w.@Nt89AvQRf}Ht]#jGGK,224	'')R(..033401MH6DEl"401MH667AvST6)JAvKLt236 Vl"t4L>)FGHMH6l^+STUV .(LAv_`t-.	
01	Bth
 !	JxjhZ{
CD1ar(   __main__)returnzdict[str, str])r-   r   rV   bool)r2   strr3   rX   rV   None)rV   int)__doc__
__future__r   r*   statsyspathlibr   __file__resolveparentsr   rD   rE   r'   r.   r4   rT   __name__
SystemExit r(   r&   <module>rf      sz    # 	  
  H~''*	
$#K \ z
TV
 r(   