MMa&@sdZddlZddlmZddlZyddlZWnek rXdZYnXddlmZddl m Z ddl m Z ddl mZyddlmZWnek rdZYnXydd lmZWnek rdZYnXd d Zd d ZdddddddZddddZded&gdfded'gdfded(gdfded)gdfded*gdfd egd!fiZd"d#Zddddddd$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)getgrnamc Cs_tdks|dkrdSyt|}Wntk rFd}YnX|dk r[|dSdS)z"Returns a gid, given a group name.N)rKeyError)nameresultr ;/opt/alt/python35/lib64/python3.5/distutils/archive_util.py_get_gids   rc Cs_tdks|dkrdSyt|}Wntk rFd}YnX|dk r[|dSdS)z"Returns an uid, given a user name.Nr )rr )r r r r r_get_uid+s   rgzipc sddddddddddi}dd dd dd dd i}|dk rl||jkrltd |d} |dkr| |j|d7} ttjj| d|ddl} tj dt t fdd} |sE| j | d||} z| j |d| Wd| jX|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. rZgzbzip2bz2xzNcompressz.gzz.bz2z.xzz.ZzKbad value for 'compress': must be None, 'gzip', 'bzip2', 'xz' or 'compress'z.tardry_runrzCreating tar archivecs@dk r|_|_dk r<|_|_|S)N)gidZgnameuiduname)Ztarinfo)rgroupownerrr r _set_uid_gidas      z"make_tarball.._set_uid_gidzw|%sfilterz'compress' will be deprecated.win32z-f)keys ValueErrorgetrospathdirnametarfilerinforropenaddcloserPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserrrZtar_compressionZ compress_extZ archive_namer&rtarZcompressed_namecmdr )rrrrr make_tarball7s<             r3c Cs|d}ttjj|d|tdkr|rAd}nd}y td|||gd|Wqtk rtd|YqXntjd|||sytj |d d tj }Wn-t k rtj |d d tj }YnXxtj |D]t\}}} xb| D]Z} tjjtjj|| } tjj| r|j| | tjd | qWqW|j|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 itwZ compressionz adding '%s')rr#r$r%zipfilerrrr'ZZipFileZ ZIP_DEFLATED RuntimeErrorZ ZIP_STOREDwalknormpathjoinisfilewriter*) r.r/r0rZ zip_filenameZ zipoptionsr4dirpathZdirnames filenamesr r$r r r make_zipfiles:         ! r?Zgztarrzgzip'ed tar-fileZbztarrzbzip2'ed tar-fileZxztarrzxz'ed tar-fileZztarzcompressed tar filer1zuncompressed tar filer4zZIP filecCs%x|D]}|tkr|SqWdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ARCHIVE_FORMATS)Zformatsformatr r rcheck_archive_formatss  rBcCs7tj}|dk rMtjd|tjj|}|sMtj||dkrbtj}d|i} yt|} Wn"t k rt d|YnX| d} x"| dD]\} } | | | sB         G5