U ia|!@sDdZddlZddlmZddlZz ddlZWnek rDdZYnXddlmZddl m Z ddl m Z ddl mZzddlmZWnek rdZYnXzdd lmZWnek rdZYnXd d Zd d Zd#ddZd$ddZedgdfedgdfedgdfedgdfedgdfegdfdZdd 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)getgrnamcCsNtdks|dkrdSz t|}Wntk r8d}YnX|dk rJ|dSdS)z"Returns a gid, given a group name.N)rKeyErrornameresultrz/private/var/folders/k6/_7fsz4ts3b78x3b3xwrxjh_c8s8xv7/T/pip-unpacked-wheel-yl_m2el9/setuptools/_distutils/archive_util.py_get_gids  rcCsNtdks|dkrdSz t|}Wntk r8d}YnX|dk rJ|dSdS)z"Returns an uid, given a user name.Nr )rr r rrr_get_uid+s  rgzipcs.dddddd}dddd d }|d k r:||kr:td |d } |dkrZ| ||d7} ttj| |ddd l} t dt t fdd} |s| | d||} z| j|| dW5| X|dkr*tdt| ||} tjdkr|| | 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. gzbz2xz)rbzip2rNcompressz.gzz.bz2z.xzz.Z)rrrrNzKbad value for 'compress': must be None, 'gzip', 'bzip2', 'xz' or 'compress'z.tarrdry_runrzCreating tar archivecs,dk r|_|_dk r(|_|_|S)N)gidgnameuiduname)tarinforgroupownerrrr _set_uid_gidasz"make_tarball.._set_uid_gidzw|%s)filterz'compress' will be deprecated.win32z-f)keys ValueErrorgetrospathdirnametarfilerinforropencloseaddrPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserr"r!tar_compression compress_ext archive_namer,r#tarcompressed_namecmdrr r make_tarball7sB          r=c Cs|d}ttj||dtdkrp|r.d}nd}ztd|||g|dWn tk rjtd|YnXn8td|||sztj |d tj d }Wn&t k rtj |d tj d }YnX||tj krtjtj|d }|||td |t|D]\}} } | D]6} tjtj|| d }|||td |q| D]B} tjtj|| }tj|rV|||td |qVq W5QRX|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-rqzipzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utilityz#creating '%s' and adding '%s' to itw) compressionrz adding '%s')rr)r*r+zipfilerrrr-ZipFile ZIP_DEFLATED RuntimeError ZIP_STOREDcurdirnormpathjoinwritewalkisfile) r4r5r6r zip_filename zipoptionsr>r*dirpathdirnames filenamesr rrr make_zipfilesV          rQ)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)gztarbztarxztarztarr:r>cCs|D]}|tkr|SqdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ARCHIVE_FORMATS)formatsformatrrrcheck_archive_formatss rYc Cst}|dk r6td|tj|}|s6t||dkrDtj}d|i} z t|} Wn t k rxt d|YnX| d} | dD]\} } | | | <q|dkr|| d<|| d <z| ||f| }W5|dk rtd |t|X|S) aCreate 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'rr>r"r!zchanging back to '%s') r)getcwdrdebugr*abspathchdirrFrVr r')r4rXroot_dirr5r6rr"r!save_cwdkwargs format_infofuncargvalfilenamerrr make_archives2       rg)rrrNN)rr)NNrrNN)__doc__r)warningsrr2rA ImportErrordistutils.errorsrdistutils.spawnrdistutils.dir_utilr distutilsrpwdrgrprrrr=rQrVrYrgrrrrsN            H =