Ë
    qûàg]9  ã                   óî   — 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mZ d dl	m
Z
 d dlmZmZ d dlmZ 	 d dlZdZ	 	 d dlZdZ G d	„ d
e«      Zy# e$ r dZY Œw xY w# e$ r d dlZY Œ&w xY w# e$ r dZY Œ1w xY w)é    N)Úsettings)ÚBaseCommandÚCommandError)Úloader)Ú
ModelGraphÚgenerate_dot)ÚsignalcommandTFc                   óX   ‡ — e Zd ZdZdZˆ fd„Zd„ Zed„ «       Zd
d„Z	d
d„Z
d„ Zd	„ Zˆ xZS )ÚCommandzµCreates a GraphViz dot file for the specified app names. You can pass multiple app names and they will all be combined into a single model. Output is usually directed to a dot file.Tc                 ó�  •— i ddddddœ“ddddd	dœ“d
dddddœ“ddddddœ“ddddddœ“ddddddœ“ddddddœ“ddddddœ“ddddd œ“d!dd"dd#d$œ“d%dd&d'd(d$œ“d)ddd*d+dœ“d,dd-d.d œ“d/dd0d1d œ“d2dd3d4d œ“d5dd6d7d œ“d8dd9d:d;dœ“d<dd:d=dœd<d9d>d?dœddd@dAdœd<d9dBdCdœdddDdEdœdddFg dG¢dHdIœdddJdKdœddLdMg dN¢dOdIœdPœ¥| _         t        t        dQdR«      }|r`| j                   D ]Q  }|j                  dS«      }|dT   j	                  dU«      j                  dUdV«      }||v sŒ=||   | j                   |   dW<   ŒS t        ‰| �  |i |¤Ž yR)XaÃ  
        Allow defaults for arguments to be set in settings.GRAPH_MODELS.

        Each argument in self.arguments is a dict where the key is the
        space-separated args and the value is our kwarg dict.

        The default from settings is keyed as the long arg name with '--'
        removed and any '-' replaced by '_'. For example, the default value for
        --disable-fields can be set in settings.GRAPH_MODELS['disable_fields'].
        z--pygraphvizÚ
