U e5d|!@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)rKeyErrornameresultr./usr/lib64/python3.8/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. Zgzbz2xz)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)gidZgnameuiduname)Ztarinforgroupownerrrr _set_uid_gidasz"make_tarball.._set_uid_gidzw|%s)filterz'compress' will be deprecated.Zwin32z-f)keys ValueErrorgetrospathdirnametarfilerinforropencloseaddrPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserrrZtar_compressionZ compress_extZ archive_namer(r tarZcompressed_namecmdrrr make_tarball7sB          r5c 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)Z compressionrz adding '%s')rr%r&r'zipfilerrrr)ZZipFileZ ZIP_DEFLATED RuntimeErrorZ ZIP_STOREDcurdirnormpathjoinwritewalkisfile) r0r1r2rZ zip_filenameZ zipoptionsr6r&dirpathZdirnames filenamesr rrr make_zipfilesV          rB)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)ZgztarZbztarZxztarZztarr3r6cCs|D]}|tkr|SqdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ARCHIVE_FORMATS)Zformatsformatrrrcheck_archive_formatss rEc 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'rr6rrzchanging back to '%s') r%getcwdrdebugr&abspathchdirr:rCr r#)r0rDZroot_dirr1r2rrrZsave_cwdkwargsZ format_infofuncargvalfilenamerrr make_archives2       rP)rrrNN)rr)NNrrNN)__doc__r%warningsrr.r8 ImportErrorZdistutils.errorsrZdistutils.spawnrZdistutils.dir_utilrZ distutilsrpwdrZgrprrrr5rBrCrErPrrrrsN            H =