
    Zi              &       N   d Z ddlZ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	 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 dd	lmZmZmZmZmZm Z m!Z!m"Z"  ej#        e$          Z% e"d
          Z&de'de(e'e'f         fdZ)dde	e*e+f         de,de'fdZ-ddee         de,de'fdZ.	 	 dde/e	eef                  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           	 	 	 	 dd!ee' e
j4        d"          f         d#ee, e
j5        d$d%          f         d&ee, e
j5        d'd(          f         ded)eddfd*            Z6de'de,fd+Z7e&3                    d,g d-           ddddej8        ddfdeee'          e
j4        d.          f         dee, e
j5        d/d0d1          f         d2ee, e
j5        d3d4          f         d5ee, e
j5        d6d7d8          f         d9eded)eddfd:            Z9d;ee'         de,d2e,d5e,d9ede,d)ee'         ddfd<Z:de'de,d2e,d5e,d9ede,d)ee'         ddfd=Z;e&3                    d>d?d@g           	 	 dd!ee' e
j4        dA          f         ded)eddfdB            Z<e&3                    dCg dD           	 	 	 	 dd!ee' e
j4        dA          f         dEee, e
j5        dFdGdH          f         dIee, e
j5        dJdK          f         ded)eddfdL            Z=e&3                    dMg dN           	 	 	 	 	 	 	 ddee' e
j4        dO          f         d5ee, e
j5        d6d7dP          f         dEee, e
j5        dFdGdH          f         dQee, e
j5        dRdS          f         dTeee/e'                   e
j5        dU          f         dVeee/e'                   e
j5        dW          f         ded)eddfdX            Z>e&3                    dYg dZ           	 dd[ee' e
j4        d\          f         d]ee' e
j4        d^          f         d)eddfd_            Z?e&3                    d`g da           	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddbeee'          e
j4        dc          f         ddeee'          e
j4        de          f         dCee, e
j5        df          f         dgee, e
j5        dhdi          f         djee, e
j5        dkdl          f         dmeee'          e
j5        dn          f         doeee'          e
j5        dp          f         dQee, e
j5        dRdq          f         dTeee/e'                   e
j5        dr          f         dVeee/e'                   e
j5        ds          f         dteee'          e
j5        du          f         dvee, e
j5        dwdx          f         dyee, e
j5        dzd{          f         d|ee, e
j5        d}d~d          f         dee, e
j5        ddd          f         d)eddf"d            Z@e&3                    dg d           	 	 	 ddee' e
j4        d          f         deee'          e
j4        d          f         ded)eddf
d            ZAdS )z7Contains commands to interact with buckets via the CLI.    N)datetime)	AnnotatedOptionalUnion)logging)BUCKET_PREFIX
BucketFileBucketFolderFilterMatcher_is_bucket_path_parse_bucket_path_split_bucket_id_and_prefix)
StatusLineare_progress_bars_disableddisable_progress_barsenable_progress_bars   )	FormatOptOutputFormatQuietOptTokenOptapi_object_to_dict
get_hf_apiprint_list_outputtyper_factoryz"Commands to interact with buckets.)helpargumentreturnc                     |                      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)
startswithr   r   r   
ValueError)r   s    V/root/projects/butler/venv/lib/python3.11/site-packages/huggingface_hub/cli/buckets.py_parse_bucket_argumentr$   8   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_sizer0   I   s     4yy-  $;;s{{'''''''''''''''    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)r2   r&   s     r#   _format_mtimer6   W   s9    }r -~~m,,,>>-...r1   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      r4   prefix_widthmax_size_widthr&   )pathsplit
isinstancer
   r	   r0   r%   maxlenr6   r2   _render_tree)r7   r&   r8   treeitempartscurrentpart
final_partr@   rA   max_date_widthsize_strdate_strliness                  r#   _build_treerR   `   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
!%%    Lr1   noderQ   indentr@   rA   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   r-   r=   N>  r:   r4   z    u   │   r?   )sortedr7   	enumeraterF   getr0   r%   r6   r2   appendrG   )rS   rQ   rT   r@   rA   r&   r7   inamevalueis_last	connectoris_dirchildrenprefixrI   rO   rP   child_indents                      r#   rG   rG      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 r1   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.tokenc                    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|          }	|rt          |	j
                   dS t          d|	j         d|	j
         d	           dS )
