[  @sdZddlZddlmZddlZyddlZWnek rXdZYnXddlmZddl m Z ddl m Z ddl mZyddlmZWnek rdZYnXydd lmZWnek rdZYnXd d Zd d ZdddddddZddddZied#gdfd6ed$gdfd6ed%gdfd6ed&gdfd6egdfd6Zdd 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 ,/usr/lib/python3.4/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 sidd6dd6dd6dd6}idd6d d6d d6}|dk rj||jkrjtd n|d } |dkr| |j|d7} nttjj| d |ddl} tj dt t fdd} |sI| j | d||} z| j |d| Wd| jXn|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), "compress", "bzip2", 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" or ".Z"). Returns the output filename. Zgzrbz2bzip2Ncompressz.gzz.bz2z.ZzEbad value for 'compress': must be None, 'gzip', 'bzip2' or 'compress'z.tardry_runrzCreating tar archivecsFdk r!|_|_ndk rB|_|_n|S)N)gidZgnameuiduname)Ztarinfo)rgroupownerrr r _set_uid_gid_s      z"make_tarball.._set_uid_gidzw|%sfilterz'compress' will be deprecated.Zwin32z-f)keys ValueErrorgetrospathdirnametarfilerinforropenaddcloserPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserrrZtar_compressionZ compress_extZ archive_namer$rtarZcompressed_namecmdr )rrrrr make_tarball7s8"          r1c 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]w\}}} xe| D]]} tjjtjj|| } tjj| r|j| | tjd | qqWqW|jn|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-r.rZ zip_filenameZ zipoptionsr2dirpathZdirnames filenamesr r"r r r make_zipfile}s:         ! r=rzgzip'ed tar-fileZgztarrzbzip2'ed tar-fileZbztarzcompressed tar fileZztarzuncompressed tar filer/zZIP filer2cCs%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  r@cCsGtj}|dk rStjd|tjj|}|sStj|qSn|dkrktj}ni|d6} yt|} Wn"t k rt d|YnX| d} x"| dD]\} } | | | r r)r,r?Zroot_dirr-r.rrrZsave_cwdkwargsZ format_infofuncargvalfilenamer r r make_archives2           rL)compresszgzip)rMzbzip2)rMrM)rMN)__doc__r!warningsrr*r4 ImportErrorZdistutils.errorsrZdistutils.spawnrZdistutils.dir_utilrZ distutilsrpwdrZgrprrrr1r=r>r@rLr r r rsB         E4