store_trueFÚ
pygraphvizz,Output graph data as image using PyGraphViz.)ÚactionÚdefaultÚdestÚhelpz--pydotÚpydotz-Output graph data as image using PyDot(Plus).z--dotÚdotzDOutput graph data as raw DOT (graph description language) text data.z--jsonÚjsonzOutput graph data as JSONz--disable-fields -dÚdisable_fieldsz#Do not show the class member fieldsz--disable-abstract-fieldsÚdisable_abstract_fieldsz7Do not show the class member fields that were inheritedz--group-models -gÚgroup_modelsz5Group models together respective to their applicationz--all-applications -aÚall_applicationsz:Automatically include all applications from INSTALLED_APPSz--output -oÚstoreÚ
outputfileziRender output file. Type of output dependend on file extensions. Use png or jpg to render graph to image.)r   r   r   z--layout -lÚlayoutzaLayout to be used by GraphViz for visualization. Layouts: circo dot fdp neato nop nop1 nop2 twopi)r   r   r   r   z
--theme -tÚthemeÚ
django2018z¬Theme to use. Supplied are 'original' and 'django2018'. You can create your own by creating dot templates in 'django_extentions/graph_models/themename/' template directory.z--verbose-names -nÚverbose_namesz%Use verbose_name of models and fieldsz--language -LÚlanguagez3Specify language used for verbose_name localizationz--exclude-columns -xÚexclude_columnszPExclude specific column(s) from the graph. Can also load exclude list from file.z--exclude-models -XÚexclude_modelszjExclude specific model(s) from the graph. Can also load exclude list from file. Wildcards (*) are allowed.z--include-models -IÚinclude_modelszBRestrict the graph to specified models. Wildcards (*) are allowed.z--inheritance -eTÚinheritancez$Include inheritance arrows (default)Ústore_falsez!Do not include inheritance arrowsÚrelations_as_fieldsz-Do not show relations as fields in the graph.Úrelation_fields_onlyz3Only display fields that are relevant for relationsÚsort_fieldszDo not sort fieldsÚhide_edge_labelsz*Do not show relations labels in the graph.Úarrow_shape)ÚboxÚcrowÚcurveÚicurveÚdiamondr   ÚinvÚnoneÚnormalÚteeÚveezˆArrow shape to use for relations. Default is dot. Available shapes: box, crow, curve, icurve, diamond, dot, inv, none, normal, tee, vee.)r   r   r   Úchoicesr   Úcolor_code_deletionszßColor the relations according to their on_delete setting, where it it applicable. The colors are: red (CASCADE), orange (SET_NULL), green (SET_DEFAULT), yellow (SET), blue (PROTECT), grey (DO_NOTHING) and purple (RESTRICT).ÚTBÚrankdir)r7   ÚBTÚLRÚRLzäSet direction of graph layout. Supported directions: "TB", "LR", "BT", "RL", corresponding to directed graphs drawn from top to bottom, from left to right, from bottom to top, and from right to left, respectively. Default is TB.)z--no-inheritance -Ez--hide-relations-from-fields -Rz--relation-fields-onlyz--disable-sort-fields -Sz--hide-edge-labelsz--arrow-shapez--color-code-deletionsz	--rankdirÚGRAPH_MODELSNú r   ú-Ú_r   )Ú	argumentsÚgetattrr   ÚsplitÚlstripÚreplaceÚsuperÚ__init__)ÚselfÚargsÚkwargsÚdefaultsÚargumentÚ	arg_splitÚsetting_optÚ	__class__s          €úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django_extensions/management/commands/graph_models.pyrF   zCommand.__init__#   s2  ø€ ðT
ØØ&Ø Ø$ØFñ	ðT
ð Ø&Ø ØØGñ	ðT
ð Ø&Ø ØØ^ñ	ðT
ð& Ø&Ø ØØ3ñ	ð'T
ð2 "Ø&Ø Ø(Ø=ñ	$ð3T
ð> (Ø&Ø Ø1ØQñ	*ð?T
ðJ  Ø&Ø Ø&ØOñ	"ðKT
ðV $Ø&Ø Ø*ØTñ	&ðWT
ðb Ø!Ø$ð DñðcT
ðl Ø!Ø Ø Ø{ñ	ðmT
ðx Ø!ØØ'ð Mñ	ðyT
ðD !Ø&Ø Ø'Ø?ñ	#ðET
ðP Ø!Ø"ØMñðQT
ðZ #Ø!Ø)Øjñ%ð[T
ðd "Ø!Ø(ð Eñ$ðeT
ðn "Ø!Ø(Ø\ñ$ðoT
ðx Ø&ØØ%Ø>ñ	!ðyT
ðF (Ø Ø%Ø;ñ	$ð (ØØ-ØGñ	0ð "Ø Ø.ØMñ	'ð (ØØ%Ø,ñ	)ð 'Ø Ø*ØDñ	#ð "Ø Ø%Úvð cñð 'Ø Ø.ð zñ	'ð "ØØ!Ú3ð ñò[T
ˆŒôl œ8 ^°TÓ:ˆáØ ŸN™Nò P�Ø$ŸN™N¨3Ó/�	Ø'¨™l×1Ñ1°#Ó6×>Ñ>¸sÀCÓH�Ø (Ò*Ø:BÀ;Ñ:O�D—N‘N 8Ñ,¨YÒ7ð	Pô 	‰Ñ˜$Ð) &Ó)ó    c                 ó¨   — |j                  dd¬«       | j                  D ]0  } |j                   |j                  d«      i | j                  |   ¤Ž Œ2 y)z/Unpack self.arguments for parser.add_arguments.Ú	app_labelÚ*)Únargsr=   N)Úadd_argumentr@   rB   )rG   ÚparserrK   s      rO   Úadd_argumentszCommand.add_argumentsÏ   sQ   € à×Ñ˜K¨sÐÔ3ØŸ™ò 	RˆHØˆF×Ñ §¡°Ó!4ÐQ¸¿¹ÀxÑ8PÓQñ	RrP   c           
      ó4  — |d   }|s5|d   s0t        t        di «      j                  d«      }|r|}nt        d«      ‚|j                  d«      xs d}t        j
                  j                  |«      \  }}|j                  «       }g d¢}|j                  «       D ��	ci c]  \  }}	||v sŒ||	“Œ }
}}	t        |
j                  «       «      }|d	kD  r.t        d
dj                  |D �cg c]  }d|z  ‘Œ	 c}«      z  «      ‚|d	k(  r!t        d„ |
j                  «       D «       «      }n2|sd}n-|dk(  rd}n%|dk(  rd}nt        rd}nt        rd}nt        d«      ‚|j                  d«      dk7  r|dvrt        d«      ‚|dv r|st        d«      ‚dj                  t        j                   dd  «      }t#        |fd|i|¤Ž}|j%                  «        |dk(  r$|j'                  d¬«      }| j)                  ||«      S |j'                  d ¬«      }|d!   }t        j
                  j                  d"d#|d$«      }t+        j,                  |«      }t/        ||¬%«      }|dk(  r | j0                  |fi |¤ŽS |dk(  r | j2                  |fi |¤ŽS | j5                  ||«       y c c}	}w c c}w )&NrR   r   r<   Ú
