
    Mi6                         S SK r S SKrS SKrSSKJrJr  S SKJr  S SKrS SK	r	\" \R                  SS9rS rS rS	 rS
 rS rS rS rS rg)    N   )AsyncLoggerLogLevel)PathT)	log_levelverbosec                     [         R                  " S5      n U (       a  [        U 5      O[        R                  " 5       nUS-  nUS-  nUS-  n/ SQnUR	                  5       (       a  [
        R                  " U5        UR                  SS9  UR                  SS9  U H  nX-  R                  SS9  M     UR	                  5       (       d'  [        US5       nUR                  S	5        S
S
S
5        g
g
! , (       d  f       g
= f)zCSet up the .crawl4ai folder structure in the user's home directory.CRAWL4_AI_BASE_DIRECTORYz
global.ymlz	.crawl4aicache)html_contentcleaned_htmlmarkdown_contentextracted_contentscreenshotsT)exist_okw N)
osgetenvr   homeexistsshutilrmtreemkdiropenwrite)base_dircrawl4ai_foldercrawl4ai_configcache_foldercontent_foldersfolderfs          j/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/crawl4ai/install.pysetup_home_directoryr%      s    yy34H(0d8ndiikO%4O%3O"W,LO l# 4(%!		!(($(7 " !!##/3'1GGBK (' $''s   C11
C?c                      [         R                  SSS9  [        5         [        R                  " S5      n U S:X  a  [         R                  SSS9  O
[        5         [        5         [         R                  SS	S9  g
)z
Run all post-installation tasks.
Checks CRAWL4AI_MODE environment variable. If set to 'api',
skips Playwright browser installation.
z"Running post-installation setup...INITtagCRAWL4AI_MODEapizECRAWL4AI_MODE=api detected. Skipping Playwright browser installation.SETUPz"Post-installation setup completed!COMPLETEN)	loggerinfor%   r   r   warninginstall_playwrightrun_migrationsuccess)run_modes    r$   post_installr5   *   sj     KK4&KA yy)H5S 	 	
 	O NN7ZNH    c                      [         R                  SSS9  [        R                  " [	        5       5        [         R                  SSS9  g! [         a7  n [         R                  SU  35        [         R                  S5         Sn A gSn A ff = f)	z.Set up a builtin browser for use with Crawl4AIzSetting up builtin browser...r'   r(   z Builtin browser setup completed!r-   z"Failed to set up builtin browser: zWYou can manually set up a builtin browser using 'crawl4ai-doctor builtin-browser-start'N)r.   r/   asynciorun_setup_builtin_browserr3   	Exceptionr0   )es    r$   setup_builtin_browserr=   C   sp    r3@*,-9zJ r;A3?@pqqrs   AA	 	
B
-BB
c                    #     SSK Jn   U " [        S9nUR                  SS9I S h  vN nU(       a  [        R	                  SU 3SS9  g [        R                  S	SS9  g  N8! [         a  n[        R                  S
U 3SS9  e S nAff = f7f)Nr   )BrowserProfiler)r.   T)headlesszBuiltin browser launched at BROWSERr(   z Failed to launch builtin browserz"Error setting up builtin browser: )browser_profilerr?   r.   launch_builtin_browserr3   r0   r;   )r?   profilercdp_urlr<   s       r$   r:   r:   M   s     5"&1 !777FFNN9'CNSNN=9NM	 G
  ;A3?YOsD   B"A! A"A! 	B
A! BA! !
B+BBBc            	          [         R                  SSS9   [        R                  " [        R
                  SSSSSS	/5        [         R                  S
SS9  [         R                  SSS9   [        R                  " [        R
                  SSSSSS	/5        [         R                  SSS9  g ! [        R                   a*    [         R                  S[        R
                   S35         N[         a*    [         R                  S[        R
                   S35         Nf = f! [        R                   a*    [         R                  S[        R
                   S35         g [         a*    [         R                  S[        R
                   S35         g f = f)Nz!Installing Playwright browsers...r'   r(   z-m
playwrightinstallz--with-depsz--forcechromiumz/Playwright installation completed successfully.r-   zPlease run 'zD -m playwright install --with-deps' manually after the installation.z5Installing Patchright browsers for undetected mode...
patchrightz/Patchright installation completed successfully.zD -m patchright install --with-deps' manually after the installation.)
r.   r/   
subprocess
check_callsys
executabler3   CalledProcessErrorr0   r;    r6   r$   r1   r1   ^   sq   
KK3K@

	
 	=: 	 	
 KKGVKT

	
 	=: 	 	
3 (( 
3>>**no	
  
3>>**no	

. (( 
3>>**no	
  
3>>**no	

s/   ?B* *?D *;D'0DD;F0FFc                  r    [         R                  SSS9  SSKJn   [        R
                  " U R                  5       5        [         R                  SSS9  g! [         a    [         R                  S5         g[         a7  n[         R                  S	U 35        [         R                  S
5         SnAgSnAff = f)z'Initialize database during installationz#Starting database initialization...r'   r(   r   )async_db_managerz/Database initialization completed successfully.r-   z8Database module not found. Will initialize on first use.z Database initialization failed: z)Database will be initialized on first useN)r.   r/   crawl4ai.async_databaserR   r8   r9   
initializer3   ImportErrorr0   r;   )rR   r<   s     r$   r2   r2      s    D9vF<$//12=: 	 	
  SQR D9!=>BCCDs   AA B66	B6?-B11B6c            	      (  #    [         R                  SSS9   SSKJn JnJnJn  U" SSSSSS	S
9nU" UR                  SS9nU " US9 ISh  vN n[         R                  SSS9  UR                  SUS9I Sh  vN nU(       a7  UR                  (       a&  [         R                  SSS9   SSS5      ISh  vN   g[        S5      e Ny NO N! , ISh  vN  (       d  f       g= f! [         a!  n[         R                  SU 3SS9   SnAgSnAff = f7f)z$Test if Crawl4AI is working properlyz Running Crawl4AI health check...r'   r(   r   )AsyncWebCrawlerBrowserConfigCrawlerRunConfig	CacheModeTrI   i   i  )r@   browser_typeignore_https_errors
light_modeviewport_widthviewport_height)
cache_mode
screenshot)configNz Testing crawling capabilities...TESTzhttps://crawl4ai.com)urlrb   u   ✅ Crawling test passed!r-   zFailed to get contentu   ❌ Test failed: ERRORF)r.   r/   async_webcrawlerrW   rX   rY   rZ   BYPASSarunmarkdownr3   r;   error)	rW   rX   rY   rZ   browser_config
run_configcrawlerresultr<   s	            r$   
run_doctorro      s	    
KK2K?"	
 	
 '# $
 & ''


 #.99WKK:KG"<<,B:<VVF&//:
K :99   788 :V :999  (,':s   D2C$ 
CC$ (C
6C71C
(C$ 3C4C$ 8D9C
C$ C
C$ 
C!CC!C$  D!C$ $
D.D
D
DDc                  l    SSK n U R                  " [        5       5        [        R                  " S5        g)z"Entry point for the doctor commandr   N)r8   r9   ro   rM   exit)r8   s    r$   doctorrr      s    KK
HHQKr6   )rK   rM   r8   async_loggerr   r   pathlibr   r   r   DEBUGr.   r%   r5   r=   r:   r1   r2   ro   rr   rP   r6   r$   <module>rv      sY     
  /  	  
x~~t	<<I2r"5
pD"%Pr6   