
    "j              &       (   d Z ddlZddlZddlZddlmZ ddlmZ ddlZddlm	Z	 ddl
mZmZmZmZmZmZmZ ddlmZmZmZmZmZ dd	lmZmZmZmZmZmZ dd
lm Z m!Z!  e	j"        e#          Z$ ed          Z%de&de'fdZ(de&de)e&e&f         fdZ*dde+e,z  de'de&fdZ-ddedz  de'de&fdZ.	 	 dde/eez           de'de'de/e&         fdZ0	 	 	 dde1de/e&         de&de+de+de'ddfd Z2e%3                    d!g d"#          ddde j4        fd$ee& ej5        d%          f         d&ee' ej6        d'd(          f         d)ee' ej6        d*d+          f         d,ed-eddfd.            Z7de&de'fd/Z8e%3                    d0g d1#          dddddde j4        fdee&dz   ej5        d2          f         dee' ej6        d3d4d5          f         d6ee' ej6        d7d8          f         d9ee' ej6        d:d;d<          f         d=ed,ed-eddfd>            Z9d?e&dz  d=e&dz  de'd6e'd9e'd,e&dz  ddfd@Z:de&de'd6e'd9e'd,e&dz  ddfdAZ;e%3                    dBdCdDg#          de j4        fd$ee& ej5        dE          f         d,ed-eddfdF            Z<e%3                    dGg dH#          ddde j4        fd$ee& ej5        dE          f         dIee' ej6        dJdKdL          f         dMee' ej6        dNdO          f         d,ed-eddfdP            Z=e%3                    dQg dR#          dddddde j4        fdee& ej5        dS          f         d9ee' ej6        d:d;dT          f         dIee' ej6        dJdKdL          f         dUee' ej6        dVdW          f         dXee/e&         dz   ej6        dY          f         dZee/e&         dz   ej6        d[          f         d,ed-eddfd\            Z>e%3                    d]g d^#          de j4        fd_ee& ej5        d`          f         daee& ej5        db          f         d,ed-eddf
dc            Z?e%3                    ddg de#          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddfee&dz   ej5        dg          f         dhee&dz   ej5        di          f         dGee' ej6        dj          f         dkee' ej6        dldm          f         dnee' ej6        dodp          f         dqee&dz   ej6        dr          f         dsee&dz   ej6        dt          f         dUee' ej6        dVdu          f         dXee/e&         dz   ej6        dv          f         dZee/e&         dz   ej6        dw          f         dxee&dz   ej6        dy          f         dzee' ej6        d{d|          f         d}ee' ej6        d~d          f         dee' ej6        ddd          f         dee' ej6        ddd          f         d,eddf"d            Z@e%3                    dg d#          dde j4        fdee& ej5        d          f         dee&dz   ej5        d          f         d,ed-eddf
d            ZAdS )z7Contains commands to interact with buckets via the CLI.    N)datetime)	Annotated)logging)BUCKET_PREFIX
BucketFileBucketFolderFilterMatcher_is_bucket_path_parse_bucket_path_split_bucket_id_and_prefix)SoftTemporaryDirectory
StatusLineare_progress_bars_disableddisable_progress_barsenable_progress_bars   )FormatWithAutoOpt	SearchOptTokenOptapi_object_to_dict
get_hf_apityper_factory)OutputFormatWithAutooutz"Commands to interact with buckets.)helppathreturnc                 ,    |                      d          S )Nzhf://)
startswithr   s    e/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/huggingface_hub/cli/buckets.py_is_hf_handler"   ;   s    ??7###    argumentc                     |                      t                    rt          |           S 	 t          |           S # t          $ r t	          d|  dt           d          w xY w)zParse a bucket argument accepting both 'namespace/name(/prefix)' and 'hf://buckets/namespace/name(/prefix)'.

    Returns:
        tuple: (bucket_id, prefix) where bucket_id is "namespace/bucket_name" and prefix may be empty string.
    zInvalid bucket argument: -. Must be in format namespace/bucket_name or znamespace/bucket_name)r   r   r   r   
