
    s                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZ G d dej0                        Z G d de      Zy)z5Database Migration Service conversion workspaces API.    )absolute_import)division)unicode_literalsN)api_util)filter_rewrite)
exceptions)
api_helper)labels_util)log)resource_property)filesc                       e Zd ZdZy))UnsupportedConversionWorkspaceDBTypeErrorzHError raised when the conversion workspace database type is unsupported.N)__name__
__module____qualname____doc__     Mlib/googlecloudsdk/api_lib/database_migration/conversion_workspaces_client.pyr   r   $   s    Pr   r   c                      e Zd ZdZdgZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd)dZd)dZd Zd)dZd Z	 d)dZd)dZd)dZd)dZd Z d)d Z!d! Z"d)d"Z#d# Z$d$ Z%d)d%Z&d& Z'd' Z(d)d(Z)y)*ConversionWorkspacesClientz2Client for connection profiles service in the API.display_namec                    t        j                  |      | _        t        j                  |      | _        t        j
                  |      | _        | j                  j                  | _        | j                  j                  | _
        | j                  j                  | _        || _        t        | j                  j                  j                   j"                  | j                  j                  j                   j$                  g      | _        y 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__z#ConversionWorkspacesClient.__init__-   s     ..}=D,,];DK..}=DMKKGGDM![[;;DHH 	 (D )!!99PP!!99NN+ !Dr   c                 `    | j                   j                  j                  j                  |      S r   )r!   DatabaseEngineInfoEngineValueValuesEnumlookup_by_name)r/   database_engines     r   _GetDatabaseEnginez-ConversionWorkspacesClient._GetDatabaseEngine=   s(    ((>>MM	
r   c                 Z    | j                   j                  | j                  |      |      S )N)engineversion)r!   r3   r7   )r/   r6   database_versions      r   _GetDatabaseEngineInfoz1ConversionWorkspacesClient._GetDatabaseEngineInfoD   s/    ==++&&7  ,  r   c                    | j                   j                  }|j                  i |_        d|j                  d<   d|j                  d<   t        j                  ||j
                  d      }| j                  |j                  |j                        }| j                  |j                  |j                        } |||j                  ||      S )zReturns a conversion workspace.*filtertruev2global_settings)globalSettingsdisplayNamesourcedestination)r!   ConversionWorkspacerB   r
   ParseCreateArgsGlobalSettingsValuer<   source_database_enginesource_database_versiondestination_database_enginedestination_database_versionr   )r/   argsconversion_workspace_typerB   rE   rF   s         r   _GetConversionWorkspacez2ConversionWorkspacesClient._GetConversionWorkspaceJ   s     $ A A#d%(D"!'D!11';;=NO ((##T%A%AF --(($*K*KK %&%%	 r   c                     t        | j                        D cg c](  }|j                  |      rt        j                  |      * }}|S c c}w )z)Returns update mask for specified fields.)sorted_FIELDS_MAPIsSpecifiedr   ConvertToCamelCase)r/   rN   fieldupdate_fieldss       r   _GetUpdateMaskz)ConversionWorkspacesClient._GetUpdateMaskb   sU     D,,--EE" 	,,U3-  
 s   -A	c                 p    | j                  |      }|j                  d      r|j                  |_        ||fS )z@Returns updated conversion workspace and list of updated fields.r   )rX   rT   r   rD   )r/   conversion_workspacerN   rW   s       r   _GetUpdatedConversionWorkspacez9ConversionWorkspacesClient._GetUpdatedConversionWorkspacek   s:    ''-M')-):):&..r   c                 p    | j                   j                  |      }| j                  j                  |      S )Nnamer!   <DatamigrationProjectsLocationsConversionWorkspacesGetRequestr#   Get)r/   r^   get_reqs      r   _GetExistingConversionWorkspacez:ConversionWorkspacesClient._GetExistingConversionWorkspacer   s6    mmXX Y G ==W%%r   c                 N    | j                   j                  |j                        S )z,Returns commit conversion workspace request.)
