Ë
    qûàg°.  ã                   óº   — d dl Z d dlZ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
 d dlmZ d dlmZ d dlmZ  G d„ d	«      Zd
„ Z G d„ de«      Z G d„ de«      Zy)é    N)ÚArgumentTypeError)Úapps)Úsettings)ÚCommandError)ÚEmailNotificationCommand)Úsignalcommandc                   ó   — e Zd ZdZdZdZy)ÚDirPolicyChoicesÚnoneÚeachÚrootN)Ú__name__Ú
__module__Ú__qualname__ÚNONEÚEACHÚROOT© ó    úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django_extensions/management/commands/runscript.pyr
   r
      s   „ Ø€DØ€DØ�Dr   r
   c                 ód   — | �t         j                  j                  | «      st        d| z  «      ‚| S )Nz%s is not a directory!)ÚosÚpathÚisdirr   )Úvalues    r   Úcheck_is_directoryr      s,   € Ø€}œBŸG™GŸM™M¨%Ô0ÜÐ 8¸5Ñ @ÓAÐAØ€Lr   c                   ó   — e Zd Zd„ Zd„ Zy)ÚBadCustomDirectoryExceptionc                 ó   — |dz   | _         y )Nzm If --dir-policy is custom than you must set correct directory in --dir option or in settings.RUNSCRIPT_CHDIR©Úmessage)Úselfr   s     r   Ú__init__z$BadCustomDirectoryException.__init__   s   € Øð  Mñ Mˆ�r   c                 ó   — | j                   S )Nr    )r"   s    r   Ú__str__z#BadCustomDirectoryException.__str__#   s   € Ø�|‰|Ðr   N)r   r   r   r#   r%   r   r   r   r   r      s   „ òMór   r   c                   ó<   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zed„ «       Zˆ xZS )ÚCommandz Runs a script in django context.c                 ód   •— t        ‰| �  |i |¤Ž t        j                  «       | _        d| _        y )Nr   )Úsuperr#   r   ÚgetcwdÚcurrent_directoryÚlast_exit_code)r"   ÚargsÚkwargsÚ	__class__s      €r   r#   zCommand.__init__*   s+   ø€ Ü‰Ñ˜$Ð) &Ò)Ü!#§¡£ˆÔØˆÕr   c                 ó  •— t         ‰| �  |«       |j                  dd¬«       |j                  ddddd¬	«       |j                  d
dddd¬	«       |j                  dddddd¬	«       |j                  dddddd¬	«       |j                  ddddd¬	«       |j                  ddt        d¬«       |j                  dt        t        j
                  t        j                  t        j                  gd¬«       |j                  dt        d ¬!«       y )"NÚscriptú+)Únargsz
--fixturesÚ
store_trueÚ
infixturesFz Also look in app.fixtures subdir)ÚactionÚdestÚdefaultÚhelpz--noscriptsÚ	noscriptsz!Do not look in app.scripts subdirz-sz--silentÚsilentzRRun silently, do not show errors and tracebacks. Also implies --continue-on-error.z-cz--continue-on-errorÚcontinue_on_errorz¸Continue executing other scripts even though one has failed. It will print a traceback unless --no-traceback or --silent are given The exit code used when terminating will always be 1.z--no-tracebackÚno_tracebackzDo not show tracebacksz--script-argsÚ*z|Space-separated argument list to be passed to the scripts. Note that the same arguments will be passed to all named scripts.)r3   Útyper9   z--dir-policyz¼Policy of selecting scripts execution directory: none - start all scripts in current directory each - start all scripts in their directories root - start all scripts in BASE_DIR directory )r?   Úchoicesr9   z--chdirz^If dir-policy option is set to custom, than this option determines script execution directory.)r?   r9   )	r)   Úadd_argumentsÚadd_argumentÚstrr
   r   r   r   r   )r"   Úparserr/   s     €r   rA   zCommand.add_arguments/   sO  ø€ Ü‰Ñ˜fÔ%Ø×Ñ˜H¨CÐÔ0Ø×ÑØ °LÈ%Ø3ð 	ô 	
ð 	×ÑØ ,°[È%Ø4ð 	ô 	
ð 	×ÑØ�* \¸È%Øeð 	ô 	
ð 	×ÑØÐ'°ÐCVÐ`eðIð 	ô 	
ð 	×ÑØ \¸ÐPUØ)ð 	ô 	
ð 	×ÑØ 3¬SðGð 	ô 	
ð
 	×ÑØ¤Ü%×*Ñ*Ô,<×,AÑ,AÔCS×CXÑCXÐYðCð 	ô 	