ValueError)r$   s    r!   _parse_bucket_argumentr(   ?   s     =)) ,!(+++
*8444 
 
 
8 8 8 8 8 8
 
 	

s	   : &A Fsizehuman_readablec                     |st          |           S dD ]&}| dk     r|dk    r	|  d| c S | dd| c S | dz  } '| ddS )zFormat a size in bytes.)BKBMBGBTBi  r,    z.1fz PB)str)r)   r*   units      r!   _format_sizer4   P   s     4yy-  $;;s{{'''''''''''''''r#   mtimec                 b    | dS |r|                      d          S |                      d          S )z0Format mtime datetime to a readable date string.N z%b %d %H:%Mz%Y-%m-%d %H:%M:%S)strftime)r5   r*   s     r!   _format_mtimer9   ^   s9    }r -~~m,,,>>-...r#   itemsquietc                 N   i }| D ]t}|j                             d          }|}|dd         D ]}||vrdi i||<   ||         d         }|d         }t          |t                    r||vrdi i||<   md|i||<   ud}	d}
d}|s| D ]{}t          |t                    rdt          |j        |          }t          |
t          |                    }
t          |j
        |          }t          |t          |                    }||
dk    r|
dz   |z   }	g }t          ||d|	|
|	           |S )
a  Build a tree representation of files and directories.

    Produces ASCII tree with size and date columns before the tree connector.
    When quiet=True, only the tree structure is shown (no size/date).

    Args:
        items: List of BucketFile/BucketFolder items
        human_readable: Whether to show human-readable sizes and short dates
        quiet: If True, show only the tree structure without sizes/dates

    Returns:
        List of formatted tree lines
    /N__children____item__r      r7   prefix_widthmax_size_widthr*   )r   split
