
    s                         S r SSKJr  SSKJr  SSKJ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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\R0                  5      r " S S\5      rg)z5Database Migration Service conversion workspaces API.    )absolute_import)division)unicode_literalsN)api_util)filter_rewrite)
exceptions)
api_helper)labels_util)log)resource_property)filesc                       \ rS rSrSrSrg))UnsupportedConversionWorkspaceDBTypeError$   zHError raised when the conversion workspace database type is unsupported. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Mlib/googlecloudsdk/api_lib/database_migration/conversion_workspaces_client.pyr   r   $   s    Pr   r   c                   *   \ rS rSrSrS/rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS+S jrS+S jrS rS+S jrS r S+S jrS+S jrS+S jrS+S jr S  r!S+S! jr"S" r#S+S# jr$S$ r%S% r&S+S& jr'S' r(S( r)S+S) jr*S*r+g),ConversionWorkspacesClient(   z2Client for connection profiles service in the API.display_namec                    [         R                  " U5      U l        [         R                  " U5      U l        [         R
                  " U5      U l        U R                  R                  U l        U R                  R                  U l
        U R                  R                  U l        Xl        [        U R                  R                  R                   R"                  U R                  R                  R                   R$                  /5      U l        g N)r   GetApiVersion_api_versionGetClientInstanceclientGetMessagesModulemessages'projects_locations_conversionWorkspaces_serviceprojects_locations_location_service4projects_locations_conversionWorkspaces_mappingRules_mapping_rules_service_release_track	frozensetEntityIssueSeverityValueValuesEnumISSUE_SEVERITY_WARNINGISSUE_SEVERITY_ERRORhigh_severity_issues)selfrelease_tracks     r   __init__#ConversionWorkspacesClient.__init__-   s     ..}=D,,];DK..}=DMKKGGDM![[;;DHH 	 ( )!!99PP!!99NN+ !Dr   c                 `    U R                   R                  R                  R                  U5      $ r   )r%   DatabaseEngineInfoEngineValueValuesEnumlookup_by_name)r3   database_engines     r   _GetDatabaseEngine-ConversionWorkspacesClient._GetDatabaseEngine=   s(    ((>>MM	
r   c                 T    U R                   R                  U R                  U5      US9$ )N)engineversion)r%   r8   r<   )r3   r;   database_versions      r   _GetDatabaseEngineInfo1ConversionWorkspacesClient._GetDatabaseEngineInfoD   s/    ==++&&7  ,  r   c                    U R                   R                  nUR                  c  0 Ul        SUR                  S'   SUR                  S'   [        R                  " XR
                  S5      nU R                  UR                  UR                  5      nU R                  UR                  UR                  5      nU" UUR                  UUS9$ )zReturns a conversion workspace.*filtertruev2global_settings)globalSettingsdisplayNamesourcedestination)r%   ConversionWorkspacerI   r
   ParseCreateArgsGlobalSettingsValuerB   source_database_enginesource_database_versiondestination_database_enginedestination_database_versionr   )r3   argsconversion_workspace_typerI   rL   rM   s         r   _GetConversionWorkspace2ConversionWorkspacesClient._GetConversionWorkspaceJ   s     $ A A#d%(D"!'D!11;;=NO ((##T%A%AF --(($*K*KK %&%%	 r   c                     [        U R                  5       Vs/ s H1  nUR                  U5      (       d  M  [        R                  " U5      PM3     nnU$ s  snf )z)Returns update mask for specified fields.)sorted_FIELDS_MAPIsSpecifiedr   ConvertToCamelCase)r3   rU   fieldupdate_fieldss       r   _GetUpdateMask)ConversionWorkspacesClient._GetUpdateMaskb   sX     D,,--EE" 	4,,U3-  
 s
   AAc                 x    U R                  U5      nUR                  S5      (       a  UR                  Ul        X4$ )z@Returns updated conversion workspace and list of updated fields.r   )r`   r\   r   rK   )r3   conversion_workspacerU   r_   s       r   _GetUpdatedConversionWorkspace9ConversionWorkspacesClient._GetUpdatedConversionWorkspacek   s;    ''-M'')-):):&..r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )Nnamer%   <DatamigrationProjectsLocationsConversionWorkspacesGetRequestr'   Get)r3   rh   get_reqs      r   _GetExistingConversionWorkspace:ConversionWorkspacesClient._GetExistingConversionWorkspacer   s6    mmXX Y G ==W%%r   c                 H    U R                   R                  UR                  S9$ )z,Returns commit conversion workspace request.)
commitName)r%    CommitConversionWorkspaceRequestcommit_namer3   rU   s     r   $_GetCommitConversionWorkspaceRequest?ConversionWorkspacesClient._GetCommitConversionWorkspaceRequestx   s'    ==99## :  r   c                     U R                   R                  UR                  S9nUb  UR                  5       Ul        Ub  UR                  5       Ul        U$ )z*Returns seed conversion workspace request.
autoCommit)r%   SeedConversionWorkspaceRequestauto_commitRelativeNamesourceConnectionProfiledestinationConnectionProfile)r3   source_connection_profile_ref"destination_connection_profile_refrU   seed_cw_requests        r   "_GetSeedConversionWorkspaceRequest=ConversionWorkspacesClient._GetSeedConversionWorkspaceRequest~   sg     mmBB## C O %0
'
4
4
6 - *5
,
9
9
; 2 r   c           	      R   / nU H`  n [         R                  " U5      nUR                  U R                  R                  U[        R                  R                  U5      S95        Mb     U$ ! [         R                   a'    [        R                  " SSR                  U5      5      ef = f)z-Returns the rules files to import rules from.z--config-flies#specified file [{}] does not exist.)rulesContentrulesSourceFilename)r   ReadFileContentsMissingFileErrorr   BadArgumentExceptionformatappendr%   	RulesFileospathbasename)r3   config_filesrules_filesconfig_filedatas        r   _GetRulesFiles)ConversionWorkspacesClient._GetRulesFiles   s    K#
%%k2 
--
!
!"$''"2"2;"? "  $  ## 
--188E
 	