app_labelsz&need one or more arguments for appnamer   Ú )r   r   r   r   é   zOnly one of %s can be set.z, z--%sc              3   ó,   K  — | ]  \  }}|sŒ	|–— Œ y ­w©N© )Ú.0ÚkeyÚvals      rO   ú	<genexpr>z!Command.handle.<locals>.<genexpr>ë   s   è ø€ ÒI¡( # sÂSœ#ÑIùs   ‚
�r   z.dotz.jsonr   r   r   z€Neither pygraphviz nor pydotplus could be found to generate the image. To generate text output, use the --json or --dot options.r8   r7   )r   r   r   z7--rankdir is not supported for the chosen output format)r   r   zQAn output file (--output) must be specified when --pydot or --pygraphviz are set.r=   é   Úcli_optionsT)Úas_jsonFr   Údjango_extensionsÚgraph_modelszdigraph.dot)Útemplate)rA   r   Úgetr   ÚosÚpathÚsplitextÚlowerÚitemsÚsumÚvaluesÚjoinÚnextÚHAS_PYGRAPHVIZÚ	HAS_PYDOTÚsysÚargvr   Úgenerate_graph_dataÚget_graph_dataÚrender_output_jsonr   Úget_templater   Úrender_output_pygraphvizÚrender_output_pydotÚprint_output)rG   rH   ÚoptionsÚdefault_app_labelsr   r?   Úoutputfile_extÚoutput_opts_namesÚkÚvÚoutput_optsÚoutput_opts_countÚoptÚoutputrd   rg   Ú
graph_datar   Útemplate_namerh   Údotdatas                        rO   ÚhandlezCommand.handleÕ   s·  € à�{Ñ#ˆÙ˜GÐ$6Ò7Ü!(¬°>À2Ó!F×!JÑ!JÈ<Ó!XÐÙ!Ø)‘ä"Ð#KÓLÐLð —[‘[ Ó.Ò4°"ˆ
ÜŸG™G×,Ñ,¨ZÓ8Ñˆˆ>Ø'×-Ñ-Ó/ˆÚBÐØ(/¯©«×R¡  1¸1Ð@QÒ;Q�q˜!‘tÐRˆÑRÜ × 2Ñ 2Ó 4Ó5ÐØ˜qÒ ÜÐ;¸d¿i¹iÐarÖHsÐZ]ÈÐRUËÒHsÓ>tÑtÓuÐuà Ò!ÜÑI¨k×.?Ñ.?Ó.AÔIÓI‰FÙð ‰FØ˜vÒ%Ø‰FØ˜wÒ&Ø‰FÝØ!‰FÝØ‰Fäð   bó  cð  cà�;‰;�yÓ! TÒ)¨fÐ<ZÑ.ZÜÐXÓYÐYð
 Ð,Ñ,±ZÜÐrÓsÐsà—h‘hœsŸx™x¨¨˜|Ó,ˆÜ! $ÑK°KÐKÀ7ÑKˆØ×(Ñ(Ô*à�VÒØ%×4Ñ4¸TÐ4ÓBˆJØ×*Ñ*¨:°zÓBÐBà!×0Ñ0¸Ð0Ó?ˆ
à˜Ñ ˆÜŸ™Ÿ™Ð%8¸.È%ÐQ^Ó_ˆÜ×&Ñ& }Ó5ˆä˜z°HÔ=ˆà�\Ò!Ø0�4×0Ñ0°ÑD¸GÑDÐDØ�WÒØ+�4×+Ñ+¨GÑ?°wÑ?Ð?Ø×Ñ˜' :Õ.ùói Sùò Its   ÂJÂ(JÃ#Jc                 óä   — t        |t        «      r|j                  «       }|r't        |d«      5 }|j	                  |«       ddd«       y| j
                  j	                  |«       y# 1 sw Y   yxY w)z8Write model data to file or stdout in DOT (text) format.ÚwtN)Ú
isinstanceÚbytesÚdecodeÚopenÚwriteÚstdout)rG   rŠ   Úoutput_fileÚdot_output_fs       rO   r}   zCommand.print_output  sc   € ä�gœuÔ%Ø—n‘nÓ&ˆGáÜ�k 4Ó(ð ,¨LØ×"Ñ" 7Ô+÷,ð ,ð �K‰K×Ñ˜gÕ&÷,ð ,ús   ¯A&Á&A/c                 óÔ   — |r,t        |d«      5 }t        j                  ||«       ddd«       y| j                  j	                  t        j
                  |«      «       y# 1 sw Y   yxY w)z2Write model data to file or stdout in JSON format.r�   N)r‘   r   Údumpr“   r’   Údumps)rG   rˆ   r”   Újson_output_fs       rO   ry   zCommand.render_output_json&  sV   € áÜ�k 4Ó(ð 5¨MÜ—	‘	˜* mÔ4÷5ð 5ð �K‰K×ÑœdŸj™j¨Ó4Õ5÷5ð 5ús   �AÁA'c                 óÌ  — t         st        d«      ‚t        j                  j	                  d«      }	 t        d„ |j                  d«      D «       «      dk  rBt        j                  «       }|j                  |«       |j                  d«       |j                  }t        j                  |«      }|j                  |d   ¬«       |j                  |d	   «       y
