HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/openai/cli/_tools/__pycache__/migrate.cpython-310.pyc
o

���g��@sddlmZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlZddlmZmZddlmZe	rLdd	l
mZd)dd�ZGdd�de�Zd*dd�ZGdd�de�Zd+dd�ZdZd,dd�Zd-dd �Zd,d!d"�Zd.d%d&�Zd/d'd(�Z dS)0�)�annotationsN)�
TYPE_CHECKING�List)�Path)�ArgumentParser�)�CLIError�SilentCLIError)�	BaseModel)�_SubParsersAction�	subparser�!_SubParsersAction[ArgumentParser]�return�NonecCs8|�d�}|jttdd�|�d�}|jttdd�dS)N�migrateT)�func�
args_model�allow_unknown_args�grit)�
add_parser�set_defaultsr�MigrateArgsr�GritArgs)r�sub�r�D/usr/local/lib/python3.10/dist-packages/openai/cli/_tools/migrate.py�registers

rc@�eZdZUgZded<dS)r�	List[str]�unknown_argsN��__name__�
__module__�__qualname__r�__annotations__rrrrr�
r�argscCs8t�}zt�|g|j��WdStjyt�d�w�N��install�
subprocess�
check_callr�CalledProcessErrorr	�r&�	grit_pathrrrr#s�rc@r)rrrNr rrrrr.r%rcCs<t�}zt�|ddg|j��WdStjyt�d�w)N�apply�openair(r-rrrr3s�rz
custodian-devrcCs(tj�d�}|durt|�St��dS)N�XDG_CACHE_HOMEz.cache)�os�environ�getr�home)�xdgrrr�
_cache_dirCsr7�message�strcCs(tj�d�sdStj�d|�d��dS)N�DEBUGz	[DEBUG]: �
)r2r3r4�sys�stdout�write)r8rrr�_debugKsr?c	Cstjdkr	td��td�tjdkrdnd}t�d}|d}|d	}|d
}|d}|��r=t|�d��tj��|Std
|���|jddd�|��rS|�	�t
�}td|���d|�d|��}d|�d�}tj�d|�d��t�
��<}	|	j|dd�}
|
jdkr�td|����t|d��}|
��D]}|�|�q�Wd�n1s�wYWd�n1s�wY|d}
|
jddd�t�|d��}tjdkr�|j|
dd �n|�|
�Wd�n1s�wYt|
|�t�|
�t�|�t�|d!�tj��|S)"z<Installs the Grit CLI and returns the location of the binary�win32z1Windows is not supported yet in the migration CLIz Using Grit installer from GitHub�darwinzapple-darwinzunknown-linux-gnuz
openai-pythonz.install�binrzgrit.tmpz already existszUsing Grit CLI path: T)�parents�exist_okzUsing architecture zgrit-�-z;https://github.com/getgrit/gritql/releases/latest/download/z.tar.gzzDownloading Grit CLI from r;)�follow_redirects��z!Failed to download Grit CLI from �wbNzcli-binzr:gz)���data)�filteri�)r<�platformrr?r7�existsr=�flush�mkdir�unlink�	_get_archr>�httpx�Clientr4�status_code�open�
iter_bytes�tarfile�version_info�
extractall�_move_files_recursively�shutil�rmtreer2�remove�chmod)rM�dir_name�install_dir�
target_dir�target_path�	temp_file�arch�	file_name�download_url�client�download_response�file�chunk�unpacked_dir�archiverrrr)Rs^




����

��



r)�
source_dirrbcCs>|��D]}|��r|�||j�q|��rt||�qdSr')�iterdir�is_file�rename�name�is_dirr[)rnrb�itemrrrr[�s
��r[cCs&t����}ddddd�}|�||�S)N�x86_64�aarch64)ru�amd64�armv7l�arm64)rM�machine�lowerr4)�architecture�arch_maprrrrR�s�rR)rr
rr)r&rrr)r&rrr)rr)r8r9rr)rnrrbrrr)rr9)!�
__future__rr2r<r\rXrMr*�typingrr�pathlibr�argparserrS�_errorsrr	�_modelsr
rrrrrr�KEYGEN_ACCOUNTr7r?r)r[rRrrrr�<module>s4






?