
    iu              &          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mZm Z  dd
l!m"Z"  e	jF                  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e0eez     de(de(de0e'   fdZ1	 	 	 dde2de0e'   de'de,de,de(ddfd Z3e&ji                  d!g d"#      	 	 	 	 dd$ee' ejj                  d%      f   d&ee( ejl                  d'd(      f   d)ee( ejl                  d*d+      f   ded,eddfd-       Z7de'de(fd.Z8e&ji                  d/g d0#      ddddejr                  ddfdee'dz   ejj                  d1      f   dee( ejl                  d2d3d4      f   d5ee( ejl                  d6d7      f   d8ee( ejl                  d9d:d;      f   d<eded,eddfd=       Z:d>e'dz  de(d5e(d8e(d<ede(d,e'dz  ddfd?Z;de'de(d5e(d8e(d<ede(d,e'dz  ddfd@Z<e&ji                  dAdBdCg#      	 	 dd$ee' ejj                  dD      f   ded,eddfdE       Z=e&ji                  dFg dG#      	 	 	 	 dd$ee' ejj                  dD      f   dHee( ejl                  dIdJdK      f   dLee( ejl                  dMdN      f   ded,eddfdO       Z>e&ji                  dPg dQ#      	 	 	 	 	 	 	 ddee' ejj                  dR      f   d8ee( ejl                  d9d:dS      f   dHee( ejl                  dIdJdK      f   dTee( ejl                  dUdV      f   dWee0e'   dz   ejl                  dX      f   dYee0e'   dz   ejl                  dZ      f   ded,eddfd[       Z?e&ji                  d\g d]#      	 dd^ee' ejj                  d_      f   d`ee' ejj                  da      f   d,eddfdb       Z@e&ji                  dcg dd#      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeee'dz   ejj                  df      f   dgee'dz   ejj                  dh      f   dFee( ejl                  di      f   djee( ejl                  dkdl      f   dmee( ejl                  dndo      f   dpee'dz   ejl                  dq      f   dree'dz   ejl                  ds      f   dTee( ejl                  dUdt      f   dWee0e'   dz   ejl                  du      f   dYee0e'   dz   ejl                  dv      f   dwee'dz   ejl                  dx      f   dyee( ejl                  dzd{      f   d|ee( ejl                  d}d~      f   dee( ejl                  ddd      f   dee( ejl                  ddd      f   d,eddf"d       ZAe&ji                  dg d#      	 	 	 ddee' ejj                  d      f   dee'dz   ejj                  d      f   ded,eddf
d       ZBy)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   )	FormatOptOutputFormatQuietOptTokenOptapi_object_to_dict
get_hf_apiprint_list_outputtyper_factory)outz"Commands to interact with buckets.)helppathreturnc                 $    | j                  d      S )Nzhf://)
startswith)r   s    l/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/huggingface_hub/cli/buckets.py_is_hf_handler"   =   s    ??7##    argumentc                     | j                  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(   A   sb     =)!(++
*844 
'z 2 /!68
 	

s	   
-  AFsizehuman_readablec                 z    |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   R   sj    4y- $;s{q''3Zq'' 3Zsr#   mtimec                 P    | y|r| j                  d      S | j                  d      S )z0Format mtime datetime to a readable date string. z%b %d %H:%Mz%Y-%m-%d %H:%M:%S)strftime)r5   r*   s     r!   _format_mtimer9   `   s,    }~~m,,>>-..r#   itemsquietc                 
   i }| D ]e  }|j                   j                  d      }|}|dd D ]  }||vrdi i||<   ||   d   } |d   }t        |t              r||vsWdi i||<   _d|i||<   g d}	d}
d}|s{| D ]i  }t        |t              st        |j                  |      }t        |
t        |            }
t        |j                  |      }t        |t        |            }k |
dkD  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   i   sS   & D 5		$#2J 	4D7"!/ 4dmN3G	4
 2Y
