
    ǷiI                         d dl Z d dlZd dlZd dlmZmZ d dlmZmZ d dl	m
Z
mZ  ej        d          ZdZd Z G d d	e          ZdS )
    N)BaseCommandCommandError)DEFAULT_DB_ALIASconnections)AmbiguityErrorMigrationLoaderz\s+replaces\s*=\s*\[[^\]]+\]\s*z.pycc                 B    | d t          t                              dz   S )Nz.py)lenPYC)pyc_fns    x/srv/django_bis/venv311/lib/python3.11/site-packages/django_extensions/management/commands/delete_squashed_migrations.pypy_from_pycr      s    *CHH9*%%    c                   .    e Zd ZdZ	 	 d Zd Zd Zd ZdS )Commandz:Deletes left over migrations that have been replaced by a c                    |                     dd           |                     dd dd           |                     dd	d
ddd           |                     dddd           |                     dt          dt          z             d S )N	app_labelz@App label of the application to delete replaced migrations from.)helpsquashed_migration_name?zPThe squashed migration to replace. If not specified defaults to the first found.)defaultnargsr   z	--noinputz
--no-inputstore_falseinteractiveTz:Tells Django to NOT prompt the user for input of any kind.)actiondestr   r   z	--dry-run
store_trueFz*Do not actually delete or change any files)r   r   r   z
--databasezGNominates a database to run command for. Defaults to the "%s" database.)r   r   )add_argumentr   )selfparsers     r   add_argumentszCommand.add_arguments   s    S 	 	
 	
 	
 	%t3A 	 	
 	
 	

 	m-Y]M 	 	
 	
 	
 	e= 	 	? 	? 	? 	"2Z]mm 	 	
 	
 	
 	
 	
r   c                 	   |d         | _         |d         | _        |d         | _        |d         }|d         }|d         }t          t          |                   |j        vrt          d|z            d }|r?|                     ||          }|j        s t          d|j	        d	|j
        d
          nj                            |          } j        |d          fdj                            j	        j
        f          D             }|gz   }|D ]j        r} n|st          d|z            g }	|j        D ]\  }
}	 j        |
|f         t!          j        j                  }|	                    |           |                    t*                    r$t-          |          }|	                    |           # t.          $ r/ | j         dk    r!| j                            d|
d	|d           Y w xY w| j         dk    s| j        rj| j                            | j                            d                     |	D ]}| j                            d|z              |                                 sd S |	D ]W}	 | j        st=          j        |           # t@          $ r, | j         dk    r| j                            d|d           Y Tw xY wt!          j        |j                  }|                    t*                    rt-          |          }tC          |          5 }tE          |          }d d d            n# 1 swxY w Y   g }tG          |          D ]v\  }}tH          %                    |          rW|                    |           |dk    r:||dz
           &                                dk    r|'                    d|dz
              nw|st          d|d          | j         dk    s| j        r| j                            | j                            d|d         tQ          |          dk    rdtS          |d                   z   ndd|                     |                                 sd S tU          |d          D ]}||= tC          |d          5 }| j        s(|                    d+                    |                     d d d            d S # 1 swxY w Y   d S )N	verbosityr   dry_runr   r   databasezVApp '%s' does not have migrations (so delete_squashed_migrations on it makes no sense)zThe migration  z is not a squashed migration.)appr   c                 X    g | ]&\  }}|j         k                        ||          'S  )r   get_migration).0almnloader	migrations      r   
<listcomp>z"Command.handle.<locals>.<listcomp>H   sE     # # #B,,, $$R,,,,,r   z-Cannot find a squashed migration in app '%s'.z!Couldn't find migration file for 
z Will delete the following files:z - %szCouldn't delete     z(Couldn't find 'replaces =' line in file z%. Please finish cleaning up manually.zWill delete line z and z from file T)reversew),r#   r   r$   r   r   migrated_appsr   find_migrationreplacesr   namegraph
leaf_nodesr*   forwards_plandisk_migrationsinspectgetfile	__class__appendendswithr   r   KeyErrorstderrwritestdoutstyleMIGRATE_HEADINGconfirmosremoveOSErroropenlist	enumerateREPLACES_REGEXmatchstripinsertr
   strsortedjoin)r   optionsr   r   r%   squashed_migrationr;   previous_migrations
migrationsfiles_to_deleter,   r-   pyc_filepy_filefnsquashed_migration_fnfpsquashed_migration_linesdelete_linesilineline_numr.   r/   s                         @@r   handlezCommand.handle-   s    -"=1y)K(	")*C"D:& !X!677F000%'01  
 "" 	!%!4!4VYH_!`!`%. "l'1113E3J3J3JL    00Y0??J,,jm<I# # # # #$l88):My~9^__# # #
 -	{:J'  	% )2&E & "C   
 (1 	4 	4FB4"22r6:	 #?9+>??&&x000$$S)) 4)(33G#**7333  2 2 2>A%%K%%%)+RRR'1 2 2 22 >A!1Kdj889[\\]]]% 0 0!!'B,////<<>> ! 	F 	FBF| "IbMMM F F F>A%%K%%%&DEEEF
 !(0B0L M M ))#.. 	G$/0E$F$F!'(( 	0B'+Bxx$	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0  !9:: 	 	GAt##D)) ##A&&&q555a!e<BBDDJJ ''1q5111	
  	,;P;P;PS  
 >A!1Kdj888a36|3D3Dq3H3H3|A////bPP&&() ) * * * <<>> |T::: 	3 	3H(22'-- 	<< <!9::;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sH   G6HH
J&&3KK0MMM.0S++S/2S/c                     | j         rBd }|r|dvr4t          d          }|sd}n |d                                         }|0|dv4|dk    S dS )NynzDo you wish to proceed? [yN] nr   yT)r   inputlower)r   answers     r   rI   zCommand.confirm   sz     		!F /d 2 2>?? / F#AY__..F  /d 2 2 S= tr   c                     	 |                     ||          S # t          $ r t          d|d|d          t          $ r t          d|d|d          w xY w)Nz!More than one migration matches 'z
' in app 'z'. Please be more specific.z"Cannot find a migration matching 'z' from app 'z'.)get_migration_by_prefixr   r   rC   )r   r.   r   r9   s       r   r7   zCommand.find_migration   s    	11)TBBB 	 	 	,$(DD)))5    	 	 	,yyy"  	s
    A AN)__name__
__module____qualname__r   r!   rf   rI   r7   r)   r   r   r   r      s_        GDG:
 
 
,o< o< o<b      r   r   )rJ   r>   redjango.core.management.baser   r   	django.dbr   r   django.db.migrations.loaderr   r   compilerP   r   r   r   r)   r   r   <module>rx      s    				  				 A A A A A A A A 3 3 3 3 3 3 3 3 G G G G G G G G>??& & &e e e e ek e e e e er   