ð 	×ÑØÔ.Øqð 	õ 	
r   c           	      óf  ‡ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡— ‰ j                   j                  Š‰ j                   j                  Š‰ j                   j                  Š‰ j                   j                  Šg Š‰d   }‰d   s ‰j                  t        t        dd«      «       ‰d   r‰j                  d«       ‰d   Š‰d   Š‰d	   Š‰d
   Š‰rdŠndŠ‰d   Š‰rdŠdŠ‰d   Št        ‰«      dk  rt         ‰d«      «       y t        |«      dk  rt         ‰d«      «       y ˆfd„Šˆˆ fd„Šˆˆˆfd„Šˆˆˆˆˆ ˆˆˆˆf	d„}ˆˆˆˆˆˆˆfd„Šˆˆfd„}‰d   r‰d   }ng }g }|D ]@  } ||«      }	|	s#d‰ _
        ‰dkD  r‰st         ‰d|z  «      «       Œ0|j                  |	«       ŒB ‰ j                  r‰dk  r‰st         ‰d«      «       ‰sg }|D ].  }
‰dkD  rt         ‰d|
j                  z  «      «        ||
g|¢­Ž  Œ0 ‰ j                  dk7  rF‰r,t        ‰ d«      ry t        j                  ‰ j                  «       	 t!        d‰ j                  ¬ «      ‚y # t"        $ r[ ‰ j                  dk(  rt!        d«      ‚t         ‰d«      «       t        ‰ d«      rY y t        j                  ‰ j                  «       Y y w xY w)!Nr1   r:   ÚRUNSCRIPT_SCRIPT_DIRÚscriptsr5   ÚfixturesÚ	verbosityÚ	tracebackr=   r<   FTr;   r   Úemail_notificationsé   zNo subdirs to run left.zScript name required.c                  óš   •— ‰d   xs t        t        dd «      } 	 t        | «       | S # t        $ r}t	        t        |«      «      ‚d }~ww xY w)NÚchdirÚRUNSCRIPT_CHDIR)Úgetattrr   r   r   r   rC   )Ú	directoryÚeÚoptionss     €r   Úget_directory_from_chdirz0Command.handle.<locals>.get_directory_from_chdir   sS   ø€ Ø Ñ(ÒV¬G´HÐ>OÐQUÓ,VˆIð:Ü" 9Ô-ð Ðøô %ò :Ü1´#°a³&Ó9Ð9ûð:ús   ›( ¨	A
±AÁA
c                 ó8  •— ‰d   xs t        t        dt        j                  «      }|t        j                  k(  rt        j
                  S |t        j                  k(  r2t        j                  j                  t        j                  | «      «      S ‰j                  S )NÚ
dir_policyÚRUNSCRIPT_CHDIR_POLICY)rP   r   r
   r   r   ÚBASE_DIRr   r   r   ÚdirnameÚinspectÚgetfiler+   )Úscript_moduleÚpolicyrS   r"   s     €€r   Úget_directory_basing_on_policyz6Command.handle.<locals>.get_directory_basing_on_policy‡   su   ø€ Ø˜\Ñ*Òp¬g´hÐ@XÔZj×ZoÑZoÓ.pˆFØÔ)×.Ñ.Ò.Ü×(Ñ(Ð(ØÔ+×0Ñ0Ò0Ü—w‘w—‘¤w§¡°}Ó'EÓFÐFà×-Ñ-Ð-r   c                 óâ   •— ‰d   r ‰«       }n/‰d   r	 ‰| «      }n!t        t        dd «      r ‰«       }n ‰| «      }t        j                  t        j                  j                  |«      «       y )NrN   rV   rO   )rP   r   r   rN   r   Úabspath)r\   rQ   r^   rT   rS   s     €€€r   Úset_directoryz%Command.handle.<locals>.set_directory�   s]   ø€ Ø�wÒÙ4Ó6‘	Ø˜Ò&Ù:¸=ÓI‘	ÜœÐ#4°dÔ;Ù4Ó6‘	á:¸=ÓI�	Ü�H‰H”R—W‘W—_‘_ YÓ/Õ0r   c                 óø  •	— d }	  ‰	| «        | j                   |Ž }t        |t        «      r|rdnd}t        |t        «      r#|dk7  r	 t	        d| j
                  ›d|›�|¬«      ‚‰r‰j                  | j
                  ¬«       y y # t        $ r t	        d| j
                  ›d|›�«      ‚w xY w# t        $ rÃ}t        |t        «      rt        |d«      r|j                  }t        |t        «      r|nd‰_        ‰rY d }~y ‰dkD  rt         ‰d| j
                  z  «      «       ‰r‰
rt        j                  «        Y d }~y ‰r‰j                  | j
                  d	¬