dL)('5r&:
##-t"4GJ5  LNN 	DD$
+'		>B!$^S]!C(^D!$^S]!C	D A)A->L E
!%% Lr#   noderS   indentrC   rD   c           	      .   t        | j                               }t        |      D ]  \  }\  }}	|t        |      dz
  k(  }
|
rdnd}d|	v }|	j	                  di       }|dkD  rz|rd|z  }nQ|	j	                  d      }|9t        |j                  |      }t        |j                  |      }|d	| d
d| }nd|z  }|j                  | d| | | |rdnd
        n|j                  | | | |rdnd
        |s||
rdndz   }t        ||||||        y)z:Recursively render a tree structure with size+date prefix.r   u
   └── u
   ├── r?   r   r1   r@   N>r7     r=   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      sL    4::< E%e, =D%s5zA~%$+L	5(99^R0!|+yy,#+DII~FH,TZZHH (>*: (:;2hZHF </FLLF82fXi[fsRT>UVWLLF8I;tfFS4KLM!wVH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.tokenc                    t        |      }| j                  t              r3	 t        |       \  }}|r t        j                  d|  dt         d      |} |j                  | |r|nd|      }	|rt        |	j                         yt        d|	j                   d|	j                   d	       y# t        $ r#}t        j                  t        |            d}~ww xY w)
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: z
 (handle: ))r   r    r   r(   r'   typerBadParameterr2   create_bucketprinthandleurl)
ri   rj   rk   r;   rl   api	parsed_idre   e
bucket_urls
             r!   rg   rg      s    F 5
!CM*	- 6y AIv $$?	{ K11>?UW  	""" # J
 j   0
:;L;L:MQOP#  	-$$SV,,	-s   B, ,	C5CCc                 d    | j                  t              r| t        t              d }d|v S | }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}     s?    =)M*,- $; $;r#   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           	      t    | duxr t        |       }|rt        | ||||||       yt        | ||||||       y)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   r;   rl   )	namespacer*   r~   r   r   r;   rl   )r}   _list_files_list_buckets)r$   r*   r~   r   r   r;   rl   is_file_modes           r!   list_cmdr     sX    r 4'CM(,CL)	
 	)	
r#   r   c                 *   |rt        j                  d      |rt        j                  d      | 8| j                  t              r#| t	        t              d } | j                  d      } t        |      }|j                  |       D cg c]  }t        |       }	}|	s<|s:|t        j                  k7  r'| | n|j                         d   }
t        d|
 d	       yg d
}dt        dt        t           ffd}ddd}t!        |	|||||       yc c}w )zList buckets in a namespace.z'Cannot use --tree when listing buckets.z,Cannot use --recursive when listing buckets.Nr=   rn   )r   r_   z"No buckets found under namespace ''.)idrj   r)   total_files
created_atrK   r   c           	          ddl m}  || j                  d             || j                  d            t        | j                  dd             || j                  d             || j                  d	            gS )
Nr   )_format_cellr   rj   r)   r   r*   r   r   )
_cli_utilsr   r\   r4   )rK   r   r*   s     r!   row_fnz_list_buckets.<locals>.row_fn  sj    , $(),-&!,^L-01,/0
 	
r#   right)r)   r   )r   r;   headersr   
alignments)rr   rs   r    r   rH   rstripr   list_bucketsr   r   jsonwhoamiru   dictlistr2   r   )r   r*   r~   r   r   r;   rl   rx   bucketresultsresolved_namespacer   r   r   s    `            r!   r   r   j  s      !JKK  !OPP !5!5m!Dc-023	$$S)	
5
!C8;8H8HS\8H8]^f!&)^G^<#4#44.7.CV\I]67I6J"MNDG	
T 	
d3i 	
 "':JgfE7SYfpq- _s   
Dc           	      X   |r(|t         j                  k(  rt        j                  d      t	        |      }	 t        |       \  }}	t        |j                  ||	xs d|            }|st        d       yt        d |D              }|t         j                  k(  r:|D cg c]  }t        |       }}t        t        j                  |d             n|r!t        |||	      }|D ]  }t        |        n|rF|D ]@  }t        |t               rt        |j"                   d
       ,t        |j"                         B n|D ]  }t        |t               r7t%        |j&                  |      }t        ddd|dd|j"                   d
       Jt)        |j*                  |      }t%        |j,                  |      }t        |dd|dd|j"                           |s|rt/               j1                  d       yyy# t        $ r#}
t        j                  t        |
            d}
~
ww xY wc c}w )zList files in a bucket.z%Cannot use --tree with --format json.rn   Nre   r   z(empty)c              3   <   K   | ]  }t        |t                y wN)rF   r   ).0rK   s     r!   	<genexpr>z_list_files.<locals>.<genexpr>  s     KT*T<8Ks   rA   rV   )r*   r;   r=   r7   z>12rY   z>19z!Use -R to list files recursively.)r   r   rr   rs   r   r(   r'   r2   r   list_bucket_treeru   anyr   dumpsrT   rF   r   r   r9   uploaded_atr4   r)   r5   r   done)r$   r*   r~   r   r   r;   rl   rx   ri   re   rz   r:   has_directoriesrK   r   
tree_linesline	mtime_strrQ   s                      r!   r   r     s	    6\...  !HII
5
!C)28<	6
 >T 	 	
E iKUKKO"""8=>%d+>>djj+,	 ~US
 	D$K		 	!D$-1o&dii 		!  	GD$-)$*:*:NK	C9S/DII;a@A'		>B)$**nE	#b3r$))EF	G => )9W  )  Q(()& ?s   G8 H'8	H$HH$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        |       \  }}|j                  |      }|rt        |j                         yt        t        j                  t        |      d             y# t        $ r#}t        j                  t        |            d}~ww xY w)zGet info about a bucket.rn   NrA   r   )r   r(   r'   rr   rs   r2   bucket_inforu   r   r   r   r   )ri   r;   rl   rx   ry   _rz   r   s           r!   r   r     s    $ 5
