o
    {$f                     @  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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
rPd d	lmZ d)ddZG dd deZd*ddZG dd deZd+ddZdZd,ddZd-dd Zd,d!d"Zd.d#d$Z d/d'd(Z!dS )0    )annotationsN)TYPE_CHECKINGList)Path)ArgumentParser   )CLIErrorSilentCLIError)	BaseModel)_SubParsersAction	subparser!_SubParsersAction[ArgumentParser]returnNonec                 C  s8   |  d}|jttdd |  d}|jttdd d S )NmigrateT)func
args_modelallow_unknown_argsgrit)
add_parserset_defaultsr   MigrateArgsr   GritArgs)r   sub r   O/var/www/html/dev/env/lib/python3.10/site-packages/openai/cli/_tools/migrate.pyregister   s   

r   c                   @     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         
 r   argsc                 C  s8   t  }zt|g| j W d S  tjy   t d w )Ninstall
subprocess
check_callr   CalledProcessErrorr	   r&   	grit_pathr   r   r   r   $   s   r   c                   @  r   )r   r   r   Nr    r   r   r   r   r   /   r%   r   c                 C  s<   t  }zt|ddg| j W d S  tjy   t d w )Napplyopenair'   r,   r   r   r   r   4   s   r   zcustodian-devr   c                  C  s(   t jd} | d urt| S t d S )NXDG_CACHE_HOMEz.cache)osenvirongetr   home)xdgr   r   r   
_cache_dirD   s   r6   messagestrc                 C  s(   t jdsd S tjd|  d d S )NDEBUGz	[DEBUG]: 
)r1   r2   r3   sysstdoutwrite)r7   r   r   r   _debugL   s   r>   c               	   C  s  t jdkr	tdt jdkrdnd} t d }|d }|d }|d	 }|d
 }| r9t| d t j  |S td|  |jddd | rO|	  t
 }td|  d|  d| }dt d| }t jd| d t n}	|	|}
|
 }|d}|r|D ]}t j| d qtdt||d d d d d  |d d d }td|  |	|}t|d}| D ]}|| qW d    n1 sw   Y  W d    n1 sw   Y  |d! }|jddd t|d"}t jd#kr|j|dd$ n|| W d    n	1 sw   Y  | D ]}|||j  q&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 CLIdarwinmacoslinuxzopenai-pythonz.installbinmarzanozmarzano.tmpz already existszUsing Grit CLI path: T)parentsexist_okzUsing architecture zmarzano--z"https://api.keygen.sh/v1/accounts/z/artifacts/z"Retrieving Grit CLI metadata from r:   errorsz3Could not locate Grit CLI binary - see above errorsdatarelationshipsreleaseidlinksredirectzRedirect URL wbNzcli-binzr:gz)      )filteri  )r;   platformr   r6   existsr>   r<   flushmkdirunlink	_get_archKEYGEN_ACCOUNTr=   httpxClientr3   jsonwrite_manifestopen
iter_bytestarfileversion_info
extractalliterdirrenamenameshutilrmtreer1   removechmod)rS   dir_nameinstall_dir
target_dirtarget_path	temp_filearch	file_namemeta_urlclientresponserI   rH   errorlinkdownload_responsefilechunkunpacked_dirarchiveitemr   r   r   r(   S   sn   










r(   c                  C  s&   t   } ddddd}|| | S )Nx64armarm64)x86_64amd64armv7laarch64)rS   machinelowerr3   )architecturearch_mapr   r   r   rX      s   rX   install_pathrK   c                 C  sd   t | dd|did}t| d }t|d}tj||dd W d    d S 1 s+w   Y  d S )NrD   )re   rK   )installPathbinarieszmanifests.jsonwr   )indent)r8   r   r^   r\   dump)r   rK   manifestmanifest_pathfr   r   r   r]      s   	"r]   )r   r   r   r   )r&   r   r   r   )r&   r   r   r   )r   r   )r7   r8   r   r   )r   r8   )r   r   rK   r8   r   r   )"
__future__r   r1   r;   r\   rf   r`   rS   r)   typingr   r   pathlibr   argparser   rZ   _errorsr   r	   _modelsr
   r   r   r   r   r   r   rY   r6   r>   r(   rX   r]   r   r   r   r   <module>   s6    






K