
                         Z   S 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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SKJr  SSKJr  SSKr " S S\R.                  5      r " S S\R.                  5      r " S S\R.                  5      rS rS rS rS rS rS r S r!S r"S r#S r$g)z,Utilities for Data Catalog entries commands.    )absolute_import)division)unicode_literals)messages)encoding)entries)util)
exceptions)	arg_utils)log)yamlNc                       \ rS rSrSrSrg)InvalidSchemaError!   z*Error if a schema is improperly specified. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       ;lib/googlecloudsdk/command_lib/data_catalog/entries/util.pyr   r   !   s    2r   r   c                       \ rS rSrSrSrg)InvalidSchemaFileError%   z1Error if a schema file is not valid JSON or YAML.r   Nr   r   r   r   r   r   %   s    9r   r   c                       \ rS rSrSrSrg)UnderSpecifiedEntryError)   z;Error if an entry resource argument is not fully specified.r   Nr   r   r   r   r   r   )   s    Cr   r   c                 v    A UR                  S5      (       a!  UR                  R                  SS5      Ul        U$ )a  Returns the update request with the corrected mask.

The API expects a request with an update mask of 'schema', whereas the inline
schema argument generates an update mask of 'schema.columns'. So if --schema
was specified, we have to correct the update mask.

Args:
  ref: The entry resource reference.
  args: The parsed args namespace.
  request: The update entry request.

Returns:
  Request with corrected update mask.
schemazschema.columns)IsSpecified
updateMaskreplacerefargsrequests      r   CorrectUpdateMaskr*   -   s9     
	h ++334DhOG	.r   c                     U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )Nadd_file_patternsremove_file_patternsclear_file_patterns)r#   )r(   s    r   _IsChangeFilePatternSpecifiedr/   B   s>    


.
/ 2


1
22


