o
    :n0j%                     @   sT  d Z ddlZddl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 ddlmZmZ ddlmZ dejd	efd
dZdejd	efddZdejd	efddZdejd	efddZdejd	efddZdejd	efddZdejd	efddZdejd	efddZdejd	efddZdZde dZd	ej fdd Z!d%d	efd!d"Z"d#d$ Z#dS )&zCommand line usage:
patool
   [global-options]
   {extract|list|create|repack|diff|search|formats}
   [sub-command-options]
   <command-args>
    N   )extract_archivelist_archivetest_archivecreate_archivediff_archivessearch_archiverepack_archivelist_formats)PatoolError)	log_errorlog_internal_error)Appargsreturnc                 C   sr   d}| j D ]1}zt|| j| j| j| jd W q ty6 } ztd| d|  |d7 }W Y d}~qd}~ww |S )zExtract files from archive(s).r   )	verbosityinteractiveoutdirpasswordzerror extracting : r   N)archiver   r   r   r   r   r   r   r   resr   msg r   S/home/wildlama/miniconda3/envs/lam_a2e/lib/python3.10/site-packages/patoolib/cli.pyrun_extract)   s    

r   c                 C   s~   d}| j D ]7}z| j}|dkrd}t||| j| jd W q ty< } ztd| d|  |d7 }W Y d}~qd}~ww |S )zList files in archive(s).r   r   r   r   r   zerror listing r   N)r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   run_list;   s$   

r   c                 C   sn   d}| j D ]/}zt|| j| j| jd W q ty4 } ztd| d|  |d7 }W Y d}~qd}~ww |S )zTest files in archive(s).r   r   zerror testing r   r   N)r   r   r   r   r   r   r   r   r   r   r   run_testP   s   

r   c              
   C   sh   d}zt | j| j| j| j| jd W |S  ty3 } ztd| j d|  d}W Y d}~|S d}~ww )z#Create an archive from given files.r   r   zerror creating r   r   N)r   r   filenamer   r   r   r   r   r   r   r   r   r   r   
run_createa   s    
r"   c              
   C   sh   zt | j| j| j| jd}W |S  ty3 } ztd| j d| j d|  d}W Y d}~|S d}~ww )z&Show differences between two archives.r   r   z"error showing differences between z and r      N)r   archive1archive2r   r   r   r   r!   r   r   r   run_diffr   s    r'   c              
   C   sd   zt | j| j| j| j| jd}W |S  ty1 } ztd| j d|  d}W Y d}~|S d}~ww )z$Search for pattern in given archive.r   zerror searching r   r$   N)r   patternr   r   r   r   r   r   r!   r   r   r   
run_search   s   
r)   c              
   C   sd   d}zt | j| j| j| jd W |S  ty1 } ztd| j d|  d}W Y d}~|S d}~ww )z(Repackage one archive in another format.r   r#   zerror repacking r   r   N)r	   archive_srcarchive_dstr   r   r   r   r!   r   r   r   
run_repack   s   	r,   c                 C   s
   t   dS )z-List supported and available archive formats.r   )r
   r   r   r   r   run_formats   s   r.   c                 C   s   t t dS )zPrint version number.r   )printr   r-   r   r   r   run_version   s   r0   aB  EXAMPLES
  patool extract archive.zip otherarchive.rar
  patool --verbose test dist.tar.gz
  patool list package.deb
  patool --verbose create myfiles.zip file1.txt dir/
  patool diff release1.0.tar.xz release2.0.zip
  patool search "def urlopen" python-3.3.tar.gz
  patool repack linux-2.6.33.tar.gz linux-2.6.33.tar.bz2
z
VERSION
  
c                  C   s  t d t } tjd| tjd}| }|jdddddd	d
 |jddddddd
 |jdddddd |jdddd}|jddd}|jddd |jddd |jdd d!d" |jd#d$d}|jddd |jdd d!d" |jd%d&d}|jdd'd |jdd(d |jd)d d*d" |jd+d,d}|jddd |jdd d!d" |jd-d.d}|jd/d0d |jd1d2d |jd3d4d}	|	jd5d6d |	jd7d8d |jd9d:d}
|
jddd |
jd;d<d |
jdd=d |jd>d?d |jd@dAd zddBl	}|
| W |S  ty   Y |S w )Cz(Construct and return an argument parser.r1   zAn archive file manager.)descriptionepilogformatter_classz	--verbosez-vcountr   r   z.verbose operation; can be given multiple times)actiondefaultdesthelpz--quietz-qquietzMquiet operation; if given twice suppresses error output from archive commandsz--non-interactiver   Tstore_falsezdon't query for user input (i.e. passwords or when overwriting duplicate files); use with care since overwriting files or ignoring passwords could be unintended)r8   r7   r6   r9   zGthe archive command; type "patool COMMAND -h" for command-specific helpcommand)r9   r8   requiredextractzextract one or more archives)r9   z--outdirzoutput directory to extract toz
--passwordzpassword for encrypted filesr   +zan archive file)nargsr9   listz$list members or one or more archivescreatezcreate an archivezpassword to encrypt fileszCthe archive file; the file extension determines the archive programr    zea file or directory to add to the archive; note that some archive programs do not support directoriestestztest an archiveZrepackz'repack an archive to a different formatr*   zsource archive filer+   ztarget archive filediffz%show differences between two archivesr%   zthe first archive filer&   zthe second archive filesearchz"search contents of archive membersr(   z%the grep(1) compatible search patternzthe archive fileformatszshow supported archive formatsversionzprint version informationN)ExamplesVersionargparseArgumentParserRawDescriptionHelpFormatteradd_mutually_exclusive_groupadd_argumentadd_subparsers
add_parserargcompleteautocompleteImportError)r3   parsergroupZ
subparsersZparser_extractZparser_listZparser_createZparser_testZparser_repackZparser_diffZparser_searchrQ   r   r   r   create_argparser   s   rV   c                 C   s   d}zt  }|j| d}|jr|j |_t d|j  |}W |S  ty1   td d}Y |S  ty?   t	  d}Y |S w )z#Parse options and execute commands.r   r-   Zrun_Zabortedr   r$   )
rV   
parse_argsr:   r   globalsr<   KeyboardInterruptr   	Exceptionr   )r   r   Z	argparserZpargsr   r   r   main#  s"   
r[   c                   C   s   t t  dS )zRun main() function.N)sysexitr[   r   r   r   r   main_cli6  s   r^   )N)$__doc__r\   rJ    r   r   r   r   r   r   r	   r
   utilr   logr   r   configurationr   	Namespaceintr   r   r   r"   r'   r)   r,   r.   r0   rH   rI   rK   rV   r[   r^   r   r   r   r   <module>   s.   (
c