
    Id                     |    d dl Z d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZ  G d de      Z G d de      Zy)	    N)system_session)CommandCommandErrorOptionSuperCommand)SamDBc                       e Zd ZdZdZ edddedd       ed	d
e       edde      gZdgZ	e
j                  e
j                  e
j                  dZd Zy)cmd_domain_tombstones_expungezZExpunge tombstones from the database.

This command expunges tombstones from the database.z%prog NC [NC [...]] [options]z-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestz--current-timezQThe current time to evaluate the tombstone lifetime from, expressed as YYYY-MM-DD)r   r   z--tombstone-lifetimez2Number of days a tombstone should be preserved forznc*)	sambaoptscredoptsversionoptsc                    |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                         }|j                  |      }	t        |t	               |	|      }
|0|.t        d| j                         t        d	| j                         |5t        j                  |d
      }t        t        j                  |            }nt        t        j                               }t        |      dk(  rN|
j                  ddt        j                  dg      }g }|d   d   D ]  }|j                  t!        |              nt#        |      }d}	 |
j%                          d}|
j'                  |||      \  }}|
j/                          | j                  j1                  d||fz         y # t(        $ r#}|r|
j+                          t-        d|      d }~ww xY w)Nr   r   r   current_timetombstone_lifetime)urlsession_infocredentialslpztNote: without --current-time or --tombstone-lifetime only tombstones already scheduled for deletion will be deleted.)filez5To remove all tombstones, use --tombstone-lifetime=0.z%Y-%m-%dr    namingContexts)
expressionbasescopeattrsFT)r   r   z.Failed to expunge / garbage collect tombstonesz-Removed %d objects and %d links successfully
)getget_loadparmget_credentialsr   r   printoutftimestrptimeintmktimelensearchldb
SCOPE_BASEappendstrlisttransaction_startgarbage_collect_tombstones	Exceptiontransaction_cancelr   transaction_commitwrite)selfncskwargsr   r   r   current_time_stringr   r   credssamdbcurrent_time_objr   resncstarted_transactionremoved_objectsremoved_linkserrs                      @/usr/lib/python3/dist-packages/samba/netcmd/domain/tombstones.pyrunz!cmd_domain_tombstones_expunge.run9   s   JJ{+	::j)JJsO$jj8#ZZ(<=##%((,!.*:"'B0 &+=+E  &*ii1 Iyy" *#}}-@*Mt{{+;<=L tyy{+Ls8q=,,"2S^^&6%7  9C C!f-. $

3r7#$ s)C#	V##%"&#>>sLXRd ? f_ 	  "		H*M:; 	<  	V"((*OQTUU	Vs   >)G 	H!G??HN)__name__
__module____qualname____doc__synopsisr   r0   r)   takes_options
takes_argsoptionsSambaOptionsCredentialsOptionsVersionOptionstakes_optiongroupsrF        rE   r
   r
   "   s    7 /H 	tW#JQT3	(g	 	%,`gjkM J ))..--4<rT   r
   c                   (    e Zd ZdZi Z e       ed<   y)cmd_domain_tombstonesz0Domain tombstone and recycled object management.expungeN)rG   rH   rI   rJ   subcommandsr
   rS   rT   rE   rV   rV   p   s    :K:<K	rT   rV   )r'   r-   samba.getoptgetoptrN   
samba.authr   samba.netcmdr   r   r   r   samba.samdbr   r
   rV   rS   rT   rE   <module>r^      s7   2  
  % D D K<G K<\=L =rT   