a „oe|!ã@s>dZddlZddlmZddlZz ddlZWneyBdZYn0ddlmZddl m Z ddl m Z ddl m Z zdd lmZWneyšdZYn0zdd lmZWneyÂdZYn0d d „Zd d„Zd$dd„Zd%dd„ZedgdfedgdfedgdfedgdfedgdfegdfdœZd d!„Zd&d"d#„ZdS)'zodistutils.archive_util Utility functions for creating archive files (tarballs, zip files, that sort of thing).éN)Úwarné)ÚDistutilsExecError)Úspawn)Úmkpath)Úlog)Úgetpwnam)ÚgetgrnamcCsLtdus|durdSz t|ƒ}Wnty6d}Yn0|durH|dSdS)z"Returns a gid, given a group name.Né)r ÚKeyError©ÚnameÚresult©rúCC:\Program Files\Certbot\pkgs\setuptools\_distutils\archive_util.pyÚ_get_gid s   rcCsLtdus|durdSz t|ƒ}Wnty6d}Yn0|durH|dSdS)z"Returns an uid, given a user name.Nr )rr r rrrÚ_get_uid-s   rÚgzipcs6ddddddœ}dddd d œ}|d ur:|| ¡vr:td ƒ‚|d } |dkrZ| | |d¡7} ttj | ¡|d�dd l} t  d¡t ˆƒ‰t ˆƒ‰‡‡‡‡fdd„} |sà|   | d||¡} z| j || d�W|  ¡n |  ¡0|dk�r2tdtƒ| ||} tjdk�r|| | g}n |d| g}t||d�| S| S)a=Create a (possibly compressed) tar file from all the files under 'base_dir'. 'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or None. ("compress" will be deprecated in Python 3.2) 'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owner and group will be used. The output tar file will be named 'base_dir' + ".tar", possibly plus the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z"). Returns the output filename. ÚgzÚbz2ÚxzÚ)rÚbzip2rNÚcompressz.gzz.bz2z.xzz.Z)rrrrNzKbad value for 'compress': must be None, 'gzip', 'bzip2', 'xz' or 'compress'z.tarr©Údry_runrzCreating tar archivecs,ˆdurˆ|_ˆ|_ˆdur(ˆ|_ˆ|_|S)N)ÚgidÚgnameÚuidÚuname)Útarinfo©rÚgroupÚownerrrrÚ _set_uid_gidjsz"make_tarball.._set_uid_gidzw|%s)Úfilterz'compress' is deprecated.Úwin32z-f)ÚkeysÚ ValueErrorÚgetrÚosÚpathÚdirnameÚtarfilerÚinforrÚopenÚaddÚcloserÚDeprecationWarningÚsysÚplatformr)Ú base_nameÚbase_dirrÚverboserr#r"Útar_compressionÚ compress_extÚ archive_namer-r$ÚtarZcompressed_nameÚcmdrr!rÚ make_tarball:sDûÿ         r=c Cs¼|d}ttj |¡|d�tdurn|r.d}nd}ztd|||g|d�Wntyhtd|ƒ‚Yn0�nJt d||¡|�s¸ztj |d tj d �}Wn$t y¼tj |d tj d �}Yn0|�ä|tj krütj tj |d ¡¡}| ||¡t d |¡t |¡D]�\}} } | D]6} tj tj || d ¡¡}| ||¡t d |¡�q| D]B} tj tj || ¡¡}tj |¡�rP| ||¡t d |¡�qP�qWdƒn1�s®0Y|S) avCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises DistutilsExecError. Returns the name of the output zip file. z.ziprNz-rz-rqÚzipzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utilityz#creating '%s' and adding '%s' to itÚw)Ú compressionrz adding '%s')rr*r+r,Úzipfilerrrr.ÚZipFileÚ ZIP_DEFLATEDÚ RuntimeErrorZ ZIP_STOREDÚcurdirÚnormpathÚjoinÚwriteÚwalkÚisfile) r5r6r7rÚ zip_filenameZ zipoptionsr>r+ÚdirpathÚdirnamesÚ filenamesr rrrÚ make_zipfile‰sL  ûÿ ÿ       4rO)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)ÚgztarÚbztarÚxztarZztarr;r>cCs|D]}|tvr|SqdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ÚARCHIVE_FORMATS)ÚformatsÚformatrrrÚcheck_archive_formatsÓs rVc Cst ¡}|dur6t d|¡tj |¡}|s6t |¡|durDtj}d|i} z t|} Wnt yvt d|ƒ‚Yn0| d} | dD]\} } | | | <qˆ|dkr²|| d<|| d <z4| ||fi| ¤Ž}W|duræt d |¡t |¡n"|du�rt d |¡t |¡0|S) aüCreate an archive file (eg. zip or tar). 'base_name' is the name of the file to create, minus any format-specific extension; 'format' is the archive format: one of "zip", "tar", "gztar", "bztar", "xztar", or "ztar". 'root_dir' is a directory that will be the root directory of the archive; ie. we typically chdir into 'root_dir' before creating the archive. 'base_dir' is the directory where we start archiving from; ie. 'base_dir' will be the common prefix of all files and directories in the archive. 'root_dir' and 'base_dir' both default to the current directory. Returns the name of the archive file. 'owner' and 'group' are used when creating a tar archive. By default, uses the current owner and group. Nzchanging into '%s'rzunknown archive format '%s'rrr>r#r"zchanging back to '%s') r*ÚgetcwdrÚdebugr+ÚabspathÚchdirrErSr r()r5rUÚroot_dirr6r7rr#r"Úsave_cwdÚkwargsÚ format_infoÚfuncÚargÚvalÚfilenamerrrÚ make_archiveÞs8        þ   rc)rrrNN)rr)NNrrNN)Ú__doc__r*Úwarningsrr3rAÚ ImportErrorÚerrorsrrZdir_utilrZ_logrÚpwdrÚgrpr rrr=rOrSrVrcrrrrÚsN             ÿ O A     ú ø