zCreate a new bucket.rj   Nz-Cannot specify a prefix for bucket creation: . Use namespace/bucket_name or namespace/bucket_name.)rh   ri   zBucket created: z
 (handle: ))r   r!   r   r$   r"   typerBadParameterr.   create_bucketprinthandleurl)
rg   rh   ri   r8   rj   api	parsed_idrc   e
bucket_urls
             r#   re   re      sB   F 5
!
!
!CM** 
	- 6y A AIvv 	- 	- 	-$SVV,,,	- 	$W	 W W1>W W W   	""", #  J
  Qj     OOO:;LOOOPPPPPs   ? 
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   rF   )r   rB   s     r#   _is_bucket_idr{     sA    =)) M**,,-$;r1   z	list | ls)	zhf buckets listzhf buckets list huggingfacez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).formatc           	          | duot          |           }|r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.
    N)r   r&   r|   r}   r~   r8   rj   )	namespacer&   r|   r}   r~   r8   rj   )r{   _list_files_list_buckets)r   r&   r|   r}   r~   r8   rj   is_file_modes           r#   list_cmdr     s    r 4'CM(,C,CL 
)	
 	
 	
 	
 	
 	
 	)	
 	
 	
 	
 	
 	
r1   r   c                 b   |rt          j        d          |rt          j        d          | K|                     t                    r1| t	          t                    d         } |                     d          } t          |          }d |                    |           D             }|sE|sC|t          j	        k    r3| | n|
                                d         }	t          d	|	 d
           dS g d}
dt          dt          t                   ffd}ddd}t          ||||
||           dS )zList buckets in a namespace.z'Cannot use --tree when listing buckets.z,Cannot use --recursive when listing buckets.Nr:   rl   c                 ,    g | ]}t          |          S  r   ).0buckets     r#   
<listcomp>z!_list_buckets.<locals>.<listcomp>x  s!    ^^^f!&))^^^r1   )r   r]   z"No buckets found under namespace ''.)idrh   r%   total_files
created_atrI   r   c           	      D   ddl m}  ||                     d                     ||                     d                    t          |                     dd                     ||                     d                     ||                     d	                    gS )
Nr   )_format_cellr   rh   r%   r   r&   r   r   )
_cli_utilsr   rZ   r0   )rI   r   r&   s     r#   row_fnz_list_buckets.<locals>.row_fn  s    ,,,,,, L$((L),,--&!,,^LLLL-0011L,//00
 	
r1   right)r%   r   )r~   r8   headersr   
alignments)rp   rq   r!   r   rF   rstripr   list_bucketsr   jsonwhoamirs   dictlistr.   r   )r   r&   r|   r}   r~   r8   rj   rv   resultsresolved_namespacer   r   r   s    `           r#   r   r   a  s}     L !JKKK Q !OPPP !5!5m!D!Dc-00223	$$S))	
5
!
!
!C^^8H8HS\8H8]8]^^^G  	<#444.7.CV\I]M7IMMMNNNFDDDG	
T 	
d3i 	
 	
 	
 	
 	
 	
 "'::JgfE7SYfpqqqqqqr1   c           	         |r$|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          d           dS t          d |D                       }|t           j        k    r1d |D             }t          t          j        |d	                     n	|r't          |||
          }|D ]}t          |           n|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-                                          d           dS dS dS )zList files in a bucket.z%Cannot use --tree with --format json.rl   Nrc   r}   z(empty)c              3   @   K   | ]}t          |t                    V  d S N)rD   r
   r   rI   s     r#   	<genexpr>z_list_files.<locals>.<genexpr>  s,      KKT*T<88KKKKKKr1   c                 ,    g | ]}t          |          S r   r   r   s     r#   r   z_list_files.<locals>.<listcomp>  s!    >>>%d++>>>r1   r>   rT   )r&   r8   r:   r4   z>12rW   z>19z!Use -R to list files recursively.)r   r   rp   rq   r   r$   r"   r.   r   list_bucket_treers   anydumpsrR   rD   r
   rB   r6   uploaded_atr0   r%   r2   r   done)r   r&   r|   r}   r~   r8   rj   rv   rg   rc   rx   r7   has_directoriesr   
tree_lineslinerI   	mtime_strrO   s                      r#   r   r     s     J6\... !HIII
5
!
!
!C)28<<	66 ) ) ) Q((() >T 	 	
 	
 E  iKKUKKKKKO""">>>>>dj+++,,,,	 G ~USSS
 	 	D$KKKK		 G 	! 	!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 ? ?=>>>>>? ? ? ?s   A 
