U
    $FZhj                     @   s  d dl Z d dlZzd dlZW n ek
r8   edY nX d dlZd dlZd dlmZm	Z	m
Z
mZmZmZ e	egef ee eee ee f dddZG dd dejZe d	ejejd
ddZedkre jddZejdddddd ejdddddd e ZeejZeejZe sPede dejd ed e szede dejd ed e erede dejd ed eee dS )     Nz@Run `python -m pip install "libcst >= 0.2.5"` to install libcst.)AnyCallableDictListSequenceTuple)	predicateiteratorreturnc                 C   s8   g g f}|D ]}|t | | | q|d |d fS )z!A stable, out-of-place partition.   r   )intappend)r   r	   resultsi r   u/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/../../../bin/fixup_firestore_admin_v1_keywords.py	partition   s    r   c                    @   s   e Zd ZU dZee ed< dddddddd	ddddd
dddddddddddddddddddZeeee f ed< e	j
e	j
e	jdddZdS )firestore_adminCallTransformer)retrytimeoutmetadataCTRL_PARAMS)namecollection_idsnamespace_ids)parentbackup_schedule)r   databasedatabase_id)r   index)r   Z
user_credsZuser_creds_id)r   )r   etag)r   r   Zoutput_uri_prefixr   Zsnapshot_time)r   r   Zinput_uri_prefixr   )r   filter)r   )r   Zshow_deleted)r   r!   Z	page_sizeZ
page_token)r   r   backupZencryption_config)r   update_mask)r   r#   )fieldr#   )Zbulk_delete_documentsZcreate_backup_scheduleZcreate_databaseZcreate_indexZcreate_user_credsZdelete_backupZdelete_backup_scheduleZdelete_databaseZdelete_indexZdelete_user_credsZdisable_user_credsZenable_user_credsZexport_documentsZ
get_backupZget_backup_scheduleZget_database	get_field	get_indexZget_user_credsZimport_documentsZlist_backupsZlist_backup_schedulesZlist_databasesZlist_fieldsZlist_indexesZlist_user_credsZreset_user_passwordZrestore_databaseZupdate_backup_scheduleZupdate_databaseZupdate_fieldMETHOD_TO_PARAMS)originalupdatedr
   c           
   	      s   z|j jj} j| }W n ttfk
r4   | Y S X tdd |j\}}tdd |D r`|S t fdd|\}}|d t	| |t	|d   }}|
dd t| jD  tjtdd t||| D td	d
}	|j|	g| dS )Nc                 S   s   t | j S N)boolkeywordar   r   r   <lambda>[       z;firestore_adminCallTransformer.leave_Call.<locals>.<lambda>c                 s   s   | ]}|j jd kV  qdS )requestN)r,   value).0kr   r   r   	<genexpr>\   s     z<firestore_adminCallTransformer.leave_Call.<locals>.<genexpr>c                    s   | j j jkS r*   )r,   r2   r   r-   selfr   r   r/   a   r0   c                 s   s*   | ]"\}}t j|jt j|d dV  qdS )r2   r2   r,   N)cstArgr2   Name)r3   r.   Zctrlr   r   r   r5   f   s   c              	   S   s2   g | ]*\}}t t d |t j|jdqS )z'{}'r8   )r:   ZDictElementZSimpleStringformatZElementr2   )r3   r   argr   r   r   
<listcomp>j   s
   z=firestore_adminCallTransformer.leave_Call.<locals>.<listcomp>r1   r9   )args)funcattrr2   r'   AttributeErrorKeyErrorr   r@   anylenextendzipr   r:   r;   r   r<   Zwith_changes)
r7   r(   r)   keyZkword_paramsr@   kwargsZctrl_kwargsZ	ctrl_argsZrequest_argr   r6   r   
leave_CallQ   s2    


"


	z)firestore_adminCallTransformer.leave_CallN)__name__
__module____qualname__r   r   str__annotations__r'   r   r:   CallZCSTNoderK   r   r   r   r   r   -   sD   
"r   )transformer)in_dirout_dirc          
   
   C   s   dd t | D }|D ]x}t|d}| }W 5 Q R X t|}||}||| }	|	j	j
ddd t|	d}||j W 5 Q R X qdS )zDuplicate the input dir to the output dir, fixing file method calls.

    Preconditions:
    * in_dir is a real directory
    * out_dir is a real, empty directory
    c                 s   sF   | ]>\}}}|D ].}t j|d  dkrtt j||V  qqdS )r   z.pyN)ospathsplitextpathlibPathjoin)r3   root_filesfr   r   r   r5      s
     zfix_files.<locals>.<genexpr>rT)parentsexist_okwN)rU   walkopenreadr:   Zparse_modulevisitjoinpathrelative_tor   mkdirwritecode)
rS   rT   rR   Z
pyfile_genZfpathr^   srctreer)   Zupdated_pathr   r   r   	fix_files{   s    

rn   __main__a  Fix up source that uses the firestore_admin client library.

The existing sources are NOT overwritten but are copied to output_dir with changes made.

Note: This tool operates at a best-effort level at converting positional
      parameters in client method calls to keyword based parameters.
      Cases where it WILL FAIL include
      A) * or ** expansion in a method call.
      B) Calls via function or method alias (includes free function calls)
      C) Indirect or dispatched calls (e.g. the method is looked up dynamically)

      These all constitute false negatives. The tool will also detect false
      positives when an API method shares a name with another method.
)descriptionz-dz--input-directoryT	input_dirz6the input directory to walk for python files to fix up)requireddesthelpz-oz--output-directory
output_dirz5the directory to output files fixed via un-flatteningzinput directory 'z&' does not exist or is not a directory)filezoutput directory 'z' is not empty)!argparserU   Zlibcstr:   ImportErrorrX   systypingr   r   r   r   r   r   r+   r   ZCSTTransformerr   rY   rn   rL   ArgumentParserparseradd_argument
parse_argsr@   rq   ru   is_dirprintstderrexitlistdirr   r   r   r   <module>   st    R#