commitName)r!    CommitConversionWorkspaceRequestcommit_namer/   rN   s     r   $_GetCommitConversionWorkspaceRequestz?ConversionWorkspacesClient._GetCommitConversionWorkspaceRequestx   s'    ==99## :  r   c                     | j                   j                  |j                        }||j                         |_        ||j                         |_        |S )z*Returns seed conversion workspace request.
autoCommit)r!   SeedConversionWorkspaceRequestauto_commitRelativeNamesourceConnectionProfiledestinationConnectionProfile)r/   source_connection_profile_ref"destination_connection_profile_refrN   seed_cw_requests        r   "_GetSeedConversionWorkspaceRequestz=ConversionWorkspacesClient._GetSeedConversionWorkspaceRequest~   sg     mmBB## C O %0
'
4
4
6 - *5
,
9
9
; 2 r   c           	      N   g }|D ]a  }	 t        j                  |      }|j                  | j                  j                  |t        j                  j                  |                   c |S # t         j                  $ r& t        j                  ddj                  |            w xY w)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)r/   config_filesrules_filesconfig_filedatas        r   _GetRulesFilesz)ConversionWorkspacesClient._GetRulesFiles   s    K#
%%k2 
--
!
!"$''"2"2;"? "  $  ## 
--188E
 	

s   A++9B$c                    |dk(  r*| j                   j                  j                  j                  S |dk(  r*| j                   j                  j                  j                  S | j                   j                  j                  j
                  S )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)r/   file_formats     r   _GetRulesFormatz*ConversionWorkspacesClient._GetRulesFormat   sw    h
--
1
1
L
L
y
y &&
--
1
1
L
L  B  B 	//JJoor   c                     | j                   j                  |j                  | j                  |j                        | j                  |j                              S )z%Returns import mapping rules request.)rl   
rulesFilesrulesFormat)r!   r   rn   r   r   r   r   rh   s     r   _GetImportMappingRulesRequestz8ConversionWorkspacesClient._GetImportMappingRulesRequest   sO    ==22##&&t'8'89(()9)9: 3  r   c                     | j                   j                  |j                        }|j                  d      r<t	        j
                         j                  |j                        \  |_        }||_        |S )z-Returns convert conversion workspace request.rk   r?   )r!   !ConvertConversionWorkspaceRequestrn   IsKnownAndSpecifiedr   RewriterRewriter?   )r/   rN   convert_req_objserver_filters       r   %_GetConvertConversionWorkspaceRequestz@ConversionWorkspacesClient._GetConvertConversionWorkspaceRequest   sl    mmEE## F O )#1#:#:#<#D#D
++$ dk=  -or   c                     | j                   j                  |j                               }|j                  d      r<t	        j
                         j                  |j                        \  |_        }||_        |S )z+Returns apply conversion workspace request.)connectionProfiler?   )r!   ApplyConversionWorkspaceRequestro   r   r   r   r   r?   )r/   rs   rN   apply_req_objr   s        r   #_GetApplyConversionWorkspaceRequestz>ConversionWorkspacesClient._GetApplyConversionWorkspaceRequest   sq     MMAA<IIK B M )#1#:#:#<#D#D
++$ dk= +mr   c                    |dk(  r*| j                   j                  j                  j                  S |dk(  r*| j                   j                  j                  j                  S | j                   j                  j                  j
                  S )z,Returns the tree type for database entities.SOURCEDRAFT)r!   QDatamigrationProjectsLocationsConversionWorkspacesDescribeDatabaseEntitiesRequestTreeValueValuesEnumSOURCE_TREE
DRAFT_TREEDB_TREE_TYPE_UNSPECIFIED)r/   	tree_types     r   _GetTreeTypez'ConversionWorkspacesClient._GetTreeType   s    H
--
i
i
}
}  J  J G
--
i
i
}
}  I  I 	gg{{  	U  	Ur   c           	         | j                   j                  |j                  ||j                  | j	                  |j
                        ||| j                   j                  j                  j                        }|j                  d      r<t        j                         j                  |j                        \  |_        }||_        |S )zHReturns request to describe database entities in a conversion workspace.)commitIdconversionWorkspaceuncommittedtreepageSize	pageTokenviewr?   )r!   r   	commit_idr   r   r   ViewValueValuesEnumDATABASE_ENTITY_VIEW_FULLr   r   r   r   r?   )r/   conversion_workspace_ref	page_size
