a
    _g                     @  s<  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZ d dlZddlmZmZ ddlmZ e	rd d	lmZ d
ddddZG dd deZdddddZG dd deZdddddZdZddddZddddd Zddd!d"Zdddd#d$d%Zddd&d'Z dS )(    )annotationsN)TYPE_CHECKINGList)Path)ArgumentParser   )CLIErrorSilentCLIError)	BaseModel)_SubParsersActionz!_SubParsersAction[ArgumentParser]None)	subparserreturnc                 C  s8   |  d}|jttdd |  d}|jttdd d S )NmigrateT)funcZ
args_modelZallow_unknown_argsgrit)
add_parserset_defaultsr   MigrateArgsr   GritArgs)r   sub r   g/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/openai/cli/_tools/migrate.pyregister   s    

r   c                   @  s   e Zd ZU g Zded< dS )r   	List[str]unknown_argsN__name__
__module____qualname__r   __annotations__r   r   r   r   r      s   
r   )argsr   c                 C  s>   t  }zt|g| j W n tjy8   t d Y n0 d S Ninstall
subprocess
check_callr   CalledProcessErrorr	   r!   Z	grit_pathr   r   r   r   #   s
    r   c                   @  s   e Zd ZU g Zded< dS )r   r   r   Nr   r   r   r   r   r   .   s   
r   c                 C  sB   t  }zt|ddg| j W n tjy<   t d Y n0 d S )NapplyZopenair#   r(   r   r   r   r   3   s
    r   zcustodian-devr   )r   c                  C  s(   t jd} | d urt| S t d S )NXDG_CACHE_HOMEz.cache)osenvirongetr   home)Zxdgr   r   r   
_cache_dirC   s    r/   str)messager   c                 C  s(   t jdsd S tjd|  d d S )NDEBUGz	[DEBUG]: 
)r+   r,   r-   sysstdoutwrite)r1   r   r   r   _debugK   s    r7   c               	   C  s$  t jdkrtdtd t jdkr(dnd} t d }|d }|d	 }|d
 }|d }| rzt| d t j  |S td|  |jddd | r|	  t
 }td|  d| d|  }d| d}t jd| d t ~}	|	j|dd}
|
jdkrtd| t|d*}|
 D ]}|| q0W d   n1 sX0    Y  W d   n1 sx0    Y  |d }|jddd t|d6}t jdkr|j|dd  n
|| W d   n1 s0    Y  t|| t| t| t|d! t j  |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-darwinzunknown-linux-gnuzopenai-pythonz.installbinr   zgrit.tmpz already existszUsing Grit CLI path: T)parentsexist_okzUsing architecture zgrit--z;https://github.com/getgrit/gritql/releases/latest/download/z.tar.gzzDownloading Grit CLI from r3   )Zfollow_redirects   z!Failed to download Grit CLI from wbNzcli-binzr:gz)      data)filteri  )r4   platformr   r7   r/   existsr5   flushmkdirunlink	_get_archr6   httpxZClientr-   status_codeopenZ
iter_bytestarfileversion_info
extractall_move_files_recursivelyshutilrmtreer+   removechmod)rD   dir_nameZinstall_dir
target_dirtarget_path	temp_filearch	file_namedownload_urlclientZdownload_responsefilechunkZunpacked_dirarchiver   r   r   r$   R   sR    



N*



r$   )
source_dirrV   r   c                 C  s>   |   D ]0}| r&|||j  q| rt|| qd S r"   )iterdiris_filerenamenameis_dirrP   )r`   rV   itemr   r   r   rP      s
    rP   c                  C  s&   t   } ddddd}|| | S )Nx86_64aarch64)rg   amd64armv7larm64)rD   machinelowerr-   )architectureZarch_mapr   r   r   rI      s    rI   )!
__future__r   r+   r4   rQ   rM   rD   r%   typingr   r   pathlibr   argparser   rJ   _errorsr   r	   Z_modelsr
   r   r   r   r   r   r   ZKEYGEN_ACCOUNTr/   r7   r$   rP   rI   r   r   r   r   <module>   s2   ?