o
    W+ iW                     @   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  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   f/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/modelscope/hub/check_model.pyget_model_id_from_cache   s   

r   
user_agentc                 C   s|  zt | }|dd}dtj|di}t }dtjv r|ni |ddi}tdd	}z|j||d
\}}t	|dkr@|d }	nd}	W n   d}	Y |j
||	d||d}
d}tjtj| dset| }|
D ]M}|d dkrpqg|dur||rzqgtd|d  d|	 d  W dS t|v rttj| |d }||t krqgtd|d  d|	 d  W dS qgW 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   ZCI_TESTZSnapshotTrue   )timeout)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_agentZget_cookiesr   environr   Zget_model_branches_and_tagslenZget_model_filesr   r   r   r
   loggerinfor   r   )r   r   r   r$   cookiesZsnapshot_header_api_Z	revisionsZlatest_revisionZmodel_filesr   Z
model_fileZlocal_file_hashr   r   r   check_local_model_is_latest!   st   




r1   r   tokenc                 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   r2   r/   r   r   r   check_model_is_idk   s   
r5   )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   r1   r5   r   r   r   r   <module>   s$   
J