
    =[j7                       d Z ddlmZ ddlmZ ddlZddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ  ej        d
          Zddd5dZe                     d           ej!        dd           ej"        ddd          dddddeef	d6d,            Z#e                     d-           ej!        d.d/           ej"        d.d0d1           ej"        ddd          dddddeef
d7d4            Z$dS )8zDrive commands.    )annotations)PathN)CLIAbort	get_stateresolve_drive_nodeservice_callwrite_response_to_pathnormalize_drive_node)
DEFAULT_LOG_LEVELDEFAULT_OUTPUT_FORMATHttpProxyOptionHttpsProxyOptionLogLevelOptionNoVerifySslOptionOutputFormatOptionSessionDirOptionUsernameOptionstore_command_options)console_table)DriveServicez'Browse and download iCloud Drive files.)helpFtrashdriver   pathstrr   boolc               r    	 t          | ||          S # t          $ r}t          d|           |d}~ww xY w)z6Resolve a drive path or raise a user-facing CLI error.r   zPath not found: N)r   KeyErrorr   )r   r   r   errs       c/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pyicloud/cli/commands/drive.py_resolve_drive_node_or_abortr#   #   sT    
;!%U;;;; ; ; ;0$0011s:;s    
616list/z#Drive path, for example /Documents.z--trashz%Resolve the path from the trash root.ctxtyper.Contextusernamer   session_dirr   
http_proxyr   https_proxyr   no_verify_sslr   output_formatr   	log_levelr   returnNonec
                   t          | |||||||	           t          |           }
|
                                t          dfdj                  }t          |||          }|j        dk    rwt          |          }|
j        r|
	                    |           dS |
j
                            t          dg d	|d
         |d         |d         |d         fg                     dS d |                                D             }|
j        r|
	                    |           dS |
j
                            t          d| g d	d |D                                  dS )z&List a drive folder or inspect a file.r(   r)   r*   r+   r,   r-   r.   Drivec                      j         S Nr   apis   r"   <lambda>zdrive_list.<locals>.<lambda>K   	    #)     account_namer   fileNz
Drive Item)NameTypeSizeModifiednametypesizemodifiedc                ,    g | ]}t          |          S  r
   ).0childs     r"   
<listcomp>zdrive_list.<locals>.<listcomp>b   s!    LLLu#E**LLLr;   zDrive: c                J    g | ] }|d          |d         |d         |d         f!S )rC   rD   rE   rF   rH   )rI   items     r"   rK   zdrive_list.<locals>.<listcomp>j   sB        ftF|T&\4
;KL  r;   )r   r   get_apir   r=   r#   rD   r   json_output
write_jsonconsoleprintr   get_children)r&   r   r   r(   r)   r*   r+   r,   r-   r.   stater   nodepayloadr8   s                 @r"   
drive_listrW   .   s   " ##	 	 	 	 cNNE
--//C"3"3"3"3#BRSSSE't5AAADyF&t,, 	W%%%F444  
+	 	
 	
 	
 	LL8I8I8K8KLLLG !!!	Md000 #  	
 	
	 	 	 	 	r;   download.zDrive path to the file.z--outputzDestination file path.outputr   c           
        t          | ||||||	|
           t          |           }|                                t          dfdj                  }t          |||          }|j        dk    rt          d          |                    d	          }t          ||           |j
        r,|                    t          |          |j        d
           dS |j                            t          |                     dS )zDownload a Drive file.r2   r3   c                      j         S r5   r6   r7   s   r"   r9   z drive_download.<locals>.<lambda>   r:   r;   r<   r   r>   zOnly files can be downloaded.T)stream)r   rC   N)r   r   rN   r   r=   r#   rD   r   openr	   rO   rP   r   rC   rQ   rR   )r&   r   rY   r   r(   r)   r*   r+   r,   r-   r.   rT   r   rU   responser8   s                  @r"   drive_downloadr_   r   s   $ ##	 	 	 	 cNNE
--//C"3"3"3"3#BRSSSE't5AAADyF6777yyy%%H8V,,, #f++tyAABBB	MF$$$$$r;   )r   r   r   r   r   r   )r&   r'   r   r   r   r   r(   r   r)   r   r*   r   r+   r   r,   r   r-   r   r.   r   r/   r0   )r&   r'   r   r   rY   r   r   r   r(   r   r)   r   r*   r   r+   r   r,   r   r-   r   r.   r   r/   r0   )%__doc__
__future__r   pathlibr   typerpyicloud.cli.contextr   r   r   r   r	   pyicloud.cli.normalizer   pyicloud.cli.optionsr   r   r   r   r   r   r   r   r   r   pyicloud.cli.outputr   pyicloud.services.driver   Typerappr#   commandArgumentOptionrW   r_   rH   r;   r"   <module>rn      s     " " " " " "                     8 7 7 7 7 7                        . - - - - - 0 0 0 0 0 0ek@AAA 6;; ; ; ; ; ; V s)NOOO%,yF    $$("&$(',(= 1@ @ @ @ @F Z s)BCCC5<Z6NOOO%,yF    $$("&$(',(= 1&% &% &% &% &% &% &%r;   