o
    )jy                     @   s   d dl Z d dlmZmZmZ d dlmZ d dlmZ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 e Zd
edefddZ		dd
edeeeef  dee fddZddedee fddZdS )    N)DictOptionalUnion)urlparse)HubApiModelScopeConfig)	FILE_HASH)GitCommandWrapper)ModelFileSystemCache)compute_hash)
get_loggermodel_root_pathreturnc                 C   sn   d }t jt j| dr-t }|| }|dr |d d }t|}|jdd  }|S t| }|	 }|S )N.git   )
ospathexistsjoinr	   Zget_repo_remote_urlendswithr   r
   Zget_model_id)r   model_cacheZgit_cmd_wrapperZgit_urlZu_parsemodel_id r   [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/hub/check_model.pyget_model_id_from_cache   s   

r   
user_agenttokenc                 C   s~  zt | }|dd}dtj|di}td|d}| }dtjv r$|ni |dd	i}z|j||d
\}}	t	|	dkrA|	d }
nd}
W n   d}
Y |j
||
d||d}d}tjtj| dsft| }|D ]M}|d dkrqqh|dur||r{qhtd|d  d|
 d  W dS t|v rttj| |d }||t krqhtd|d  d|
 d  W dS qhW dS    Y dS )z`Check local model repo is latest.
    Check local model repo is same as hub latest version.
    Z___.z
user-agent)r      )timeoutr   ZCI_TESTZSnapshotTrue)r   use_cookiesr   ZmasterT)r   revision	recursiveheadersr"   Nr   TypetreezModel file Namez' is different from the latest version `zQ`,This is because you are using an older version or the file is updated manually.Path)r   replacer   Zget_user_agentr   Zget_cookiesr   environZget_model_branches_and_tagslenZget_model_filesr   r   r   r
   loggerinfor   r   )r   r   r   r   r%   _apicookiesZsnapshot_header_Z	revisionsZlatest_revisionZmodel_filesr   Z
model_fileZlocal_file_hashr   r   r   check_local_model_is_latest!   st   



r2   r   c                 C   sP   | d u s
t j| rdS t }|| z	|j| d W dS  ty'   Y dS w )NF)r   T)r   r   r   r   loginZ	get_model	Exception)r   r   r/   r   r   r   check_model_is_idl   s   
r5   )NN)N)r   typingr   r   r   urllib.parser   Zmodelscope.hub.apir   r   Zmodelscope.hub.constantsr   Zmodelscope.hub.gitr	   Zmodelscope.hub.utils.cachingr
   Zmodelscope.hub.utils.utilsr   Zmodelscope.utils.loggerr   r-   strr   r2   r5   r   r   r   r   <module>   s*   
K