!C)-i8	1 __Y'Ffiidjj+F3A>?  )  Q(()s   A/ /	B8BB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                    | j                  t              r4	 t        |       \  }}|r t	        j
                  d|  dt         d      |} n$d| vr t	        j
                  d|  dt         d      t        j                  d|  d	|
       t        |      }|j                  | |       |rt        |        yt        d|         y# t        $ r#}t	        j
                  t        |            d}~ww xY w)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: ro   rp   r=   zInvalid bucket ID: r&   z(Are you sure you want to delete bucket ''?r   rn   )r   zBucket deleted: )r    r   r(   r'   rr   rs   r2   r   confirmr   delete_bucketru   )	ri   r   r   r;   rl   ry   re   rz   rx   s	            r!   r   r     s   L M*	- 6y AIv $$?	{ K11>?UW  		I	  !) -;;H/I_a
 	

 KK:9+RHcR
5
!CiJ7i ,-+  	-$$SV,,	-s   C 	C1C,,C1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        |       \  }}	|	dk(  r|st        j                  d| d| d      |s|r|st        j                  d      t        |      }|rt        |       }|j                  d	       g }|j                  ||	j                  d
      xs dd      D ]B  }t        |t              s|j                  |       |j                  dt        |       d       D |j                  dt        |       d       |s|r9t        ||      }|D cg c]   }|j!                  |j"                        s|" }}n|}|D cg c]  }|j"                   }}t%        d |D              }t'        |d      }|s|st)        d       yt        |       d| }|s7|s5|s|D ]  }t)        d|         t+        j,                  d| d| dd       |r.|D ]  }t)        dt.         | d
|         t)        d| d       y|j1                  ||       |r|D ]  }t)        |        y|D ]  }t)        dt.         | d
|         t)        d| d| d       y|	j                  d
      }|st        j                  d       |r#t)        dt.         | d