A;!A66A;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                 n   t          |          }	 t          |           \  }}n3# t          $ r&}t          j        t          |                    d}~ww xY w|                    |          }|rt          |j                   dS t          t          j
        t          |          d                     dS )zGet info about a bucket.rl   Nr>   r   )r   r$   r"   rp   rq   r.   bucket_infors   r   r   r   r   )rg   r8   rj   rv   rw   _rx   r   s           r#   r   r     s    $ 5
!
!
!C)-i88	11 ) ) ) Q((() __Y''F @fidj+F33A>>>?????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                 n   |                      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          |s<t	          j        d|  d	          }|s"t          d
           t	          j	                    t          |          }	|	                    | |           |rt          |            dS t          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: rm   rn   r:   zInvalid bucket ID: r    z(Are you sure you want to delete bucket ''?Aborted.rl   )r   zBucket deleted: )r!   r   r$   r"   rp   rq   r.   confirmrs   Abortr   delete_bucket)
rg   r   r   r8   rj   rw   rc   rx   r   rv   s
             r#   r   r     s   L M** 
	- 6y A AIvv 	- 	- 	-$SVV,,,	- 	$W	 W W1>W W W   			I		 a) a a;Ha a a
 
 	

   - X9 X X XYY 	 *+--
5
!
!
!CiJ777 .i,,,-----s   / 
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          |          }|rOt          |           }|                    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|st%          d           dS t          |           d| }|sZ|sX|s|D ]}t%          d|            t          j        d| d| d          }|s"t%          d           t          j                    |r6|D ]}t%          dt*           | d
|            t%          d| d           dS |                    ||           |r|D ]}t%          |           dS |D ]}t%          dt*           | d
|            t%          d| d| d            dS |		                    d
          }|st          j        d!          |r-t%          dt*           | d
|            t%          d"           dS |s?t          j        d#| d$| d          }|s"t%          d           t          j                    |                    ||g           |rt%          |           dS t%          dt*           | d
|            dS )%zbRemove files from a bucket.

    To delete an entire bucket, use `hf buckets delete` instead.
    Nr4   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.rl   )enabledzListing files from remoter:   Tr   zListing files from remote (z files))include_patternsexclude_patternsc                 H    g | ]}                     |j                  |S r   )matchesrB   )r   fmatchers     r#   r   zremove.<locals>.<listcomp>  s,    MMM1W__QV5L5LMQMMMr1   c                     g | ]	}|j         
S r   )rB   r   r   s     r#   r   zremove.<locals>.<listcomp>  s    444af444r1   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7r1   r   zNo files to remove.z file(s) totaling rW   zRemove z from 'r   r   zdelete: z
(dry run) z would be removed.)r   zRemoved r   zFile path cannot be empty.z"(dry run) 1 file would be removed.zRemove 'z' from ')r$   r"   rp   rq   r.   r   r   updater   r   rD   r	   r[   rF   r   r   sumr0   rs   r   r   r   batch_bucket_files)r   r}   r   r   r   r   r8   rj   rg   rc   rx   rv   status	all_filesrI   matched_files
file_paths
total_sizerO   count_labelrB   r   	file_pathr   s                          @r#   remover   7  s+   |)28<<	66 ) ) ) Q((() ||I| R R RDMR R R
 
 	
 	 Q7 QI Q !OPPP