page_tokenrN   describe_entities_reqr   s          r   _GetDescribeEntitiesRequestz6ConversionWorkspacesClient._GetDescribeEntitiesRequest   s     !MM{{4$$t~~.]]ll  A  A  [  [ |  )#1#:#:#<#D#D
++$ dk= &3"  r   c                    | j                   j                  |j                  ||j                  | j                   j                  j                  j
                  ||      }|j                  d      r!| j                  |j                        |_	        n/| j                   j                  j                  j                  |_	        |j                  d      r<t        j                         j                  |j                        \  |_        }||_        |S )z2Returns describe ddl conversion workspace request.)r   r   r   r   r   r   r   r?   )r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r?   )r/   r   r   r   rN   describe_ddl_reqr   s          r   _GetDescribeDDLsRequestz2ConversionWorkspacesClient._GetDescribeDDLsRequest   s     }}vv4$$]]ll  A  A  [  [ w  ,"//? --
i
i
}
}  I  I  )#1#:#:#<#D#D
++$ dk= !.r   c           	      \   | j                   j                  |j                  ||j                  || j                   j                  j                  j
                  ||      }|j                  d      r<t        j                         j                  |j                        \  |_
        }||_
        |S )z5Returns describe issues conversion workspace request.)r   r   r   r   r   r   r   r?   )r!   r   r   r   r   r   r   r   r   r   r?   )r/   r   r   r   rN   r   describe_issues_reqr   s           r   _GetDescribeIssuesRequestz4ConversionWorkspacesClient._GetDescribeIssuesRequest  s     --yy4$$]]ll  A  A  [  [ z  )#1#:#:#<#D#D
++$ dk= $1 r   Nc                     | j                  |      }t        j                         }| j                  j                  } |||||      }| j
                  j                  |      S )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)rP   r   GenerateRequestIdr!   ?DatamigrationProjectsLocationsConversionWorkspacesCreateRequestr#   Create)r/   
parent_refconversion_workspace_idrN   rZ   
request_idcreate_req_type
create_reqs           r   r   z!ConversionWorkspacesClient.Create)  sd      77=++-JUU  !05	J ==
++r   c                    | j                  |      }| j                  ||      \  }}t        j                         }| j                  j
                  } ||||dj                  |            }| j                  j                  |      S )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   r^   r   
updateMask)	rc   r[   r   r   r!   >DatamigrationProjectsLocationsConversionWorkspacesPatchRequestjoinr#   Patch)	r/   r^   rN   
current_cwrZ   rW   r   update_req_type
update_reqs	            r   Updatez!ConversionWorkspacesClient.UpdateE  s     55d;J*.*M*MD+'- ++-JTT  !088M*	J ==z**r   c                     t        j                         }| j                  j                  } |||      }| j                  j                  |      S )zDeletes a conversion workspace.

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

    Returns:
      Operation: the operation for deleting the conversion workspace.
    )r^   r   )r   r   r!   ?DatamigrationProjectsLocationsConversionWorkspacesDeleteRequestr#   Delete)r/   r^   r   delete_req_type
delete_reqs        r   r   z!ConversionWorkspacesClient.Deletec  sG     ++-JUU  !djAJ==
++r   c                     | j                   j                  } || j                  |      |      }| j                  j	                  |      S )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
    ) commitConversionWorkspaceRequestr^   )r!   ?DatamigrationProjectsLocationsConversionWorkspacesCommitRequestri   r#   Commit)r/   r^   rN   commit_req_type
commit_reqs        r   r   z!ConversionWorkspacesClient.Commitu  sO     	UU  !)-)R)R*
 	J ==
++r   c                     | j                   j                  } ||| j                   j                               }| j                  j	                  |      S )zRollbacks a conversion workspace.

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

    Returns:
      Operation: the operation for rollbacking the conversion workspace
    )r^   "rollbackConversionWorkspaceRequest)r!   ADatamigrationProjectsLocationsConversionWorkspacesRollbackRequest"RollbackConversionWorkspaceRequestr#   Rollback)r/   r^   rollback_req_typerollback_reqs       r   r   z#ConversionWorkspacesClient.Rollback  sL     	WW  %+/==+[+[+]L
 ==!!,//r   c                     | j                   j                  } ||| j                  |||            }| j                  j	                  |      S )a  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
    )r^   seedConversionWorkspaceRequest)r!   =DatamigrationProjectsLocationsConversionWorkspacesSeedRequestru   r#   Seed)r/   r^   rr   rs   rN   seed_req_typeseed_reqs          r   r   zConversionWorkspacesClient.Seed  sS    0 	SS  '+'N'N).(