|        t)        d!       yt+        j,                  d"| d#| d|       |j1                  ||g       |rt)        |       yt)        dt.         | d
|        y# t        $ r#}
t        j                  t	        |
            d}
~
ww xY wc c}w c c}w )$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.rn   )enabledzListing files from remoter=   Tr   zListing files from remote (z files))include_patternsexclude_patternsc              3   4   K   | ]  }|j                     y wr   )r)   )r   fs     r!   r   zremove.<locals>.<genexpr>  s     7A7s   r   zNo files to remove.z file(s) totaling rY   zRemove z from 'r   Fr   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'   rr   rs   r2   r   r   updater   r   rF   r   r]   rH   r   r	   matchesr   sumr4   ru   r   r   r   batch_bucket_files)r$   r   r   r   r   r   r;   rl   ri   re   rz   rx   status	all_filesrK   matcherr   matched_files
file_paths
total_sizerQ   count_labelr   	file_paths                           r!   remover   <  s~   |)28<	6 |I   k "DDM;bR
 	
 	7I  !OPP
5
!CI.12&(	((==%- ) 
 	UD
 $
+  & ;C	N;K7ST	U 	1#i.1AIJg#WwWG(1M1W__QVV5LQMMM%M&34aff4
4777

4@+,Z));H:F7& 'DBtf+&'KK'+gi[CO" D	{!D6BCDJ{m+=>?y<" d # D	{!D6BCDH[M2>? MM#&	$$%ABBH]OI;a	{CD67hyk)B?SIy)=)H]OI;a	{CDi  )  Q(()@ N 5s)   L  L4=L4
L9	L1L,,L1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                 $   t        |       \  }}|r t        j                  d|  dt         d      t        |      \  }}|r t        j                  d| dt         d      t	        |      }|j                  ||       t        d| d|        y)	z2Move (rename) a bucket to a new name or namespace.z)Cannot specify a prefix for bucket move: ro   rp   rn   )r   r   zBucket moved:  -> N)r(   rr   rs   r   r   move_bucketru   )r   r   rl   parsed_from_idfrom_prefixparsed_to_id	to_prefixrx   s           r!   r   r     s    2 #9"ANK  7y A--:O;QS
 	
 5U;L)  7w ?--:O;QS
 	

 5
!COON,O?	N>*$|n
=>r#   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        |      }|j                  | ||||||||	|
|||||       y)z0Sync files between local directory and a bucket.rn   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   N)r   sync_bucket)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   rl   rx   s                    r!   r   r     sM    h 5
!COO!!'  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xr t        |      }t        |       }|duxr t        |      }| dk(  }	|dk(  }
|rC|rA|r
t                	 |j	                  | |       	 |rt                	 |st        d|  d|        y|s0|s.|	s,|t        j                  d      t        j                  d      |	r|st        j                  d      |	r;|r9t        |      \  }}|d	k(  s|j                  d
      rt        j                  d      |
r|st        j                  d      |s6|	s4t        j                  j                  |       rt        j                  d      |rt        |       \  }}|d	k(  s|j                  d
      rt        j                  d      |j!                  d
d      d   }|
rt#               }|s
t                	 t%               5 }t        j                  j'                  ||      }|j)                  |||fg       t+        |d      5 }|j-                  d      x}r=t.        j0                  j2                  j5                  |       |j-                  d      x}r=ddd       ddd       |st                y||}nrt        j                  j                  |      s0|j                  t        j6                        s|j                  d
      r!t        j                  j'                  ||      }n|}t        j                  j9                  |      }|rt        j:                  |d       |r
t                	 |j)                  |||fg       |rt                	 |st        d|  d|        yyy|	rxt        |      \  }}t.        j<                  j2                  j-                         }|r
t                	 |j?                  |||fg       |rt                	 |st        d|        yyt        j                  jA                  |       st        j                  d|        t        |      \  }}|d	k(  r t        j                  jC                  |       }n6|j                  d
      r#|t        j                  jC                  |       z   }n|}|r