s   A++;B&c                    US:X  a*  U R                   R                  R                  R                  $ US:X  a*  U R                   R                  R                  R                  $ U R                   R                  R                  R
                  $ )z2Returns the file format enum to import rules from.ORA2PGHARBOUR_BRIDGE)r%   ImportMappingRulesRequestRulesFormatValueValuesEnum,IMPORT_RULES_FILE_FORMAT_ORATOPG_CONFIG_FILE4IMPORT_RULES_FILE_FORMAT_HARBOUR_BRIDGE_SESSION_FILE$IMPORT_RULES_FILE_FORMAT_UNSPECIFIED)r3   file_formats     r   _GetRulesFormat*ConversionWorkspacesClient._GetRulesFormat   sw    h
--
1
1
L
L
y
y &&
--
1
1
L
L  B  B 	//JJoor   c                     U R                   R                  UR                  U R                  UR                  5      U R                  UR                  5      S9$ )z%Returns import mapping rules request.)rx   
rulesFilesrulesFormat)r%   r   rz   r   r   r   r   rs   s     r   _GetImportMappingRulesRequest8ConversionWorkspacesClient._GetImportMappingRulesRequest   sO    ==22##&&t'8'89(()9)9: 3  r   c                     U R                   R                  UR                  S9nUR                  S5      (       a<  [        R
                  " 5       R                  UR                  5      u  Ul        nX2l        U$ )z-Returns convert conversion workspace request.rw   rF   )r%   !ConvertConversionWorkspaceRequestrz   IsKnownAndSpecifiedr   RewriterRewriterF   )r3   rU   convert_req_objserver_filters       r   %_GetConvertConversionWorkspaceRequest@ConversionWorkspacesClient._GetConvertConversionWorkspaceRequest   sm    mmEE## F O ))#1#:#:#<#D#D