H ==h''r   c                     | j                   j                  } ||| j                  |            }| j                  j	                  |      S )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)r/   r^   rN   import_rules_req_typeimport_rules_reqs        r   ImportRulesz&ConversionWorkspacesClient.ImportRules  sN     	aa  -"&"D"DT"J
 &&--.>??r   c                     | j                   j                  } ||| j                  |            }| j                  j	                  |      S )aL  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
    )r^   !convertConversionWorkspaceRequest)r!   @DatamigrationProjectsLocationsConversionWorkspacesConvertRequestr   r#   Convert)r/   r^   rN   convert_req_typeconvert_reqs        r   r   z"ConversionWorkspacesClient.Convert  sM     	VV  #*.*T*T+
K ==  --r   c                     | j                   j                  } ||| j                  ||            }| j                  j	                  |      S )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
    )r^   applyConversionWorkspaceRequest)r!   >DatamigrationProjectsLocationsConversionWorkspacesApplyRequestr   r#   Apply)r/   r^   rs   rN   apply_req_type	apply_reqs         r   r  z ConversionWorkspacesClient.Apply  sO     	TT  (,(P(P.)
I ==y))r   c                 p    | j                   j                  |      }| j                  j                  |      S )zDescribe a conversion worksapce.

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

    Returns:
      Described conversion worksapce Resource.
    r]   r_   )r/   r^   describe_reqs      r   Describez#ConversionWorkspacesClient.Describe
  s8     ==]] ^ L ==\**r   c           
         g }d}t               }| j                  ||||      }	 | j                  j                  |      }|j                  }|D ]s  }	|j                  |	j                  |	j                  |	j                  t        j                  |	j                        j                  dd      | j                  |	      d       u |j                  s	 |S |j                  |_        )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   )
r/   r^   rN   entity_resultr   r   r  responseentitiesentitys
             r   DescribeEntitiesz+ConversionWorkspacesClient.DescribeEntities  s     MIJ33iTL 77Eh**h&"//))KK--(9(9:BB' ++F3
 	  ##   (55l r   c                    d}|j                   D ]u  }|j                  | j                  j                  j                  j
                  k(  r y|j                  | j                  j                  j                  j                  k(  std}w |S )zBGet entity status (Action required/review recommended/ no issues).	NO_ISSUESACTION_REQUIREDREVIEW_RECOMMENDED)issuesseverityr!   r*   r+   r-   r,   )r/   r  r  issues       r   r  z+ConversionWorkspacesClient._GetEntityStatus=  st    F
..]]&&>>SST !
..]]&&>>UUV &  Mr   c                 :   g }d}| j                  ||t               |      }	 | j                  j                  |      }|j                  D ]0  }|j
                  D ]  }|j                  d|j                  i       ! 2 |j                  s	 |S |j                  |_	        {)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#   r  r  	entityDdlr~   r$  r  r   )	r/   r^   rN   entity_ddlsr   r  r  r  
entity_ddls	            r   DescribeDDLsz'ConversionWorkspacesClient.DescribeDDLsM  s     KI//iML
77Eh--& **J