t                	 |j?                  || |fg       |rt                	 |st        d|  dtD         | d
|        yy# t
        $ r#}t        j                  t        |            d}~ww xY w# |rt                w w xY w# 1 sw Y   xY w# 1 sw Y   xY w# |st                w w xY w# |rt                w w xY w# |rt                w w xY w# |rt                w w xY w)zCopy files to or from buckets.rn   N-zCopied: 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   zDownloaded: )addzUploaded: stdin -> zSource file not found: z
Uploaded: )#r   r"   r
   r   
copy_filesr'   rr   rs   r2   r   ru   r   endswithosr   isdirrsplitr   r   joindownload_bucket_filesopenreadsysstdoutbufferwritesepdirnamemakedirsstdinr   isfilebasenamer   )r   r   r;   rl   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     s   4 5
!Cc"I46M#$6I#C(MtO<(<M#:L3JM Y!#	'NN3$ $&HSEcU+, |;$$%YZZ  !^__M  !NOO&s+	6R<6??3/$$%hii]  !EFF"''--2D  !qrr .s3	6R<6??3/$$%qrr==a(, !; <$%'	++- ;!ww||GX>H--i68:L9MNh- ;'(vvj'99e9JJ--33E: ()vvj'99e9;; )(* {%
s#s||BFF';s||C?PWW\\#x8
 
 4JJ6%'+)))vz6J5KL(*SEj\:; 1 )6 
!3C!8	;yy$$&!#	'""9D+3F2G"H$&'u-. 
 ww~~c"$$'>se%DEE.s3	6R<''**3/K__S! 277#3#3C#88K K!#	'""9C3E2F"G$&Jse4yk;-PQ m  	-$$SV,,	- $& \; ;; ; )(* )* (*   $& 2 $& s    S- 
U !AT;#AT.4T;<U U 
U, ,U> -	T6TTT T+.T8	3T;;U U UU),U;>V)F)FF)r   r   F)FFFN)FN)FFFNNFNr   )NNFFFNNFNNNFFFFN)NFN)C__doc__r   r   r   r   typingr   rr   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   r   _outputr   
get_logger__name__loggerbuckets_clir2   boolr"   tupler(   intfloatr4   r9   r   rT   r   rI   commandArgumentOptionrg   r}   tabler   r   r   r   r   r   r   r   r    r#   r!   <module>r"     s   >  	 
    #   	 	 	  
		H	% !EF$ $ $
S 
U38_ 
"sU{ D S /D /$ /3 / !<
\)*<< < 
#Y	<F  )
)9) ) 	)
 ) ) 
)X 	  	. 	 	-/Qg	
	/Q +	
	/Q F	
	/Q* +/Q, -/Q. 
//Q	/QdC D  	
  . 	 	 	 	$**G@
d
W	
	@
 7	
	@
$ F	
	%@
2 C	
	3@
B C@
D E@
F G@
H 
I@
@
F-rTz-r-r -r 	-r
 -r -r :-r 
-r`>?>?>? >? 	>?
 >? >? :>? 
>?B 	(5   @Y	
	@ @ @ 
@@2 	  . 	 	/5.Y	
	5. 
,	
	
5. F	
	5., -5.. /5.0 
15.5.p 	  	6 	 	 	 	 	]JEa	
	JE C	
	JE$ 
,	
	
%JE4 K	
	5JEB S	Dd	
	CJEN S	D_	
	OJEZ [JE\ ]JE^ 
_JE	JEZ 	  * "?`	
	"? e	
	"? "? 
"?"?T 		  & 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	Ixd
^	
	x d
c	
	x B	
	x& N	
	'x4 O	
	5xB d
P	
	CxN d
6	
	OxZ H	
	[xh S	DI	
	ixt S	DI	
	ux@ d
;	
	AxL T	
	MxZ V	
	[xh 8	
	ixx "	
	yxH IxJ 
Kxx@ 	  * 	QR	^U^^!pqq
QR 
d
NENN(jkk
	QR QR QR 
QRQRr#   