
                             S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  S rS	 rS
 rS r " S S\5      rS rS r " S S\5      rg)z%Utilities for Backup and DR commands.    N)tz)arg_parsers)
exceptions)iso_duration)timesc                  >    [        [        R                  " 5       5      $ N)struuiduuid4     /lib/googlecloudsdk/command_lib/backupdr/util.pyGenerateRequestIdr      s    	TZZ\	r   c                     [        U 5      S-   $ )Ns)r
   )durations    r   ConvertIntToStrr      s    	X	r   c                     U c  gU [         R                  " 5       :  a&  [        R                  " USR	                  U 5      5      eU R                  [        R                  " 5       5      n U R                  S5      $ )z&Verify that the date is in the future.NzDate must be in the future: {0}z%Y-%m-%dT%H:%M:%SZ)	r   Nowr   InvalidArgumentExceptionformat
astimezoner   tzutcstrftime)dateflags     r   VerifyDateInFuturer   #   sb    	\	EIIK

-
-)006  
	$$	+	,,r   c                      g)Nz0001-01-01T00:00:00.000Zr   r   r   r   ResetEnforcedRetentionr    0   s    	#r   c                   $    \ rS rSrSrS rS rSrg)OptionsMapValidator4   zYOption that are passed as key(alternative) value(actual) pairs are validated on the args.c                 ^    U Vs0 s H  o"R                  5       X   _M     snU l        g s  snf r	   )upperoptions)selfr&   opts      r   __init__OptionsMapValidator.__init__7   s&    9@A#IIK-ADLAs   *c                    UR                  5       U R                  R                  5       ;   a  U R                  UR                  5          $ XR                  R                  5       ;   a  U$ [        R
                  " SR                  USR                  [        U R                  R                  5       5      [        U R                  R                  5       5      -   5      5      5      eNz7Failed to parse the arg ({}). Value should be one of {}, )	r%   r&   keysvaluesr   ArgumentTypeErrorr   joinlistr'   r   s     r   ParseOptionsMapValidator.Parse:   s    wwyDLL%%''\\!'')$$	
ll!!#	#h))
C
J
Jiit||((*+d4<<3F3F3H.II r   )r&   N__name__
__module____qualname____firstlineno____doc__r)   r4   __static_attributes__r   r   r   r"   r"   4   s    aBr   r"   c                    [        U [        5      (       a  U R                  S0 5      nOU R                  nU(       d  gSnSnSnSn[        R
                  " U5      R                  n[        R                  " Xe-  5      nXe-  n[        R                  " X-  5      n	X-  n[        R                  " X-  5      n
X-  n[        R                  " X-  5      n[        R                  " XyXS9n[        R                  " USS	9$ )
zTransforms the backup vault enforced retention to a human readable format.

Args:
  backup_vault: type of backup_vault can be either a Backup vault object or a
    dict.

Returns:
  Human readable format of backup vault enforced retention.
&backupMinimumEnforcedRetentionDuration i  iQ ip ( i>)yearsmonthsdayshours)parts)
isinstancedictgetr>   r   ParseDurationtotal_secondsmathfloorceilr   DurationFormatDuration)backup_vaultbackup_min_enforced_retentionseconds_in_hourseconds_in_dayseconds_in_monthseconds_in_yearsecondsyearremaining_secondsmonthdayhourr   s                r   TransformEnforcedRetentionr\   J   s     d##$0$4$40"%!
 	;; " 
'/./ =>LL'	G-	.$/
**&9
:%'

$56#%	$6	7$""S( 
		hb	11r   c                    ^ [         R                  " U4S jSR                  U 5      SR                  T5      -   [        5      nU$ )Nc                    > U T;   $ r	   r   )argr&   s    r   <lambda>#GetOneOfValidator.<locals>.<lambda>w   s	    #.r   z#{} should be one of the following: r-   )r   CustomFunctionValidatorr   r1   r
   )namer&   validtors    ` r   GetOneOfValidatorre   u   s<    00 +2248499W;MM	(
 
/r   c                   $    \ rS rSrSrS rS rSrg)
EnumMapper~   zMaps the args to Enum values.c                     Xl         g r	   enum_mapping)r'   rk   s     r   r)   EnumMapper.__init__   s    $r   c                     XR                   ;   a  U R                   U   $ [        R                  " SR                  USR	                  [        U R                   R                  5       5      5      5      5      er,   )rk   r   r0   r   r1   r2   r.   r3   s     r   r4   EnumMapper.Parse   sc    q!!))
C
J
JiiT..33567 r   rj   Nr6   r   r   r   rg   rg   ~   s    %%	r   rg   )r;   rK   r   dateutilr   googlecloudsdk.callioper   r   googlecloudsdk.core.utilr   r   r   r   r   r    objectr"   r\   re   rg   r   r   r   <module>rs      sV    ,    / . 1 *
-$& ,(2V r   