5
!
!
!C LEI...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@@@ 	 -+,,,FZFFHFF 	$7 	$ '& ' 'D+t++&&&&m$Ok$O$O)$O$O$OPPG $j!!!kmm# 	" D DBB	BBDBBCCCC>{>>>???Fy<<< 	@"  d  # D DBB	BBDBBCCCC>[>>>>>????? MM#&&	 	C$%ABBB 	C]CICC	CCDDD6777F 	$m$Oy$O$O)$O$O$OPPG $j!!!kmm#y)=== 	E)C]CICC	CCDDDDDs    
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                 N   t          |           \  }}|r t          j        d|  dt           d          t          |          \  }}|r t          j        d| dt           d          t	          |          }|                    ||           t          d| d|            dS )	z2Move (rename) a bucket to a new name or namespace.z)Cannot specify a prefix for bucket move: rm   rn   rl   )r   r   zBucket moved:  -> N)r$   rp   rq   r   r   move_bucketrs   )r   r   rj   parsed_from_idfrom_prefixparsed_to_id	to_prefixrv   s           r#   r   r     s   2 #9"A"ANK 
 S S S-:S S S
 
 	
 5U;;L) 
 S S S-:S S S
 
 	

 5
!
!
!COON,O???	
=>
=
=|
=
=>>>>>r1   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                 n    t          |          }|                    | ||||||||	|
|||||           dS )z0Sync files between local directory and a bucket.rl   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   N)r   sync_bucket)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   rj   rv   s                    r#   r   r     sg    h 5
!
!
!COO!!'      r1   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.jsonsrcz9Source: local file, hf://buckets/... path, or - for stdindstz?Destination: local path, hf://buckets/... path, or - for stdoutc           	         t          |          }t          |           }|duot          |          }| dk    }|dk    }|r|rt          j        d          |s.|s,|s*|t          j        d          t          j        d          |r|st          j        d          |rG|rE|J t	          |          \  }	}
|
dk    s|
                    d	          rt          j        d
          |r|st          j        d          |s5|s3t          j                            |           rt          j        d          |rt	          |           \  }}
|
dk    s|
                    d	          rt          j        d          |
	                    d	d          d         }|rt                      }|st                       	 t          j                    5 }t          j                            ||          }|                    ||
|fg           t!          |d          5 }t"          j        j                            |                                           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |st-                       dS dS # |st-                       w w xY w||}nvt          j                            |          s4|                    t          j                  s|                    d	          r!t          j                            ||          }n|}t          j                            |          }|rt          j        |d           |rt                       	 |                    ||
|fg           |rt-                       n# |rt-                       w w xY w|st5          d|  d|            dS dS |rt	          |          \  }}t"          j        j                                        }|rt                       	 |                    |||fg           |rt-                       n# |rt-                       w w xY w|st5          d|            dS dS t          j                            |           st          j        d|            t	          |          \  }}
|
dk    r t          j                            |           }n:|
                    d	          r#|