isinstancer   r   r4   r)   maxlenr9   r5   _render_tree)r:   r*   r;   treeitempartscurrentpart
final_partrC   rD   max_date_widthsize_strdate_strliness                  r!   _build_treerT   g   s   & D 5 5	$$#2#J 	4 	4D7""!/ 4dmN3GG2Y
dL)) 	5(('5r&:
##-t"4GJ LNN ? 	D 	DD$
++ D'	>BB!$^S]]!C!C(^DD!$^S]]!C!CA)A->L E
!%%    Lr#   noderS   indentrC   rD   c           	      t   t          |                                           }t          |          D ]\  }\  }}	|t          |          dz
  k    }
|
rdnd}d|	v }|	                    di           }|dk    r|rd|z  }nR|	                    d          }|6t          |j        |          }t          |j        |          }|d	| d
| }nd|z  }|	                    | d
| | | |rdnd            n!|	                    | | | |rdnd            |r||
rdndz   }t          ||||||           dS )z:Recursively render a tree structure with size+date prefix.r   u
   └── u
   ├── r?   r   r1   r@   N>  r=   r7   z    u   │   rB   )sortedr:   	enumeraterH   getr4   r)   r9   r5   appendrI   )rU   rS   rV   rC   rD   r*   r:   inamevalueis_last	connectoris_dirchildrenprefixrK   rQ   rR   child_indents                      r!   rI   rI      s    4::<<  E%e,,  =D%s5zzA~%$+=LL	5(99^R00! 	0|+yy,,#+DI~FFH,TZHHH (H>HHHHhHHFF </FLLFVVfViVVf?TssRTVVWWWWLLFLILtLF5JSSLLMMM 		!w%DVVHEL)--   1 r#   create)zhf buckets create my-bucketz hf buckets create user/my-bucketz-hf buckets create hf://buckets/user/my-bucketz*hf buckets create user/my-bucket --privatez+hf buckets create user/my-bucket --exist-ok)r_   examples	bucket_idzTBucket ID: bucket_name, namespace/bucket_name, or hf://buckets/namespace/bucket_nameprivatez	--privatezCreate a private bucket.exist_okz
--exist-okz3Do not raise an error if the bucket already exists.tokenformatc                    t          |          }|                     t                    rk	 t          |           \  }}n3# t          $ r&}t          j        t          |                    d}~ww xY w|r t          j        d|  dt           d          |} |                    | |r|nd|          }	t          j
        d|	j        |	j                   dS )	zCreate a new bucket.rl   Nz-Cannot specify a prefix for bucket creation: . Use namespace/bucket_name or namespace/bucket_name.)rj   rk   zBucket created)handleurl)r   r   r   r(   r'   typerBadParameterr2   create_bucketr   resultrr   rs   )
ri   rj   rk   rl   rm   api	parsed_idre   e
bucket_urls
             r!   rg   rg      s   F 5
!
!
!CM** 
	- 6y A AIvv 	- 	- 	-$SVV,,,	- 	$W	 W W1>W W W   	""", #  J
 J
(9z~NNNNNNs   ? 
A/	!A**A/c                 |    |                      t                    r| t          t                    d         }n| }d|v S )zFCheck if argument is a bucket ID (namespace/name) vs just a namespace.Nr=   )r   r   rH   )r$   r   s     r!   _is_bucket_idr}     sA    =)) M**,,-$;r#   z	list | ls)
zhf buckets listzhf buckets list huggingfacez$hf buckets list --search "my-prefix"zhf buckets list user/my-bucketz!hf buckets list user/my-bucket -Rz!hf buckets list user/my-bucket -hz%hf buckets list user/my-bucket --treez(hf buckets list user/my-bucket --tree -hz+hf buckets list hf://buckets/user/my-bucketz%hf buckets list user/my-bucket/sub -RzyNamespace (user or org) to list buckets, or bucket ID (namespace/bucket_name(/prefix) or hf://buckets/...) to list files.z--human-readablez-hz$Show sizes in human readable format.as_treez--treez3List files in tree format (only for listing files).	recursivez--recursivez-Rz0List files recursively (only for listing files).searchc                     | duot          |           }|r,|t          j        d          t          | ||||           dS t	          | |||||           dS )zList buckets or files in a bucket.

    When called with no argument or a namespace, lists buckets.
    When called with a bucket ID (namespace/bucket_name), lists files in the bucket.
    Nz'Cannot use --search when listing files.)r$   r*   r~   r   rl   )	namespacer   r*   r~   r   rl   )r}   rt   ru   _list_files_list_buckets)r$   r*   r~   r   r   rl   rm   is_file_modes           r!   list_cmdr     s    t 4'CM(,C,CL 
$%NOOO)	
 	
 	
 	
 	
 	
 	)	
 	
 	
 	
 	
 	
r#   r   c                    |rt          j        d          |rt          j        d          | K|                     t                    r1| t	          t                    d         } |                     d          } t          |          }fd|                    | |          D             }t          j	        |ddd	
           dS )zList buckets in a namespace.z'Cannot use --tree when listing buckets.z,Cannot use --recursive when listing buckets.Nr=   ro   c                     g | ]:}|j         |j        rt          |j                  n|j        |j        |j        d ;S ))idrj   r)   total_files
created_at)r   rj   r4   r)   r   r   ).0bucketr*   s     r!   
<listcomp>z!_list_buckets.<locals>.<listcomp>{  se     	 	 	  )~AO`Ln===U[U`!- +	
 	
	 	 	r#   )r   r   right)r)   r   )
alignments)
rt   ru   r   r   rH   rstripr   list_bucketsr   table)r   r   r*   r~   r   rl   rx   r:   s     `     r!   r   r   e  s      L !JKKK Q !OPPP !5!5m!D!Dc-00223	$$S))	
5
!
!
!C	 	 	 	 &&6&JJ	 	 	E Ie I IJJJJJJr#   c           	          |r.t           j        t          j        k    rt	          j        d          t          |          }	 t          |           \  }}n3# t          $ r&}t	          j        t          |                    d}~ww xY wt          |                    ||pd|                    }	|	st          j        d           dS t          d |	D                       }
|r@t           j        t          j        k    }t          |	||          D ]}t!          |           n@t           j        t          j        k    r.t!          t          j        d |	D             d	
                     nt           j        t          j        k    rG|	D ]C}t%          |t&                    rt!          |j         d           /t!          |j                   Dn|	D ]}t%          |t&                    r5t+          |j        |          }t!          ddd|dd|j         d           Lt/          |j        |          }t+          |j        |          }t!          |dd|dd|j                    |s|
rt          j        d           dS dS dS )zList files in a bucket.z%Cannot use --tree with --format json.ro   Nre   r   z(empty)c              3   @   K   | ]}t          |t                    V  d S N)rF   r   r   rK   s     r!   	<genexpr>z_list_files.<locals>.<genexpr>  s,      KKT*T<88KKKKKKr#   )r*   r;   c                 ,    g | ]}t          |          S  )r   r   s     r!   r   z_list_files.<locals>.<listcomp>  s!    EEEt,T22EEEr#   rA   )rV   r=   r7   z>12rY   z>19z!Use -R to list files recursively.)r   moder   jsonrt   ru   r   r(   r'   r2   listlist_bucket_treetextanyr;   rT   printdumpsrF   r   r   r9   uploaded_atr4   r)   r5   hint)r$   r*   r~   r   rl   rx   ri   re   rz   r:   has_directoriesr;   linerK   	mtime_strrQ   s                   r!   r   r     s     J383888 !HIII
5
!
!
!C)28<<	66 ) ) ) Q((() >T 	 	
 	
 E  KKUKKKKKO G066nERRR 	 	D$KKKK		).	.	.djEEuEEEaPPPQQQQ	)/	/	/ 	! 	!D$-- !ooo&&&&di    		!  	G 	GD$-- G)$*:NKK	@@@9@@@DI@@@AAAA'	>BB)$*nEE	EEEEEE$)EEFFFF 6 64555556 6 6 6s   A 
B!B  Binfozhf buckets info user/my-bucketz+hf buckets info hf://buckets/user/my-bucketzFBucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_namec                 
   t          |          }	 t          |           \  }}n3# t          $ r&}t          j        t          |                    d}~ww xY w|                    |          }t          j        |d           dS )zGet info about a bucket.ro   Nr   )id_key)	r   r(   r'   rt   ru   r2   bucket_infor   dict)ri   rl   rm   rx   ry   _rz   r   s           r!   r   r     s    $ 5
!
!
!C)-i88	11 ) ) ) Q((() __Y''FHVD!!!!!!s   % 
A!AAdelete)z hf buckets delete user/my-bucketz-hf buckets delete hf://buckets/user/my-bucketz&hf buckets delete user/my-bucket --yesz-hf buckets delete user/my-bucket --missing-okyesz--yesz-yzSkip confirmation prompt.
missing_okz--missing-okz3Do not raise an error if the bucket does not exist.c                    |                      t                    rl	 t          |           \  }}n3# t          $ r&}t	          j        t          |                    d}~ww xY w|r t	          j        d|  dt           d          |} n$d| vr t	          j        d|  dt           d          t          j        d|  d	|
           t          |          }|
                    | |           t          j        d|            dS )zDelete a bucket.

    This deletes the entire bucket and all its contents. Use `hf buckets rm` to remove individual files.
    Nz-Cannot specify a prefix for bucket deletion: rp   rq   r=   zInvalid bucket ID: r&   z(Are you sure you want to delete bucket ''?r   ro   )r   zBucket deleted)ri   )r   r   r(   r'   rt   ru   r2   r   confirmr   delete_bucketrw   )	ri   r   r   rl   rm   ry   re   rz   rx   s	            r!   r   r     sj   L M** 
	- 6y A AIvv 	- 	- 	-$SVV,,,	- 	$W	 W W1>W W W   			I		 a) a a;Ha a a
 
 	

 KH9HHHcRRRR
5
!
!
!CiJ777J9555555s   / 
A!AAzremove | rm)z)hf buckets remove user/my-bucket/file.txtz2hf buckets rm hf://buckets/user/my-bucket/file.txtz.hf buckets rm user/my-bucket/logs/ --recursivez:hf buckets rm user/my-bucket --recursive --include "*.tmp"z8hf buckets rm user/my-bucket/data/ --recursive --dry-runzBucket path: namespace/bucket_name/path or hf://buckets/namespace/bucket_name/path. With --recursive, namespace/bucket_name is also accepted to target all files.z0Remove files recursively under the given prefix.dry_runz	--dry-runz8Preview what would be deleted without actually deleting.includezQInclude only files matching pattern (can specify multiple). Requires --recursive.excludezLExclude files matching pattern (can specify multiple). Requires --recursive.c                 >   	 t          |           \  }n3# t          $ r&}	t          j        t	          |	                    d}	~	ww xY w|dk    r|st          j        d d d          |s|r|st          j        d          t          |          }
|rSt          t          j        t          j
        k              }|                    d	           g }|
                    |                    d
          pdd          D ]R}t          |t                    r;|                    |           |                    dt#          |           d           S|                    dt#          |           d           |s|r t'          ||          fd|D             }n|}d |D             }t)          d |D                       }t+          |d          }|st          j        d           dS t#          |           d| }|sP|sNt          j        d                    d |D                                  t          j        d| d dd           |rMt          j        d                    fd|D                                  t          j        d| d           dS |
                    |            t          j        d!| d d"t#          |          |#           dS |                    d
          }|st          j        d$          |r7t          j        d%t6            d
|            t          j        d&           dS t          j        d'| d( d|           |
                    |g            t          j        d)|*           dS )+zbRemove files from a bucket.

    To delete an entire bucket, use `hf buckets delete` instead.
    Nr7   z?No file path specified. To remove files, provide a path (e.g. 'zd/FILE') or use --recursive to remove all files. To delete the entire bucket, use `hf buckets delete z`.z,--include and --exclude require --recursive.ro   )enabledzListing files from remoter=   Tr   zListing files from remote (z files))include_patternsexclude_patternsc                 H    g | ]}                     |j                  |S r   )matchesr   )r   fmatchers     r!   r   zremove.<locals>.<listcomp>  s,    MMM1W__QV5L5LMQMMMr#   c                     g | ]	}|j         
S r   r    r   r   s     r!   r   zremove.<locals>.<listcomp>  s    444af444r#   c              3   $   K   | ]}|j         V  d S r   )r)   r   s     r!   r   zremove.<locals>.<genexpr>  s$      77A777777r#   )r*   zNo files to remove.z file(s) totaling 
c              3       K   | ]	}d | V  
dS )rY   Nr   )r   r   s     r!   r   zremove.<locals>.<genexpr>  s(      BBt{D{{BBBBBBr#   zRemove z from 'r   Fr   c              3   6   K   | ]}d t             d| V  dS )delete: r=   N)r   )r   r   ri   s     r!   r   zremove.<locals>.<genexpr>  s:      ccPTK-KKKTKKccccccr#   z
(dry run) z would be removed.)r   zRemoved ')ri   files_deletedr)   zFile path cannot be empty.r   z"(dry run) 1 file would be removed.zRemove 'z' from 'zFile removed)r   ri   )r(   r'   rt   ru   r2   r   r   r   r   r   humanupdater   r   rF   r   r]   rH   doner	   sumr4   r   joinr   batch_bucket_filesrw   r   )r$   r   r   r   r   r   rl   rm   re   rz   rx   status	all_filesrK   matched_files
file_paths
total_sizerQ   count_label	file_pathri   r   s                       @@r!   remover   !  sz   |)28<<	66 ) ) ) Q((() ||I| R R RDMR R R
 
 	
 	 Q7 QI Q !OPPP
5
!
!
!C =HCH0D0J$JKKK1222&(	((==%%- ) 
 
 	U 	UD
 $
++ U  &&&SC	NNSSSTTTI#i..IIIJJJ 	&g 	&#WwWWWGMMMM	MMMMM%M44m444
7777777

4@@@ 	H*+++FZFFHFF 	P7 	PHTYYBBzBBBBBCCCKC+CCiCCCOOOO 	HTYYccccXbcccccdddHA+AAABBBFy<<<
7{779777j//		
 	
 	
 	
 	
 	
 MM#&&	 	C$%ABBB 	HFFyFF9FFGGGH9:::F?y??)???SIIIIy)===
>	YGGGGGGs    
A!AAmove)z/hf buckets move user/old-bucket user/new-bucketz/hf buckets move user/my-bucket my-org/my-bucketzIhf buckets move hf://buckets/user/old-bucket hf://buckets/user/new-bucketfrom_idzMSource bucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_nameto_idzRDestination bucket ID: namespace/bucket_name or hf://buckets/namespace/bucket_namec                 R   t          |           \  }}|r t          j        d|  dt           d          t          |          \  }}|r t          j        d| dt           d          t	          |          }|                    ||           t          j        d||           dS )z2Move (rename) a bucket to a new name or namespace.z)Cannot specify a prefix for bucket move: rp   rq   ro   )r   r   zBucket movedN)r(   rt   ru   r   r   move_bucketr   rw   )	r   r   rl   rm   parsed_from_idfrom_prefixparsed_to_id	to_prefixrx   s	            r!   r   r     s    4 #9"A"ANK 
 S S S-:S S S
 
 	
 5U;;L) 
 S S S-:S S S
 
 	

 5
!
!
!COON,O???J~~\JJJJJJr#   sync)z2hf buckets sync ./data hf://buckets/user/my-bucketz2hf buckets sync hf://buckets/user/my-bucket ./dataz;hf buckets sync ./data hf://buckets/user/my-bucket --deletez^hf buckets sync hf://buckets/user/my-bucket ./data --include "*.safetensors" --exclude "*.tmp"zIhf buckets sync ./data hf://buckets/user/my-bucket --plan sync-plan.jsonlz'hf buckets sync --apply sync-plan.jsonlz<hf buckets sync ./data hf://buckets/user/my-bucket --dry-runzChf buckets sync ./data hf://buckets/user/my-bucket --dry-run | jq .sourcezKSource path: local directory or hf://buckets/namespace/bucket_name(/prefix)destzPDestination path: local directory or hf://buckets/namespace/bucket_name(/prefix)z/Delete destination files not present in source.ignore_timesz--ignore-timesz;Skip files only based on size, ignoring modification times.ignore_sizesz--ignore-sizesz<Skip files only based on modification times, ignoring sizes.planz=Save sync plan to JSONL file for review instead of executing.applyz#Apply a previously saved plan file.z5Print sync plan to stdout as JSONL without executing.z6Include files matching pattern (can specify multiple).z6Exclude files matching pattern (can specify multiple).filter_fromz(Read include/exclude patterns from file.existingz
--existingzASkip creating new files on receiver (only update existing files).ignore_existingz--ignore-existingzCSkip updating files that exist on receiver (only create new files).verbosez	--verbosez-vz%Show detailed logging with reasoning.z--quietz-qzMinimal output.c                     t          |          }|                    | ||||||||	|
|||||           |r|st          j        d| d           dS dS dS )z0Sync files between local directory and a bucket.ro   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   zRun `hf buckets sync --apply z` to execute this plan.N)r   sync_bucketr   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   rl   rx   s                    r!   r   r     s    h 5
!
!
!COO!!'    "  PE PNNNNOOOOOP P P Pr#   cp)
z5hf buckets cp hf://buckets/user/my-bucket/config.jsonz=hf buckets cp hf://buckets/user/my-bucket/config.json ./data/zDhf buckets cp hf://buckets/user/my-bucket/config.json my-config.jsonz7hf buckets cp hf://buckets/user/my-bucket/config.json -z8hf buckets cp my-config.json hf://buckets/user/my-bucketz>hf buckets cp my-config.json hf://buckets/user/my-bucket/logs/zKhf buckets cp my-config.json hf://buckets/user/my-bucket/remote-config.jsonz7hf buckets cp - hf://buckets/user/my-bucket/config.jsonzVhf buckets cp hf://buckets/user/my-bucket/logs/ hf://buckets/user/archive-bucket/logs/zehf buckets cp hf://datasets/user/my-dataset/processed/ hf://buckets/user/my-bucket/dataset/processed/srczMSource: local file, any hf:// handle (model, dataset, bucket), or - for stdindstz@Destination: local path, bucket hf://... handle, or - for stdoutc                 
   t          |          }t          |           }|duot          |          }t          |           }|duot          |          }| dk    }	|dk    }
|rf|rd	 |                    | |           n3# t          $ r&}t          j        t          |                    d}~ww xY wt          j	        d| |           dS |s.|s,|	s*|t          j        d          t          j        d          |	r|st          j        d          |	rC|rAt          |          \  }}|d	k    s|                    d
          rt          j        d          |
r|st          j        d          |s5|	s3t          j                            |           rt          j        d          |rft          |           \  }}|d	k    s|                    d
          rt          j        d          |                    d
d          d         }|
r"t!                      }|st#                       	 t%                      5 }t          j                            ||          }|                    |||fg           t+          |d          5 }|                    d          x}r;t.          j        j                            |           |                    d          x};ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |st7                       dS dS # |st7                       w w xY w||}nvt          j                            |          s4|                    t          j                  s|                    d
          r!t          j                            ||          }n|}t          j                            |          }|rt          j        |d           |                    |||fg           t          j	        d| |           dS |	rht          |          \  }}t.          j        j                                        }|                     |||fg           t          j	        dd|           dS t          j        !                    |           st          j        d|            t          |          \  }}|d	k    r t          j        "                    |           }n:|                    d
          r#|t          j        "                    |           z   }n|}|                     || |fg           t          j	        d| tF           | d
|            dS )zCopy files to or from buckets.ro   N-Copied)r   r   z2Missing destination. Provide a bucket path as DST.z;One of SRC or DST must be a bucket path (hf://buckets/...).z+Stdin upload requires a bucket destination.r7   r=   zAStdin upload requires a full destination path including filename.z"Cannot pipe to stdout for uploads.zNSource must be a file, not a directory. Use `hf buckets sync` for directories.zJSource path must include a file name, not just a bucket or directory path.r   r>   rbi HT)rk   
Downloaded)addUploadedstdinzSource file not found: )$r   r"   r
   
copy_filesr'   rt   ru   r2   r   rw   r   endswithosr   isdirrsplitr   r   r   r   download_bucket_filesopenreadsysstdoutbufferwriter   sepdirnamemakedirsr   r   isfilebasenamer   )r   r   rl   rm   rx   	src_is_hf	dst_is_hfsrc_is_bucketdst_is_bucketsrc_is_stdindst_is_stdoutrz   r   re   ri   filenamepbar_was_disabledtmp_dirtmp_pathr   chunk
local_path
parent_dirremote_pathdatas                            r!   r   r   r  sA   4 5
!
!
!Cc""I46M#$6$6I#C((MtO<(<(<M#:L3JM  Y 	-NN3$$$$ 	- 	- 	-$SVV,,,	- 	
8#....  ` `| `;$%YZZZ !^___ PM P !NOOO j j&s++	6R<<6??3//<$%hiii G] G !EFFF s s"'--2D2D s !qrrr  ?Y.s33	6R<<6??3//<$%qrrr==a((, 	> !; < <$ (%'''	++-- ;!w||GX>>H--i68:L9MNNNh-- ;'(vvj'9'99e ;J-33E::: ()vvj'9'99e ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ) +(*****+ +( +(****+ {%

s## !s||BF';'; !s||C?P?P !W\\#x88

 
 44J 7J6666%%i6:2F1GHHHJ|*======	 Y!3C!8!8	;y$$&&yk/B.CDDD
:7444444 w~~c"" 	F$%Ds%D%DEEE.s33	6R<<'**3//KK__S!! 	! 27#3#3C#8#88KK Ky[/A.BCCC
:3},Wi,W,W+,W,WXXXXXXsn   &A= =
B-!B((B-'L 5A
K5?AKK5K"	"K5%K"	&K5)L 5K99L <K9=L L')F)FF)r   r   F)NNFFFNNFNNNFFFFN)B__doc__r   r   r  r   typingr   rt   huggingface_hubr   huggingface_hub._bucketsr   r   r   r	   r
   r   r   huggingface_hub.utilsr   r   r   r   r   
_cli_utilsr   r   r   r   r   r   _outputr   r   
get_logger__name__loggerbuckets_clir2   boolr"   tupler(   intfloatr4   r9   r   rT   r   rI   commandautoArgumentOptionrg   r}   r   r   r   r   r   r   r   r   r   r   r#   r!   <module>r-     s   > =  				 



              # # # # # #                                              / . . . . . . . 
	H	%	% m!EFFF$ $ $ $ $ $
S 
U38_ 
 
 
 
" sU{ D S    / /D /$ /3 / / / / !< <
\)*<< < 
#Y	< < < <F  ) )
)9) ) 	)
 ) ) 
) ) ) )X 	    	 	. 	 	 4 9-,O ,Og	
 	
 	
	,O +	
 	
 	
	,O F	
 	
 	
	,O* +,O, -,O. 
/,O ,O ,O	 	,O^C D     	     0 	 	 	 	 4 9G?
 ?
d
W	
 	
 	
	?
 7	
 	
 	
	?
$ F	
 	
 	
	%?
2 C	
 	
 	
	3?
B C?
D E?
F G?
H 
I?
 ?
 ?
 ?
D KTz K$J K  K 	 K
  K : K 
 K  K  K  KF;6;6;6 ;6 	;6
 :;6 
;6 ;6 ;6 ;6| 	(5     4 9" "Y	
 	
 	
	" " " 
" " " ", 	     . 	 	 4 9/26 26Y	
 	
 	
	26 
,	
 	
 	
	
26 F	
 	
 	
	26, -26. /260 
126 26 26 26j 	    	 	6 	 	 	 	 	 4 9]BH BHa	
 	
 	
	BH C	
 	
 	
	BH$ 
,	
 	
 	
	
%BH4 K	
 	
 	
	5BHB S	Dd	
 	
 	
	CBHN S	D_	
 	
 	
	OBHZ [BH\ ]BH^ 
_BH BH BH	 	BHJ 	     *  4 9#K #K`	
 	
 	
	#K e	
 	
 	
	#K #K #K 
#K #K #K #KV 		 	 	   & 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	IzP zPd
^	
 	
 	
	zP d
c	
 	
 	
	zP B	
 	
 	
	zP& N	
 	
 	
	'zP4 O	
 	
 	
	5zPB d
P	
 	
 	
	CzPN d
6	
 	
 	
	OzPZ H	
 	
 	
	[zPh S	DI	
 	
 	
	izPt S	DI	
 	
 	
	uzP@ d
;	
 	
 	
	AzPL T	
 	
 	
	MzPZ V	
 	
 	
	[zPh 8	
 	
 	
	izPx "	
 	
 	
	yzPH IzPJ 
KzP zP zP zPD 	     * 	 4 9sY sY	^U^!pqqqq
sY 
d
NEN(jkkkk
	sY sY sY 
sY sY sY sY sY sYr#   