«       ‰rt	        t        |«      «      ‚‚ d }~ww xY w)NrL   r   ú'z' failed with exit code ©Ú
returncode)Únotification_idre   z%Exception while running run() in '%s'T)rf   Úinclude_traceback)ÚrunÚ
isinstanceÚboolÚintr   r   Ú	TypeErrorÚsend_email_notificationÚ	ExceptionÚhasattrre   r,   ÚprintrJ   Ú	print_excÚrepr)ÚmodÚscript_argsÚ	exit_coderR   ÚERRORr<   rK   r=   r"   ra   Úshow_tracebackr;   rI   s       €€€€€€€€€r   Ú
run_scriptz"Command.handle.<locals>.run_script›   sh  ø€ ØˆIð Ù˜cÔ"Ø#˜CŸG™G [Ð1�	Ü˜i¬Ô.á%.¡°A�IÜ˜i¬Ô-Ø  A’~ðlÝ".ÐRU×R^ÓR^Ñ`iÐ/jð  xAô  #Bð  Bñ 'Ø×0Ñ0ÀÇÁÐ0ÕNð 'øô  )ò lÝ".ÐRU×R^ÓR^Ñ`iÐ/jÓ"kÐkðlûô ò Ü˜a¤Ô.´7¸1¸lÔ3KØ !§¡�IÜ3=¸iÌÔ3M¡iÐST�Ô#ÙÜØ˜q’=Ü™%Ð GÈ#Ï,É,Ñ VÓWÔXÙ$Ù%Ü!×+Ñ+Ô-ÜÙ&Ø×0Ñ0ÀÇÁÐaeÐ0ÔfáÜ&¤t¨A£wÓ/Ð/àûð%ús=   …AB- ÁB Á%B- Â%B*Â*B- Â-	E9Â6AE4Ã>;E4Ä>6E4Å4E9c           
      ó^  •— | ›d|›�}‰dkD  rt         ‰d|z  «      «       	 t        j                  | «       	 t        j                  |«      }t%        |d
«      r‰dkD  rt         ‰	d|z  «      «       |S ‰dkD  rt         ‰d|z  «      «       y y # t        $ r)}t	        |«      j                  d«      rY d }~yY d }~Œ…d }~ww xY w# t        $ rÞ}	 t        j                  j                  |«      €Y d }~ynt# t        $ rh t        j                  j                  t        j                  g|j                  d«      ¢­Ž dz   }t        j                  j                  |«      sY Y d }~yY nw xY w‰rY d }~y‰
rt!        j"                  «        ‰dkD  rt         ‰d|›d	|›d�«      «       Y d }~yd }~ww xY w)Nú.rL   zCheck for %szNo module namedFz.pyr   zCannot import module 'z': rh   zFound script '%s' ...z.Found script '%s' but no run() function found.)rp   Ú	importlibÚimport_moduleÚImportErrorrC   Ú
startswithÚutilÚ	find_specrn   r   r   Újoinr   rX   ÚsplitÚisfilerJ   rq   ro   )Úparent_packageÚmodule_nameÚfull_module_pathrR   ÚtÚmodule_filerv   ÚERROR2ÚNOTICEÚNOTICE2rw   r;   rI   s         €€€€€€€r   Ú	my_importz!Command.handle.<locals>.my_import¿   s‹  ø€ Ú*8¹+ÐFÐØ˜1Š}Ü‘f˜^Ð.>Ñ>Ó?Ô@ð!Ü×'Ñ'¨Ô7ðÜ×+Ñ+Ð,<Ó=�ô( �q˜%Ô Ø˜q’=Ü™'Ð"9Ð<LÑ"LÓMÔNØ�à˜q’=Ü™&Ð!QÐTdÑ!dÓeÕfð !øô? ò !Ü�q“6×$Ñ$Ð%6Ô7ä ô 8ûð!ûô ò ð%Ü —~‘~×/Ñ/Ð0@ÓAÐIÜ$ð Jøä ò %Ü"$§'¡'§,¡,¬x×/@Ñ/@Ð"_ÐCS×CYÑCYÐZ]ÓC^Ò"_ÐbgÑ"g�KÜŸ7™7Ÿ>™>¨+Ô6Ý$ñ 7ð%úñ
 Ü Ù!Ü×'Ñ'Ô)Ø˜q’=Üš%ÒDTÒVWÐ XÓYÔZäûð#úsY   £B ¹C Â	CÂB=Â=CÃ	F,ÃC4Ã3F'Ã4A(E%ÅF'Å"F'Å$E%Å%F'Å/3F'Æ'F,c                 óz  •— g }t        j                  «       D ]5  }‰D ].  } ‰|j                  ›d|›�| «      }|sŒ|j                  |«       Œ0 Œ7 | j	                  d«      dk7  r3| j                  dd«      \  }} ‰||«      }|r|j                  |«       |S ‰D ]  } ‰|| «      }|sŒ|j                  |«       Œ! |S )z3 Find script module which contains 'run' attribute rz   éÿÿÿÿrL   )r   Úget_app_configsÚnameÚappendÚfindÚrsplit)	r1   ÚmodulesÚappÚsubdirrs   ÚparentÚmod_namerŒ   Úsubdirss	          €€r   Úfind_modules_for_scriptz/Command.handle.<locals>.find_modules_for_scriptè   sÐ   ø€ àˆGä×+Ñ+Ó-ò ,�Ø%ò ,�FÙ#¨s¯x«x¹Ð$@À&ÓI�CÚØŸ™ sÕ+ñ,ð,ð �{‰{˜3Ó 2Ò%Ø#)§=¡=°°aÓ#8Ñ �˜Ù ¨Ó1�ÙØ—N‘N 3Ô'ð ˆNð &ò ,�FÙ# F¨FÓ3�CÚØŸ™ sÕ+ð,ð
 ˆNr   rt   z'No (valid) module for script '%s' foundé   z:Try running with a higher verbosity level like: -v2 or -v3zRunning script '%s' ...Úrunning_testsz8An error has occurred running scripts. See errors above.rd   )ÚstyleÚ	SQL_TABLEÚ	SQL_FIELDrv   rŠ   r‘   rP   r   Úlenrp   r,   Úextendr   ro   ÚsysÚexitr   rl   )r"   r-   rS   rG   rx   rš   rt   Úscript_to_runr1   Úscript_modulesÚ