Z^^  + .
 ##   (55l r   c                    g }|j                   D ]  }|j                  | j                  v s|j                  |j                  |j
                  t        j                  |j                        j                  dd      t        j                  |j                        j                  dd      t        j                  |j                        j                  dd      |j                  |j                  d        |S )z%Get issues in a conversion worksapce.r	  r
  ISSUE_TYPE_ISSUE_SEVERITY_)r  r  r  	issueTypeissueSeverity	issueCodeissueMessage)r   r!  r.   r~   r  r  r  r  r  r  typecodemessage)r/   r  entity_issuesr"  s       r   GetIssuesHelperz*ConversionWorkspacesClient.GetIssuesHelperh  s     M	444	4"//))--(9(9:BB' uzz2::="M ]]5>>:BB!2 !MM
 	  r   c                    g }| j                  ||t               ||      }	 | j                  j                  |      }|j                  D ]"  }|j                  | j                  |             $ |j                  s	 |S |j                  |_        m)z*Describe issues in a conversion worksapce.)	r   r  r#   r  r  extendr4  r  r   )	r/   r^   r   rN   r   r3  r  r  r  s	            r   DescribeIssuesHelperz/ConversionWorkspacesClient.DescribeIssuesHelper}  s    M11L 77Eh--&T11&9: .##   (55l r   c                    d}| j                  |||| j                  j                  j                  j                        }|j                  | j                  |||| j                  j                  j                  j                               |S )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  )r7  r!   r   r   r   r6  r   )r/   r^   rN   r   r3  s        r   DescribeIssuesz)ConversionWorkspacesClient.DescribeIssues  s     I--gg{{  	H  	H	M !!MMkk  K  K		
 r   c                 
   	 t        j                  |      }| j                  j                  || j                  j                  |            }t        j                  j                  d|z   dz          | j                  j                  |      }t        j                  ||      }d}|j                   r||k(  rk|t"        j"                  j%                         j'                  d      z   d	z   }	t        j(                  |	|       t        j                  j                  d
|	z          d}t        j(                  ||j                          t        j                  j                  d|z   dz   |z          n"t        j                  j                  d|z          |j*                  r,t        j                  j                  d|j*                  z          |S # t         j                  $ r& t        j                  ddj                  |            w xY w)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-filerw   )
sourceCode)r^   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   rz   r{   r   r|   r}   r!   ;DatamigrationProjectsLocationsConvertApplicationCodeRequestConvertApplicationCodeRequestr   r  Printr%   ConvertApplicationCoder	   #GetTargetFileNameForApplicationCoder;  datetimenowstrftimeWriteFileContentsresultMessage)
r/   r^   source_filetarget_pathsource_codeconvert_application_code_reqconvert_application_code_resptarget_file	convertedbackup_files
             r    ConvertApplicationCodeSingleFilez;ConversionWorkspacesClient.ConvertApplicationCodeSingleFile  s   **;7k $(==#l#l&*mm&Q&Q" 'R '
 $m $  JJ_{25FFG55(	
 " @@[K I$//		###%../?@A 	
 	[9

5C	
 i
4?? 
jj
K
"@
@;
N 
jj9KGH$22	jj
<JJ
J g !! ++

/
6
6{
C s   G	 	9Hc                 ~    t        j                  |d      5 }|j                  |       d d d        y # 1 sw Y   y xY w)NT)r~   )r   
FileWriterwrite)r/   
audit_fileaudit_contentfs       r   WriteAuditContentz,ConversionWorkspacesClient.WriteAuditContent  s7    			
 
ggm	
 
 
s   3<c           	      T   |j                   rL|j                   j                         dk7  r/t        j                  ddj	                  |j                               |j
                  rL|j
                  j                         dk7  r/t        j                  ddj	                  |j
                              |j                  r(| j                  ||j                  |j                         yt        j                  j                  |j                        s/t        j                  dd	j	                  |j                              |j                  rXt        j                  j                  |j                        s/t        j                  d
dj	                  |j                              |j                  s|j                  |_        d}d}t        j                  j                  |j                  d      }| j                  |d       t        j                  |j                        D cg c]K  }t        j                  j!                  t        j                  j                  |j                  |            r|M }}t#        |      D ]   }|dk(  r
|j%                  d      r|dz  }| j                  |t        j                  j                  |j                  |      |j                        rNt&        j&                  j)                         j+                  d      dz   |z   dz   }	| j                  ||	       |dz  }t&        j&                  j)                         j+                  d      dz   |z   dz   }	| j                  ||	       t,        j.                  j1                  d|z   dz          # |dk(  rBt&        j&                  j)                         j+                  d      dz   }	| j                  ||	       t,        j.                  j1                  dt3        |      z   dz   t3        |      z   dz          yc c}w )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_dialectrG  rO  rH  r   r   isdirsource_folderr   rV  listdirisfilerR   endswithrB  rC  rD  r   r  r?  r  )
r/   r^   rN   total_filesconverted_filesrS  rU  source_filesfilerT  s
             r   r@  z1ConversionWorkspacesClient.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--#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P%r   )*r   r   r   r   rS   r1   r7   r<   rP   rX   r[   rc   ri   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r(  r4  r7  r9  rO  rV  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   rB  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   r  Errorr   objectr   r   r   r   <module>rr     sY    < &  '  	 > D . Z < = # : * 
Q0E0E Qw wr   