# t        $ r Y ŒJw xY w)z,Render model data as image using pygraphviz.z,You need to install pygraphviz python modulez-svnc              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr]   )Úint)r_   rƒ   s     rO   rb   z3Command.render_output_pygraphviz.<locals>.<genexpr>5  s   è ø€ Ò8 ”S˜—VÑ8ùs   ‚ú.)r   é$   r   r   )Úprogr   N)rs   r   r   Ú__version__ÚrstripÚtuplerB   ÚtempfileÚNamedTemporaryFiler’   ÚseekÚnameÚ
ValueErrorÚAGraphr   Údraw)rG   rŠ   rI   ÚversionÚtmpfileÚgraphs         rO   r{   z Command.render_output_pygraphviz.  sÀ   € åÜÐMÓNÐNä×(Ñ(×/Ñ/°Ó7ˆð	ÜÑ8 W§]¡]°3Ó%7Ô8Ó8¸7ÒBä"×5Ñ5Ó7�Ø—‘˜gÔ&Ø—‘˜Q”Ø!Ÿ,™,�ô ×!Ñ! 'Ó*ˆØ�‰˜& Ñ*ˆÔ+Ø�
‰
�6˜,Ñ'Õ(øô ò 	Ùð	ús   ²A&C Ã	C#Ã"C#c                 óp  — t         st        d«      ‚t        j                  |«      }|st        d«      ‚t	        |t
        t        f«      r2t        |«      dkD  rt        j                  j                  d«       |d   }|d   }g d¢}||j                  d«      dz   d	 }||v r|nd
}|j                  ||¬«       y	)z'Render model data as image using pydot.z'You need to install pydot python modulezpydot returned an errorr[   z9Found more then one graph, rendering only the first one.
r   r   ))ÚbmpÚcanonÚcmapÚcmapxÚcmapx_npr   ÚdiaÚemfÚemÚfplusÚepsÚfigÚgdÚgd2ÚgifÚgvÚimapÚimap_npÚismapÚjpeÚjpegÚjpgÚmetafileÚpdfÚpicÚplainz	plain-extÚpngÚpovÚpsÚps2ÚsvgÚsvgzÚtifÚtiffÚtkÚvmlÚvmlzÚvrmlÚwbmpÚxdotr�   NÚraw)Úformat)rt   r   r   Úgraph_from_dot_datarŽ   Úlistr¢   Úlenru   Ústderrr’   Úrfind)rG   rŠ   rI   r¬   r”   ÚformatsÚextÚformat_s           rO   r|   zCommand.render_output_pydotB  s²   € åÜÐHÓIÐIä×)Ñ)¨'Ó2ˆÙÜÐ8Ó9Ð9Ü�eœd¤E˜]Ô+Ü�5‹z˜AŠ~Ü—
‘
× Ñ Ð!]Ô^Ø˜!‘HˆEà˜\Ñ*ˆò
ˆð ˜+×+Ñ+¨CÓ0°1Ñ4Ð5Ð6ˆØ ™‘#¨UˆØ�‰�K¨ˆÕ0rP   r]   )Ú__name__Ú
__module__Ú__qualname__r   Úcan_import_settingsrF   rW   r	   r‹   r}   ry   r{   r|   Ú__classcell__)rN   s   @rO   r   r      sI   ø„ ð C€DàÐôj*òXRð ñC/ó ðC/óJ	'ó6ò)ö(1rP   r   )ru   r   rj   r£   Údjango.confr   Údjango.core.management.baser   r   Údjango.templater   Ú%django_extensions.management.modelvizr   r   Ú"django_extensions.management.utilsr	   r   rs   ÚImportErrorÚ	pydotplusr   rt   r   r^   rP   rO   ú<module>rë      s�   ðã 
Û Û 	Û å  ß AÝ "ç JÝ <ðÛØ€NððÛ!ð €Iô
{1ˆkõ {1øð ò Ø‚Nðûð ò Ýðûð ò Ø‚Iðús@   ´A ¼A Á A* ÁAÁAÁ	A'Á$A* Á&A'Á'A* Á*A4Á3A4