script_modrv   r‰   rŠ   r‹   r<   rK   r^   rT   rŒ   r=   ra   rw   r;   r™   rI   s   ` `        @@@@@@@@@@@@@@@r   ÚhandlezCommand.handleZ   sÅ  ÿÿø€ ð —‘×%Ñ%ˆØ—*‘*×&Ñ&ˆØ—
‘
× Ñ ˆØ—‘×"Ñ"ˆàˆØ˜(Ñ#ˆà�{Ò#Ø�N‰Nœ7¤8Ð-CÀYÓOÔPØ�<Ò Ø�N‰N˜:Ô&Ø˜KÑ(ˆ	Ø  Ñ-ˆØ˜~Ñ.ˆØ#Ð$7Ñ8ÐÙØ"‰Nà!ˆNØ˜Ñ"ˆÙØˆIØ $ÐØ%Ð&;Ñ<Ðäˆw‹<˜!ÒÜ‘&Ð2Ó3Ô4Øäˆw‹<˜!ÒÜ‘%Ð/Ó0Ô1Øô	õ	.ö		1÷"	ô "	÷H'	gò '	gõR	ð0 �=Ò!Ø! -Ñ0‰KàˆKð ˆØò 	1ˆFÙ4°VÓ<ˆNÙ!Ø&'�Ô#Ø˜q’=©Ü™%Ð IÈFÑ RÓSÔTØØ× Ñ  Õ0ð	1ð ×ÒØ˜1Š}¡VÜ‘eÐXÓYÔZÙ$Ø "�à'ò 	1ˆJØ˜1Š}Ü‘gÐ7¸*×:MÑ:MÑMÓNÔOÙ�zÐ0 KÔ0ð	1ð
 ×Ñ !Ò#ÙÜ˜4 Ô1ØÜ—‘˜×,Ñ,Ô-ð
.Ü"Ð#]Ðjn×j}Ñj}Ô~Ð~ð $øô ò .à×&Ñ&¨!Ò+ä&Ð'aÓbÐbÜ‘eÐVÓWÔXÜ˜4 Ô1ÙÜ—‘˜×,Ñ,Ö-ð.ús   È4I ÉA J0ÊJ0Ê/J0)	r   r   r   r9   r#   rA   r   r§   Ú__classcell__)r/   s   @r   r'   r'   '   s)   ø„ Ø-€Dô ô
)
ðV ñP.ó ôP.r   r'   )r   r¢   r{   rZ   rJ   Úargparser   Údjango.appsr   Údjango.confr   Údjango.core.management.baser   Ú0django_extensions.management.email_notificationsr   Ú"django_extensions.management.utilsr   r
   r   rn   r   r'   r   r   r   ú<module>r¯      sP   ðã 	Û 
Û Û Û å &å Ý  Ý 4å UÝ <÷ñ òô )ô ôD.Ð&õ D.r   