\d|!BdZddlZddlmZddlZ ddlZn #e$rdZYnwxYwddlmZddl m Z ddl m Z ddl mZ ddlmZn #e$rdZYnwxYw dd lmZn #e$rdZYnwxYwd Zd Z dd ZddZedgdfedgdfedgdfedgdfedgdfegdfdZdZ ddZdS) zodistutils.archive_util Utility functions for creating archive files (tarballs, zip files, that sort of thing).N)warn)DistutilsExecError)spawn)mkpath)log)getpwnam)getgrnamcvt|dS t|}n#t$rd}YnwxYw||dSdS)z"Returns a gid, given a group name.N)r KeyErrornameresults '..\python\lib\distutils\archive_util.py_get_gidr\4<t$  ay 4  ,,cvt|dS t|}n#t$rd}YnwxYw||dSdS)z"Returns an uid, given a user name.Nr )rr r s r_get_uidr+rrgzipcdddddd}dddd d }|%||vrtd |d z} |dkr| ||dz } ttj| |dd l} tj dttfd} |se| | d||z} | || | n#| wxYw|dkrNtdt | ||z} t"jdkr|| | g}n|d| g}t'||| 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. gzbz2xz)rbzip2rNcompressz.gzz.bz2z.xzz.Z)rrrrNzKbad value for 'compress': must be None, 'gzip', 'bzip2', 'xz' or 'compress'z.tarrdry_runrzCreating tar archivecH|_|_|_|_|S)N)gidgnameuiduname)tarinfor!groupownerr#s r _set_uid_gidz"make_tarball.._set_uid_gidas. ?GK!GM ?GK!GMzw|%s)filterz'compress' will be deprecated.win32z-f)keys ValueErrorgetrospathdirnametarfilerinforropenaddcloserPendingDeprecationWarningsysplatformr) base_namebase_dirrverboserr'r&tar_compression compress_ext archive_namer2r(tarcompressed_namecmdr!r#s `` @@r make_tarballrC7s" $e4r#%''O!F% $&&L 0A0A0C0C C C#$$ $v%L: ((2666  27??< ( ('::::NNNH #$$$ 5//C 5//C ll</(2K)KLL  GGH\G 2 2 2 IIKKKKCIIKKKK: -/HIII&h)?? <7 " "\?;CCT<0C c7#### s -DD/c &|dz}ttj||t?|rd}nd} t d|||g|n7#t $rt d|zwxYwtjd|||s t j |d tj }n1#t$r$t j |d tj }YnwxYw|5|tj krhtjtj|d }|||tjd |tj|D]\}} } | D]k} tjtj|| d }|||tjd |l| D]} tjtj|| }tj|r+|||tjd | dddn #1swxYwY|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) compressionrz adding '%s')rr/r0r1zipfilerrrr3ZipFile ZIP_DEFLATED RuntimeError ZIP_STOREDcurdirnormpathjoinwritewalkisfile) r:r;r<r zip_filename zipoptionsrEr0dirpathdirnames filenamesrs r make_zipfilerXsv%L 27??< ( ('::::  JJJ D 5*lH=! # # # # #! D D D%'36B&CDD D D 6x ) ) ) : FolC292FHHH F F FolC292DFFF F : :ry((7++BGLL2,F,FGGDIIdD)))H]D11146GH4E4E : :0GXy (66!w// WdB0O0OPP $---5555 )::!w// Wd0K0KLL7>>$//:IIdD111H]D999 : :  : : : : : : : : : : : : : : : s1AA7!B66+C$#C$)FJJ  J )rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rrzxz'ed tar-file)rrzcompressed tar file)rNzuncompressed tar filezZIP file)gztarbztarxztarztarr@rEc*|D]}|tvr|cSdS)zqReturns the first format from the 'format' list that is unknown. If all formats are known, returns None N)ARCHIVE_FORMATS)formatsformats rcheck_archive_formatsras1   ( (MMM ) 4r)cltj}|Jtjd|tj|}|stj|| tj}d|i} t|} n #t$rtd|zwxYw| d} | dD] \} } | | | < |dkr || d<|| d < | ||fi| }|)tjd |tj|n1#|*tjd |tj|wwxYw|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'rrEr'r&zchanging back to '%s') r/getcwdrdebugr0abspathchdirrMr^r r-)r:r`root_dirr;r<rr'r&save_cwdkwargs format_infofuncargvalfilenames r make_archiverps}$y{{H &111GOOI..   HX   9 !FA%f- AAA6?@@@A q>DNSs  ww4 866v66   I-x 8 8 8 HX      I-x 8 8 8 HX      Os3 BB D.D1)rrrNN)rr)NNrrNN)__doc__r/warningsrr8rH ImportErrordistutils.errorsrdistutils.spawnrdistutils.dir_utilr distutilsrpwdrgrpr rrrCrXr^rarpr)rr{s   NNNNGGG0/////!!!!!!%%%%%%HHHHHH      KL#'FFFFP::::z124F G235H I/02B C568M N/02I JBz * KL.2222222s/!!AA AAA#"A#