o ?Og|!@sFdZddlZddlmZddlZzddlZWn ey!dZYnwddlmZddl m Z ddl m Z ddl mZzddlmZWn eyMdZYnwzdd lmZWn eyadZYnwd d Zd d Z  d#ddZd$ddZedgdfedgdfedgdfedgdfedgdfegdfdZdd Z  d%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)getgrnamcCLtdus|dur dSzt|}Wn tyd}Ynw|dur$|dSdS)z"Returns a gid, given a group name.N)rKeyErrornameresultr=/opt/alt/python310/lib64/python3.10/distutils/archive_util.py_get_gid  rcCr )z"Returns an uid, given a user name.Nr )rr r rrr_get_uid+rrgzipcs2dddddd}dddd d }|d ur||vrtd |d } |dkr-| ||d7} ttj| |ddd l} t dt t fdd} |sp| | d||} z | j || dW| n| w|dkrtdt| ||} 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,dur |_|_dur|_|_|S)N)gidZgnameuiduname)Ztarinforgroupownerrrr _set_uid_gidasz"make_tarball.._set_uid_gidzw|%s)filterz'compress' will be deprecated.Zwin32z-f)keys ValueErrorgetrospathdirnametarfilerinforropenaddcloserPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserr!r Ztar_compressionZ compress_extZ archive_namer*r"tarZcompressed_namecmdrrr make_tarball7sB        r7c Cs|d}ttj||dtdur4|rd}nd}z td|||g|dW|Sty3td|wtd|||sz tj |d tj d }Wnt yZtj |d tj d }Ynw|o|tj krztjtj|d }|||td |t|D]D\}} } | D]} tjtj|| d }|||td |q| D]} tjtj|| }tj|r|||td |qqWd|S1swY|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) r2r3r4rZ zip_filenameZ zipoptionsr8r(dirpathZdirnames filenamesr rrr make_zipfilesf  %           rD)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)ZgztarZbztarZxztarZztarr5r8cCs|D] }|tvr |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 rGc Cst}|durtd|tj|}|st||dur"tj}d|i} zt|} Wn t y9t d|w| d} | dD]\} } | | | <qB|dkrW|| d<|| d <z| ||fi| }W|durqtd |t||S|durtd |t|ww) 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'rr8r!r zchanging back to '%s') r'getcwdrdebugr(abspathchdirr<rEr r%)r2rFZroot_dirr3r4rr!r Zsave_cwdkwargsZ format_infofuncargvalfilenamerrr make_archives<           rR)rrrNN)rr)NNrrNN)__doc__r'warningsrr0r: ImportErrorZdistutils.errorsrZdistutils.spawnrZdistutils.dir_utilrZ distutilsrpwdrZgrprrrr7rDrErGrRrrrrsP            H =