0
13r   c                 Z   [        U5      (       d  U$ A UR                  R                  R                  5       n[        R
                  " 5       R                  U5      R                  R                  =(       d    / nUR                  S5      (       a  / nUR                  S5      (       a.  [        UR                  5      nU Vs/ s H  ofU;  d  M
  UPM     nnUR                  S5      (       a  XAR                  -  n[        R                  " USU5        U=R                  S-  sl        U$ s  snf )zMerges user-provided GCS file patterns with existing patterns.

Args:
  ref: The entry resource reference.
  args: The parsed args namespace.
  request: The update entry request.

Returns:
  Request with merged GCS file pattern.
r.   r-   r,   z>googleCloudDatacatalogV1beta1Entry.gcsFilesetSpec.filePatternsz,gcsFilesetSpec.filePatterns)r/   CONCEPTSentryParser   EntriesClientGetgcsFilesetSpecfilePatternsr#   setr-   r,   r   SetFieldInMessager$   )r'   r(   r)   	entry_reffile_patterns	to_removebs          r   MergeGcsFilePatternsr>   H   s    
't	,	,N	mm!!''))'')--302 	+,,M	,--D--.I -D1)1CQMD	)**+++MO 
66	. Es    	D(D(c                 F    A [         R                  " UR                  U5      $ N)r   ParseResourceIntoLookupRequestresourcer&   s      r   rA   rA   k   s    			/	/w	GGr   c                    A UR                   R                  R                  5       nUR                  S5      (       a  U(       d  [	        S5      eU(       a  UR                  S5      (       d  U(       d-  UR                  S5      (       d  [
        R                  " SS5      eU(       a  UR                  5       Ul        U$ [        R                  " 5       nUR                  UR                  5      R                  Ul        U$ )ar  Parses the entry into the request, performing a lookup first if necessary.

Args:
  ref: None.
  args: The parsed args namespace.
  request: The update entry request.

Returns:
  Request containing the parsed entry.
Raises:
  UnderSpecifiedEntryError: if ENTRY was only partially specified.
  RequiredMutexGroupError: if both or neither ENTRY, --lookup-entry specified.
r2   zYArgument [ENTRY : --entry-group=ENTRY_GROUP --location=LOCATION] was not fully specified.lookup_entryzJ([ENTRY : --entry-group=ENTRY_GROUP --location=LOCATION] | --lookup-entry))r1   r2   r3   r#   r   concept_exceptionsRequiredMutexGroupErrorRelativeNamenamer   r4   LookuprD   )r'   r(   r)   r:   clients        r   LookupAndParseEntryrK   p   s     
mm!!''))
 
gy
"	    T%%n55T--n==

4
4   ))+GL 
. ""$F==!2!2388GL	.r   c                      [         R                  " U 5      n[        U5      $ ! [         R                   a  n[        SR	                  U5      5      eS nAff = f)NzError parsing schema file: [{}])r   loadYAMLParseErrorr   format_SchemaToMessage)schema_filer"   es      r   ProcessSchemaFromFilerS      sT    NYY{#F 
&	!! 
		 N
 !B!I!I!!L
MMNs   # AAAc                 r   [         R                  " 5       n [        R                  " SU 0UR                  5      n[        U5      nU(       a!  S/nXT-  n[        SR                  U5      5      eU$ ! [
         a    [        S5      e[        R                   a  n[        SR                  U5      5      eSnAff = f)zConverts the given schema dict to the corresponding schema message.

Args:
  schema: dict, The schema that has been processed.

Returns:
  googleCloudDatacatalogV1betaSchema
Raises:
  InvalidSchemaError: If the schema is invalid.
columnsztInvalid schema: expected list of column names along with their types, modes, descriptions, and/or nested subcolumns.zInvalid schema: [{}]Nz6Invalid schema, the following fields are unrecognized:
)api_utilGetMessagesModuler   DictToMessage#GoogleCloudDatacatalogV1beta1SchemaAttributeErrorr   	_messagesValidationErrorrO   _GetUnrecognizedFieldPathsjoin)r"   r   schema_messagerR   unrecognized_field_pathserror_msg_liness         r   rP   rP      s     '')(?++	FXIIKN 8GOPO/O
TYY7
88	 
 :
	9: : 
	"	" ? 3::1=
>>?s   #A/ /(B6B11B6c                    [         R                  " U 5      n/ nU HZ  u  p4SR                  S U 5       5      nUR                  SSS5      nU H$  nUR	                  SR                  UU5      5        M&     M\     [        U5      $ )z?Returns the field paths for unrecognized fields in the message..c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr@   )six	text_type).0rR   s     r   	<genexpr>-_GetUnrecognizedFieldPaths.<locals>.<genexpr>   s     !M<Lq#--"2"2<Ls   #%rU       z{}.{})r   UnrecognizedFieldIterr_   r%   appendrO   sorted)messageerrorsra   edges_to_messagefield_namesmessage_field_path
field_names          r   r^   r^      s    ))'2&'-#!M<L!MM+33Ir1E!
%%gnn5G5?'A B "	 (. 
(	))r   c                 t    [         R                  R                  SR                  UR                  5      5        g )NzStarred entry [{}].r   outPrintrO   r2   _r(   s     r   LogStarSuccessr|      s"    ''--%,,TZZ89r   c                 t    [         R                  R                  SR                  UR                  5      5        g )NzUnstarred entry [{}].rw   rz   s     r   LogUnstarSuccessr~      s"    ''--'..tzz:;r   )%r   
__future__r   r   r   apitools.base.protorpcliter   r\   apitools.base.pyr   #googlecloudsdk.api_lib.data_catalogr   r	   rW   #googlecloudsdk.command_lib.conceptsr
   rE   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   rf   Errorr   r   r   r*   r/   r>   rA   rK   rS   rP   r^   r|   r~   r   r   r   <module>r      s    3 &  ' < % 7 @ P : * # $ 
3)) 3:Z-- :Dz// D*3 FH
$N"D*:<r   