B äxácF!ã@sDdZddlZddlmZddlZy ddlZWnek rDdZYnXddlmZddl m Z ddl m Z ddl mZyddlmZWnek rždZYnXydd lmZWnek rÈdZYnXd d „Zd d „Zd#dd„Zd$dd„ZedgdfedgdfedgdfedgdfedgdfegdfdœZdd „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|dkrdSy t|ƒ}Wntk r8d}YnX|dk rJ|dSdS)z"Returns a gid, given a group name.Né)rÚKeyError)ÚnameÚresult©r ú;/opt/alt/python37/lib64/python3.7/distutils/archive_util.pyÚ_get_gids  rcCsNtdks|dkrdSy t|ƒ}Wntk r8d}YnX|dk rJ|dSdS)z"Returns an uid, given a user name.Nr )rr )r r r r rÚ_get_uid+s  rÚgzipcs.ddddddœ}dddd d œ}|d k r:|| ¡kr:td ƒ‚|d } |dkrZ| | |d¡7} ttj | ¡|ddd l} t  d¡t ˆƒ‰t ˆƒ‰‡‡‡‡fdd„} |sØ|   | d||¡} z| j || dWd |  ¡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. ZgzÚ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,ˆdk rˆ|_ˆ|_ˆdk r(ˆ|_ˆ|_|S)N)ÚgidZgnameÚuidÚuname)Ztarinfo)rÚgroupÚownerrr rÚ _set_uid_gidasz"make_tarball.._set_uid_gidzw|%s)Úfilterz'compress' will be deprecated.Zwin32z-f)ÚkeysÚ ValueErrorÚgetrÚosÚpathÚdirnameÚtarfilerÚinforrÚopenÚaddÚcloserÚPendingDeprecationWarningÚsysÚplatformr)Ú base_nameÚbase_dirrÚverboserrrZtar_compressionZ compress_extZ archive_namer%rÚtarZcompressed_nameÚcmdr )rrrrrÚ make_tarball7s<          r2c Cs®|d}ttj |¡|dtdkrp|r.d}nd}ytd|||g|dWn tk rjtd|ƒ‚YnXn:t d||¡|sªytj |d tj d }Wn&t k rÀtj |d tj d }YnX|tj krútj tj |d ¡¡}| ||¡t d |¡x¦t |¡D]˜\}} } x>| D]6} tj tj || d ¡¡}| ||¡t d |¡qWxJ| D]B} tj tj || ¡¡}tj |¡rV| ||¡t d |¡qVWqW| ¡|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.zip)rNz-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)Z compressionrz adding '%s')rr"r#r$Úzipfilerrrr&ZZipFileZ ZIP_DEFLATEDÚ RuntimeErrorZ ZIP_STOREDÚcurdirÚnormpathÚjoinÚwriteÚwalkÚisfiler)) r-r.r/rZ zip_filenameZ zipoptionsr3r#ÚdirpathZdirnamesÚ filenamesr r r rÚ make_zipfilesJ          r?)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)ZgztarZbztarZxztarZztarr0r3cCsx|D]}|tkr|SqWdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ÚARCHIVE_FORMATS)ZformatsÚformatr r rÚcheck_archive_formatsÄs rBc Csðt ¡}|dk r6t d|¡tj |¡}|s6t |¡|dkrDtj}d|i} y t|} Wn t k rxt d|ƒ‚YnX| d} x| dD]\} } | | | <qŒW|dkr¸|| d<|| d <z| ||f| Ž}Wd|dk rêt d |¡t |¡X|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'rér3rrzchanging back to '%s') r"ÚgetcwdrÚdebugr#ÚabspathÚchdirr7r@r r )r-rAZroot_dirr.r/rrrZsave_cwdÚkwargsZ format_infoÚfuncÚargÚvalÚfilenamer r rÚ make_archiveÎs2       rM)rrrNN)rr)NNrrNN)Ú__doc__r"Úwarningsrr+r5Ú ImportErrorZdistutils.errorsrZdistutils.spawnrZdistutils.dir_utilrZ distutilsrÚpwdrZgrprrrr2r?r@rBrMr r r rÚsB            G =