++$ dk=  -r   c                     U R                   R                  UR                  5       S9nUR                  S5      (       a<  [        R
                  " 5       R                  UR                  5      u  Ul        nXCl        U$ )z+Returns apply conversion workspace request.)connectionProfilerF   )r%   ApplyConversionWorkspaceRequestr{   r   r   r   r   rF   )r3   r   rU   apply_req_objr   s        r   #_GetApplyConversionWorkspaceRequest>ConversionWorkspacesClient._GetApplyConversionWorkspaceRequest   sr     MMAA<IIK B M ))#1#:#:#<#D#D
++$ dk= +r   c                    US:X  a*  U R                   R                  R                  R                  $ US:X  a*  U R                   R                  R                  R                  $ U R                   R                  R                  R
                  $ )z,Returns the tree type for database entities.SOURCEDRAFT)r%   QDatamigrationProjectsLocationsConversionWorkspacesDescribeDatabaseEntitiesRequestTreeValueValuesEnumSOURCE_TREE
DRAFT_TREEDB_TREE_TYPE_UNSPECIFIED)r3   	tree_types     r   _GetTreeType'ConversionWorkspacesClient._GetTreeType   s    H
--
i
i
}
}  J  J G
--
i
i
}
}  I  I 	gg{{  	U  	Ur   c           
         U R                   R                  UR                  UUR                  U R	                  UR
                  5      UUU R                   R                  R                  R                  S9nUR                  S5      (       a<  [        R                  " 5       R                  UR                  5      u  Ul        nXel        U$ )zHReturns request to describe database entities in a conversion workspace.)commitIdconversionWorkspaceuncommittedtreepageSize	pageTokenviewrF   )r%   r   	commit_idr   r   r   ViewValueValuesEnumDATABASE_ENTITY_VIEW_FULLr   r   r   r   rF   )r3   conversion_workspace_ref	page_size
page_tokenrU   describe_entities_reqr   s          r   _GetDescribeEntitiesRequest6ConversionWorkspacesClient._GetDescribeEntitiesRequest   s     !MM{{4$$t~~.]]ll  A  A  [  [ |  ))#1#:#:#<#D#D
++$ dk= &3"  r   c           	      *   U R                   R                  UR                  UUR                  U R                   R                  R                  R
                  UUS9nUR                  S5      (       a!  U R                  UR                  5      Ul	        O/U R                   R                  R                  R                  Ul	        UR                  S5      (       a<  [        R                  " 5       R                  UR                  5      u  Ul        nXel        U$ )z2Returns describe ddl conversion workspace request.)r   r   r   r   r   r   r   rF   )r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   )r3   r   r   r   rU   describe_ddl_reqr   s          r   _GetDescribeDDLsRequest2ConversionWorkspacesClient._GetDescribeDDLsRequest   s     }}vv4$$]]ll  A  A  [  [ w  ,,"//? --
i
i
}
}  I  I  ))#1#:#:#<#D#D
++$ dk= !.r   c           
      `   U R                   R                  UR                  UUR                  UU R                   R                  R                  R
                  UUS9nUR                  S5      (       a<  [        R                  " 5       R                  UR                  5      u  Ul
        nXvl
        U$ )z5Returns describe issues conversion workspace request.)r   r   r   r   r   r   r   rF   )r%   r   r   r   r   r   r   r   r   r   rF   )r3   r   r   r   rU   r   describe_issues_reqr   s           r   _GetDescribeIssuesRequest4ConversionWorkspacesClient._GetDescribeIssuesRequest  s     --yy4$$]]ll  A  A  [  [ z  ))#1#:#:#<#D#D
++$ dk= $1 r   Nc                     U R                  U5      n[        R                  " 5       nU R                  R                  nU" UUUUS9nU R
                  R                  U5      $ )a  Creates a conversion workspace.

Args:
  parent_ref: a Resource reference to a parent
    datamigration.projects.locations resource for this conversion workspace.
  conversion_workspace_id: str, the name of the resource to create.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for creating the conversion workspace.
)r   conversionWorkspaceIdparent	requestId)rW   r   GenerateRequestIdr%   ?DatamigrationProjectsLocationsConversionWorkspacesCreateRequestr'   Create)r3   
parent_refconversion_workspace_idrU   rc   
request_idcreate_req_type
create_reqs           r   r   !ConversionWorkspacesClient.Create)  sd      77=++-JUU  !05	J ==
++r   c                    U R                  U5      nU R                  X25      u  pE[        R                  " 5       nU R                  R
                  nU" UUUSR                  U5      S9nU R                  R                  U5      $ )a  Updates a conversion workspace.

Args:
  name: str, the reference of the conversion workspace to update.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for updating the conversion workspace
,)r   rh   r   
updateMask)	rm   rd   r   r   r%   >DatamigrationProjectsLocationsConversionWorkspacesPatchRequestjoinr'   Patch)	r3   rh   rU   
current_cwrc   r_   r   update_req_type
update_reqs	            r   Update!ConversionWorkspacesClient.UpdateE  s     55d;J*.*M*M+' ++-JTT  !088M*	J ==z**r   c                     [         R                  " 5       nU R                  R                  nU" XS9nU R                  R                  U5      $ )zDeletes a conversion workspace.

Args:
  name: str, the name of the resource to delete.

Returns:
  Operation: the operation for deleting the conversion workspace.
)rh   r   )r   r   r%   ?DatamigrationProjectsLocationsConversionWorkspacesDeleteRequestr'   Delete)r3   rh   r   delete_req_type
delete_reqs        r   r   !ConversionWorkspacesClient.Deletec  sE     ++-JUU  !dAJ==
++r   c                     U R                   R                  nU" U R                  U5      US9nU R                  R	                  U5      $ )a  Commits a conversion workspace.

Args:
  name: str, the reference of the conversion workspace to commit.
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  Operation: the operation for committing the conversion workspace
) commitConversionWorkspaceRequestrh   )r%   ?DatamigrationProjectsLocationsConversionWorkspacesCommitRequestrt   r'   Commit)r3   rh   rU   commit_req_type
commit_reqs        r   r   !ConversionWorkspacesClient.Commitu  sO     	UU  !)-)R)R*
 	J ==
++r   c                     U R                   R                  nU" UU R                   R                  5       S9nU R                  R	                  U5      $ )zRollbacks a conversion workspace.

Args:
  name: str, the reference of the conversion workspace to rollback.

Returns:
  Operation: the operation for rollbacking the conversion workspace
)rh   "rollbackConversionWorkspaceRequest)r%   ADatamigrationProjectsLocationsConversionWorkspacesRollbackRequest"RollbackConversionWorkspaceRequestr'   Rollback)r3   rh   rollback_req_typerollback_reqs       r   r  #ConversionWorkspacesClient.Rollback  sL     	WW  %+/==+[+[+]L
 ==!!,//r   c                     U R                   R                  nU" UU R                  UUU5      S9nU R                  R	                  U5      $ )ac  Seeds a conversion workspace from a connection profile.

Args:
  name: str, the reference of the conversion workspace to seed.
  source_connection_profile_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource for source
    connection profile.
  destination_connection_profile_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource for
    destination connection profile.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for seeding the conversion workspace
)rh   seedConversionWorkspaceRequest)r%   =DatamigrationProjectsLocationsConversionWorkspacesSeedRequestr   r'   Seed)r3   rh   r~   r   rU   seed_req_typeseed_reqs          r   r	  ConversionWorkspacesClient.Seed  sS    0 	SS  '+'N'N).(
H ==h''r   c                     U R                   R                  nU" UU R                  U5      S9nU R                  R	                  U5      $ )a!  Import rules in a conversion workspace.

Args:
  name: str, the reference of the conversion workspace to import rules in.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for importing rules in the conversion workspace
)r   importMappingRulesRequest)r%   KDatamigrationProjectsLocationsConversionWorkspacesMappingRulesImportRequestr   r+   Import)r3   rh   rU   import_rules_req_typeimport_rules_reqs        r   ImportRules&ConversionWorkspacesClient.ImportRules  sN     	aa  -"&"D"DT"J
 &&--.>??r   c                     U R                   R                  nU" UU R                  U5      S9nU R                  R	                  U5      $ )a0  Converts the source entities to draft entities in a conversion workspace.

Args:
  name: str, the reference of the conversion workspace to seed.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for converting the conversion workspace
)rh   !convertConversionWorkspaceRequest)r%   @DatamigrationProjectsLocationsConversionWorkspacesConvertRequestr   r'   Convert)r3   rh   rU   convert_req_typeconvert_reqs        r   r  "ConversionWorkspacesClient.Convert  sM     	VV  #*.*T*T+
K ==  --r   c                     U R                   R                  nU" UU R                  X#5      S9nU R                  R	                  U5      $ )a  applies a conversion workspace onto the destination database.

Args:
  name: str, the reference of the conversion workspace to seed.
  destination_connection_profile_ref: a Resource reference to a
    datamigration.projects.locations.connectionProfiles resource for
    destination connection profile.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Operation: the operation for applying the conversion workspace
)rh   applyConversionWorkspaceRequest)r%   >DatamigrationProjectsLocationsConversionWorkspacesApplyRequestr   r'   Apply)r3   rh   r   rU   apply_req_type	apply_reqs         r   r   ConversionWorkspacesClient.Apply  sM     	TT  (,(P(P.)
I ==y))r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )zDescribe a conversion worksapce.

Args:
  name: str, the name for conversion worksapce being described.

Returns:
  Described conversion worksapce Resource.
rg   ri   )r3   rh   describe_reqs      r   Describe#ConversionWorkspacesClient.Describe
  s8     ==]] ^ L ==\**r   c           
         / nSn[        5       nU R                  XXR5      n U R                  R                  U5      nUR                  nU Hu  n	UR                  U	R                  U	R                  U	R                  [        R                  " U	R                  5      R                  SS5      U R                  U	5      S.5        Mw     UR                  (       d   U$ UR                  Ul        M  )a  Describes database entities in a conversion worksapce.

Args:
  name: str, the name for conversion worksapce being described.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Described entities for the conversion worksapce.
  DATABASE_ENTITY_TYPE_ )parentEntity	shortNamer   
entityTypestatus)strr   r'   DescribeDatabaseEntitiesdatabaseEntitiesr   r+  r,  r   six	text_typer-  replace_GetEntityStatusnextPageTokenr   )
r3   rh   rU   entity_resultr   r   r$  responseentitiesentitys
             r   DescribeEntities+ConversionWorkspacesClient.DescribeEntities  s     MIJ33L 77Eh**h&"//))KK--(9(9:BB' ++F3
 	  ##   (55l r   c                    SnUR                    Hy  nUR                  U R                  R                  R                  R
                  :X  a    gUR                  U R                  R                  R                  R                  :X  d  Mw  SnM{     U$ )zBGet entity status (Action required/review recommended/ no issues).	NO_ISSUESACTION_REQUIREDREVIEW_RECOMMENDED)issuesseverityr%   r.   r/   r1   r0   )r3   r:  r.  issues       r   r5  +ConversionWorkspacesClient._GetEntityStatus=  st    F
..]]&&>>SST !
..]]&&>>UUV &  Mr   c                 L   / nSnU R                  X[        5       U5      n U R                  R                  U5      nUR                   H3  nUR
                   H   nUR                  SUR                  05        M"     M5     UR                  (       d   U$ UR                  Ul	        M  )a  Describe DDLs in a conversion worksapce.

Args:
  name: str, the name for conversion worksapce being described.
  args: argparse.Namespace, the arguments that this command was invoked
    with.

Returns:
  DDLs for the entities of the conversion worksapce.
r(  ddl)
r   r/  r'   r0  r1  	entityDdlr   rF  r6  r   )	r3   rh   rU   entity_ddlsr   r$  r8  r:  
entity_ddls	            r   DescribeDDLs'ConversionWorkspacesClient.DescribeDDLsM  s     KI//ML
77Eh--& **J


Z^^  + .
 ##   (55l r   c                    / nUR                    H  nUR                  U R                  ;   d  M  UR                  UR                  UR
                  [        R                  " UR                  5      R                  SS5      [        R                  " UR                  5      R                  SS5      [        R                  " UR                  5      R                  SS5      UR                  UR                  S.5        M     U$ )z%Get issues in a conversion worksapce.r)  r*  ISSUE_TYPE_ISSUE_SEVERITY_)r+  r,  r-  	issueTypeissueSeverity	issueCodeissueMessage)rA  rB  r2   r   r+  r,  r2  r3  r-  r4  typecodemessage)r3   r:  entity_issuesrC  s       r   GetIssuesHelper*ConversionWorkspacesClient.GetIssuesHelperh  s     M	444	4"//))--(9(9:BB' uzz2::="M ]]5>>:BB!2 !MM
 	  r   c                 ,   / nU R                  UU[        5       UU5      n U R                  R                  U5      nUR                   H#  nUR                  U R                  U5      5        M%     UR                  (       d   U$ UR                  Ul        Mu  )z*Describe issues in a conversion worksapce.)	r   r/  r'   r0  r1  extendrW  r6  r   )	r3   rh   r   rU   r   rV  r$  r8  r:  s	            r   DescribeIssuesHelper/ConversionWorkspacesClient.DescribeIssuesHelper}  s    M11L 77Eh--&T11&9: .##   (55l r   c                    SnU R                  UUUU R                  R                  R                  R                  5      nUR                  U R                  UUUU R                  R                  R                  R                  5      5        U$ )a$  Describe database entity issues in a conversion worksapce.

Args:
  name: str, the name for conversion worksapce being described.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  Issues found for the database entities of the conversion worksapce.
r(  )r[  r%   r   r   r   rZ  r   )r3   rh   rU   r   rV  s        r   DescribeIssues)ConversionWorkspacesClient.DescribeIssues  s     I--gg{{  	H  	H	M !!MMkk  K  K		
 r   c                     [         R                  " U5      nU R                  R                  UU R                  R                  US9S9n[        R                  R                  SU-   S-   5        U R                  R                  U5      n[        R                  " X#5      nSnUR                   (       a  Xr:X  ak  U["        R"                  R%                  5       R'                  S5      -   S	-   n	[         R(                  " X5        [        R                  R                  S
U	-   5        Sn[         R(                  " XvR                   5        [        R                  R                  SU-   S-   U-   5        O"[        R                  R                  SU-   5        UR*                  (       a,  [        R                  R                  SUR*                  -   5        U$ ! [         R                   a'    [        R                  " SSR                  U5      5      ef = f)a  Converts application code.

Args:
  name: str, the name of the location.
  source_file: str, the path of the source file to be converted.
  target_path: str, the path of the target file to be written.

Returns:
  True if the file was converted, False otherwise.
z--source-filer   )
sourceCode)rh   convertApplicationCodeRequestzSending file z for conversionFz_%Y%m%d_%H%M%Sz.bakz'The original file content was saved to TzFile z was converted and saved in z No changes were made to the filezResult message: )r   r   r   r   r   r   r%   ;DatamigrationProjectsLocationsConvertApplicationCodeRequestConvertApplicationCodeRequestr   r.  Printr)   ConvertApplicationCoder	   #GetTargetFileNameForApplicationCodera  datetimenowstrftimeWriteFileContentsresultMessage)
r3   rh   source_filetarget_pathsource_codeconvert_application_code_reqconvert_application_code_resptarget_file	convertedbackup_files
             r    ConvertApplicationCodeSingleFile;ConversionWorkspacesClient.ConvertApplicationCodeSingleFile  s   **;7k $(==#l#l&*mm&Q&Q" 'R '
 $m $  JJ_{25FFG55(	
 " @@K I$//		###%../?@A 	
 	9

5C	
 i
?? 
jj
K
"@
@;
N 
jj9KGH$22	jj
<JJ
J g !! ++

/
6
6{
C s   G ;H	c                     [         R                  " USS9 nUR                  U5        S S S 5        g ! , (       d  f       g = f)NT)r   )r   
FileWriterwrite)r3   
audit_fileaudit_contentfs       r   WriteAuditContent,ConversionWorkspacesClient.WriteAuditContent  s7    			
 
ggm	
 
 
s   1
?c           	         UR                   (       aN  UR                   R                  5       S:w  a0  [        R                  " SSR	                  UR                   5      5      eUR
                  (       aN  UR
                  R                  5       S:w  a0  [        R                  " SSR	                  UR
                  5      5      eUR                  (       a'  U R                  XR                  UR                  5        g[        R                  R                  UR                  5      (       d0  [        R                  " SS	R	                  UR                  5      5      eUR                  (       a^  [        R                  R                  UR                  5      (       d0  [        R                  " S
SR	                  UR                  5      5      eUR                  (       d  UR                  Ul        SnSn[        R                  R                  UR                  S5      nU R                  US5        [        R                  " UR                  5       Vs/ s HS  n[        R                  R!                  [        R                  R                  UR                  U5      5      (       d  MQ  UPMU     nn[#        U5       GH.  nUS:X  a  M  UR%                  S5      (       a  US-  nU R                  U[        R                  R                  UR                  U5      UR                  5      (       aN  [&        R&                  R)                  5       R+                  S5      S-   U-   S-   n	U R                  XY5        US-  nM  [&        R&                  R)                  5       R+                  S5      S-   U-   S-   n	U R                  XY5        GM	  [,        R.                  R1                  SU-   S-   5        GM1     US:X  aA  [&        R&                  R)                  5       R+                  S5      S-   n	U R                  XY5        [,        R.                  R1                  S[3        U5      -   S-   [3        U5      -   S-   5        gs  snf )zConverts application code.

Args:
  name: str, the name of the location.
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  None.

POSTGRESQLz--target-dialectzLspecified target dialect [{}] is not supported. Only POSTGRESQL is supportedORACLEz--source-dialectzHspecified source dialect [{}] is not supported. Only ORACLE is supportedNz--source-folderz0specified source folder [{}] is not a directory.z--target-pathzOspecified target path [{}] is not a directory while source folder is specified.r   zConversion-Audit.txtz	--------
z.java   z%Y-%m-%d %H:%M:%Sz: File z converted
z not converted
zSkipping file z since it is not a java filez): No files found eligible for conversion
zSent z files for conversion, z files were actually converted.)target_dialectupperr   r   r   source_dialectrm  ru  rn  r   r   isdirsource_folderr   r}  listdirisfilerZ   endswithrh  ri  rj  r   r.  re  r/  )
r3   rh   rU   total_filesconverted_filesrz  r|  source_filesfiler{  s
             r   rf  1ConversionWorkspacesClient.ConvertApplicationCode  s    t2288:lJ++
vd112  t2288:hF++
vd112  
++
  $"2"2 WW]]4--..-->EE""
 	
 
		"''--0@0@"A"A--#VD$4$45
 	
 --ko77<< 2 24JKj
Z6 ::d0011aWW^^BGGLL););Q?@ 1  
 &$))
==!!

+22BGGLL!3!3T:D<L<L  !!%%'001DE !!  "":=q O !!%%'001DE %%  "":=
**

%(FF3 ': 
	!!#,,-@A:; 	 	z9	jj
%&  ! .	. cs   AQ'Q')r!   r)   r+   r,   r'   r#   r2   r%   r   ),r   r   r   r   r   r[   r5   r<   rB   rW   r`   rd   rm   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r%  r;  r5  rJ  rW  r[  r^  ru  r}  rf  r   r   r   r   r   r   (   s    : + 0/&(&!*4*,8+<,$,.00 #(J@*..*4+#J 6*(8AFhr   r   )r   
__future__r   r   r   rh  r   )googlecloudsdk.api_lib.database_migrationr   r   googlecloudsdk.callioper   Cgooglecloudsdk.command_lib.database_migration.conversion_workspacesr	   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corecore_exceptionsr   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r2  Errorr   objectr   r   r   r   <module>r     sY    < &  '  	 > D . Z < = # : * 
Q0E0E Qw wr   