t          j                            |           z   }n|
}|rt                       	 |                    || |fg           |rt-                       n# |rt-                       w w xY w|s!t5          d|  dt>           | d	|            dS dS )z'Copy a single file to or from a bucket.rl   N-z$Remote-to-remote copy not supported.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.r4   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;   rbT)ri   zDownloaded: r   )addzUploaded: stdin -> zSource file not found: z
Uploaded: ) r   r   rp   rq   r   endswithosrB   isdirrsplitr   r   tempfileTemporaryDirectoryjoindownload_bucket_filesopensysstdoutbufferwritereadr   sepdirnamemakedirsrs   stdinr   isfilebasenamer   )r   r   r8   rj   rv   src_is_bucketdst_is_bucketsrc_is_stdindst_is_stdoutr   rc   rg   filenamepbar_was_disabledtmp_dirtmp_pathr   
local_path
parent_dirremote_pathdatas                        r#   r   r     s   , 5
!
!
!C#C((MtO<(<(<M#:L3JM  I I !GHHH ` `| `;$%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  VR.s33	6R<<6??3//<$%qrrr==a((, &	< !; < <$ (%'''+022 :g!w||GX>>H--i68:L9MNNNh-- :
)//999: : : : : : : : : : : : : : :: : : : : : : : : : : : : : : ) +(*****+ +( +(****+ {%

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

 
 44J 7J6666 (%'''+)))vz6J5KLLL +(***  +(****+  <:S::j::;;;;;< < 
 'R!3C!8!8	;y$$&& 	$!###	'""9D+3F2G"HHH '$&&&  '$&&&&'  	/---.....	/ 	/
 w~~c"" 	F$%Ds%D%DEEE.s33	6R<<'**3//KK__S!! 	! 27#3#3C#8#88KK K 	$!###	'""9C3E2F"GGG '$&&&  '$&&&&'  	RPsPPPyPP;PPQQQQQ	R 	Rsy   9J A
I07II0I	I0 I	!I0$J 0I44J 7I48J J"(N N%P6 6Q	U U)F)FF)r   r   F)FFFN)FN)FFFNNFNr   )NNFFFNNFNNNFFFFN)NFN)B__doc__r   r   r   r   r   typingr   r   r   rp   huggingface_hubr   huggingface_hub._bucketsr   r	   r
   r   r   r   r   huggingface_hub.utilsr   r   r   r   r   r   r   r   r   r   r   r   r   
get_logger__name__loggerbuckets_clir.   tupler$   intfloatboolr0   r6   r   rR   r   rG   commandArgumentOptionre   r{   tabler   r   r   r   r   r   r   r   r   r   r1   r#   <module>r&     s   > =  				 



        - - - - - - - - - -  # # # # # #                  v u u u u u u u u u u u	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
	H	%	% m!EFFF
S 
U38_ 
 
 
 
" uS%Z( $ 3    / /(+ /T /c / / / / !< <j,./0<< < 
#Y	< < < <F  ) )
)9) ) 	)
 ) ) 
) ) ) )X 	    	 	. 	 	-/Q /Qg	
 	
 	
	/Q +	
 	
 	
	/Q F	
 	
 	
	/Q* +/Q, -/Q. 
//Q /Q /Q	 	/QdC D     	
 
 
   . 	 	 	 	$*G@
 @
W	
 	
 	
	@
 7	
 	
 	
	@
$ F	
 	
 	
	%@
2 C	
 	
 	
	3@
B C@
D E@
F G@
H 
I@
 @
 @
 @
F-r}-r-r -r 	-r
 -r -r C=-r 
-r -r -r -r`>?>?>? >? 	>?
 >? >? C=>? 
>? >? >? >?B 	(5    @ @Y	
 	
 	
	@ @ @ 
@ @ @ @2 	     . 	 	/9. 9.Y	
 	
 	
	9. 
,	
 	
 	
	
9. F	
 	
 	
	9., -9.. /9.0 
19. 9. 9. 9.x 	    	 	6 	 	 	 	 	]QE QEa	
 	
 	
	QE C	
 	
 	
	QE$ 
,	
 	
 	
	
%QE4 K	
 	
 	
	5QEB cd	
 	
 	
	CQEN c_	
 	
 	
	OQEZ [QE\ ]QE^ 
_QE QE QE	 	QEh 	     * "? "?`	
 	
 	
	"? e	
 	
 	
	"? "? 
"? "? "? "?T 		 	 	   & 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	Ix x^	
 	
 	
	x c	
 	
 	
	x B	
 	
 	
	x& N	
 	
 	
	'x4 O	
 	
 	
	5xB P	
 	
 	
	CxN 6	
 	
 	
	OxZ H	
 	
 	
	[xh cI	
 	
 	
	ixt cI	
 	
 	
	ux@ ;	
 	
 	
	AxL T	
 	
 	
	MxZ V	
 	
 	
	[xh 8	
 	
 	
	ixx "	
 	
 	
	yxH IxJ 
Kx x x x@ 		 	 	   " 	R R	3,ghhhh	iR	~u~+lmmmm
R
 R R 
R R R R R Rr1   