
    >Tf                         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
mZmZmZmZmZ d dlmZ e
eeeeefZ G d de          Zd	S )
    )BaseCommand)no_style)
connection)Q)	CablePathConsolePortConsoleServerPort	Interface	PowerFeedPowerOutlet	PowerPort)create_cablepathc                   $    e Zd ZdZd Zd Zd ZdS )CommandzNGenerate any missing cable paths among all cable termination objects in NetBoxc                 j    |                     dddd           |                     dddd           d S )	Nz--force
store_trueforcez/Force recalculation of all existing cable paths)actiondesthelpz
--no-inputno_inputz-Do not prompt user for any input/confirmation)add_argument)selfparsers     I/var/www/html/netbox-4.1.3/netbox/dcim/management/commands/trace_paths.pyadd_argumentszCommand.add_arguments   s\    lB 	 	
 	
 	
 	J@ 	 	
 	
 	
 	
 	
    c           	          t          |dz            }| j                            dd|z   dd|z
  z   dt          |           dd	           d
S )zf
        Draw a simple progress bar 20 increments wide illustrating the specified percentage.
           z  [#    z] % )endingN)intstdoutwrite)r   
percentagebar_sizes      r   draw_progress_barzCommand.draw_progress_bar    sc     zA~&&]#.]#h2G]]3z??]]]fhiiiiir   c           	      Z   |d         rt           j                                        }|                                }|r|d         s| j                            | j                            d                     | j                            d| d           t          d          }|dk    r4| j                            | j        	                    d                     d S | j                            d	| d
           t           j                                        
                                \  }}| j                            | j        	                    d| d                     | j                            d           t          j                            t                      t           g          }t          j                    5 }	|D ]}
|	                    |
           	 d d d            n# 1 swxY w Y   t"          D ]x}t%          d          }t'          |d          r|t%          d          z  }|j                            |          }|d         s|                    d          }|                                }|s)| j                            d|j        j         d           | j                            d| d|j        j         d           d}t1          |d          D ]5\  }}t3          |g           |dz  s|                     |dz  |z             6|                     d           | j                            | j        	                    d| d|j        j                              z| j                            | j        	                    d                     d S ) Nr   r   z2WARNING: Forcing recalculation of all cable paths.z%This will delete and recalculate all z$ existing cable paths. Are you sure?zType yes to confirm: yesAbortingz	Deleting z existing cable paths...z
  Deleted z pathsz/Resetting database sequence for CablePath modelF)cable__isnullwireless_link)wireless_link__isnullT)_path__isnullzFound no missing z paths; skippingz
Retracing z cabled z...r      )startd   z
  Retraced r!   z	Finished.)r   objectsallcountr'   r(   styleERRORinputSUCCESSdeleter   opssequence_reset_sqlr   cursorexecuteENDPOINT_MODELSr   hasattrfilter_metaverbose_nameverbose_name_plural	enumerater   r+   )r   model_namesoptionscable_pathspaths_countconfirmationdeleted_count_sequence_sqlr@   sqlmodelparamsoriginsorigins_countiobjs                    r   handlezCommand.handle'   s    7 	(#+//11K%++--K  7:#6 !!$*"2"23g"h"hiii!!mKmmm    %%<==5((K%%dj&8&8&D&DEEEF KO+OOOPPP(04466==??M1Ktz112T}2T2T2TUUWWW KPQQQ%><<XZZ)UUL"$$ (' ( (CNN3''''(( ( ( ( ( ( ( ( ( ( ( ( ( ( (
 % 	i 	iEU+++Fuo.. 9!%8888m**622G7# =!..t.<<#MMOOM  !!"`ek6N"`"`"`aaaKf=ff%+BafffgggA#G1555 D D3 #'''3w D**1s7]+BCCC""3'''Kdj001f1f1fU[Ed1f1fgghhhh$*,,[99:::::s   G--G14G1N)__name__
__module____qualname__r   r   r+   rX    r   r   r   r      sI        [D
 
 
j j j3; 3; 3; 3; 3;r   r   N)django.core.management.baser   django.core.management.colorr   	django.dbr   django.db.modelsr   dcim.modelsr   r   r	   r
   r   r   r   dcim.signalsr   rB   r   r\   r   r   <module>rc      s    3 3 3 3 3 3 1 1 1 1 1 1                   o o o o o o o o o o o o o o o o o o ) ) ) ) ) ) G; G; G; G; G;k G; G; G; G; G;r   