o
    i	                  	   @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ er.d dlmZ dede
edf d	dfd
dZddde
edf deded	dfddZded	e	eeef  fddZdS )    N)Path)TYPE_CHECKINGAnyDictOptionalUnion)msg)	CloudPathsrcdestr	   returnc              	   C   s   ddl }t|tr|j s|jjdd t|}|dr%|ddd}t	|}|j
|d	|d
.}| j
dd}||  W d   n1 sJw   Y  W d   dS W d   dS 1 sbw   Y  dS )zfUpload a file.

    src (Path): The source path.
    url (str): The destination URL to upload to.
    r   NT)parentsaz://azazure   wb)modetransport_paramsrbr   )
smart_open
isinstancer   parentexistsmkdirstr
startswithreplace_transport_paramsopenwriteread)r
   r   r   r   output_file
input_file r%   F/home/ubuntu/.local/lib/python3.10/site-packages/weasel/util/remote.pyupload_file   s$   


"r'   F)forcer(   c             	   C   s   ddl }| r|sdS t| } | dr| ddd} t| }|j| dd|d	-}|jd
d}t|| W d   n1 sAw   Y  W d   dS W d   dS 1 sYw   Y  dS )zDownload a file using smart_open.

    url (str): The URL of the file.
    dest (Path): The destination path.
    force (bool): Whether to force download even if file exists.
        If False, the download will be skipped.
    r   Nr   r   r   r   r   disable)r   compressionr   r   r   )	r   r   r   r   r   r   r    shutilcopyfileobj)r
   r   r(   r   r   r$   r#   r%   r%   r&   download_file%   s"   

"r-   urlc                 C   sN   |  dr%tjd}|stdd td ddlm	} d|
|iS d S )	Nzazure://AZURE_STORAGE_CONNECTION_STRINGzCAzure storage requires a connection string, which was not provided.zFAssign it to the environment variable AZURE_STORAGE_CONNECTION_STRING.r   r   )BlobServiceClientclient)r   osenvirongetr   failsysexitazure.storage.blobr0   from_connection_string)r.   connection_stringr0   r%   r%   r&   r   >   s   

r   )r2   r+   r6   pathlibr   typingr   r   r   r   r   wasabir   cloudpathlibr	   r   r'   boolr-   r   r%   r%   r%   r&   <module>   s(    

"