0{Y9@sddlZddlZddlZddlZddlZddlZddlmZmZm Z ddl m Z ddl m Z ddlmZGdddeZdS)N) display_path backup_dirrmtree)logger)InstallationError)CommandcseZdZdZdZdZdZfddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZS) ZipCommandzZip individual packages.zipz# %prog [options] ...z$DEPRECATED. Zip individual packages.c s9tt|j|||jdkrM|jjdddddddn(|jjd dd ddd d dd |jjddddddd|jjdddddddd|jjddddddd|jjddddddd|jjdddddd|jjd|jdS) Nr z--unzipaction store_truedestunziphelpz"Unzip (rather than zip) a package.z--zip store_falsedefaultTz"Zip (rather than unzip) a package.z--no-pycno_pyczEDo not include .pyc files in zip files (useful on Google App Engine).z-lz--listlistz2List the packages available, and their zip status.z --sort-files sort_fileszDWith --list, sort packages according to how many files they contain.z--pathappendpathsz?Restrict operations to the given paths (may include wildcards).z-nz --simulatez0Do not actually perform the zip/unzip operation.r)superr__init__namecmd_opts add_optionparserinsert_option_group)selfargskw) __class__+/tmp/pip-ok8sy_ze-build/pip/commands/zip.pyrsL          zZipCommand.__init__cCsp|jstjSg}t}xtjD]}tjjtjj|}x|jD]}tjjtjj|}d|krtjt j |d|r|j ||j |PqqW|j |rW|j ||j |PqWqWWtjd|dj|jfq)WxJ|jD]?}||kr)d|kr)|j |tjd|q)q)W|S)z:All the entries of sys.path, possibly restricted by --path*z,Skipping path %s because it doesn't match %sz, zDAdding path %s because it doesn't match anything already on sys.path) select_pathssyspathsetosnormcaseabspathresearchfnmatch translateradd startswithrdebugjoin)rresult match_anyr&matchr!r!r"r>s2          zZipCommand.pathscCsVtjdd|j|_|j|_|jrA|j||S|sVtdng}x|D]}|j|\}}|jrt j j |rtd||fn6|j rt j j | rtd||fn|j ||fqcWd}xJ|D]B\}}|jr6|j ||}q |j|||j}q W|S)Nz1.7z_DEPRECATION: 'pip zip' and 'pip unzip` are deprecated, and will be removed in a future release.z2You must give at least one package to zip or unzipz;The module %s (in %s) is not a zip file; cannot be unzippedz:The module %s (in %s) is not a directory; cannot be zipped)r deprecatedrr$simulaterr find_packager r(r&isdirr unzip_package zip_packager)roptionsrpackagesarg module_namefilename last_statusr!r!r"run\s4      zZipCommand.runc Cstjj|}tjj| rPtj|rPtd|||fntjj|}||jkrtj dt |t |t |fntj d|t |f|j rtj ddStj d7_ ztj|}g}x|jD] }|j}|j|tjjr|j|} tjj||} tjjtjj| stjtjj| n| r| jtjjrtjj| stj| qqt| d} | j| | jq|j||j|fqW|j|sbtjdt |tj||j|n`tjd|t |ftj|d }x$|D]\}} |j|| qW|jWdtj d8_ XdS) Nz3Module %s (in %s) isn't located in a zip file in %sz/Unpacking %s into %s, but %s is not on sys.pathzUnzipping %s (in %s)z3Skipping remaining operations because of --simulatewbzRemoving now-empty zip file %sz(Removing entries in %s/ from zip file %sw) r(r&dirnameisfilezipfile is_zipfilerrrwarnrnotifyr7indentZipFileinfolistr@r0sepreadr2existsmakedirsendswithopenwritecloserinfounlinkremove_filename_from_pthwritestr) rr?r@ zip_filename package_pathr to_saverWrcontentr fr!r!r"r:{sX"        zZipCommand.unzip_packagecCsN|}tjd|t|ftjd7_|jdrJ|}n |d}z||krt|}tjd||f|jstj||qnyvtj dt||jst j |d}|j |dd xt j|D]\}}} |r)d d | D} nx|d f| d fgD]\} } x| D]} t jj|| } t jj||t|djt jj| }| r|j |dd qU|j| |qUWqBWqW|jntj dt||jst|nWn YnX|j|Wdtjd8_XdS)NzZip %s (in %s)rCz.eggz.zipzMoving %s aside to %szCreating zip file in %srE/cSs+g|]!}|jjds|qS)z.pyc)lowerrS).0r_r!r!r" s z*ZipCommand.zip_package..TFzRemoving old directory %s)rrKrrLrSrr7shutilmoverWrHrMrZr(walkr&r2lenlstriprOrUrVradd_filename_to_pth)rr?r@r orig_filename dest_filenamer dirpathdirnames filenamesfnsis_dirfnfullr r!r!r"r;sF      % 7  zZipCommand.zip_packagecsx|jD]}t|d}|j}|jfdd|D}||kr tjdtt|fdd|Dstjdt||jstj |qn2|jst|d}|j ||jndSq Wtj dtdS) Nrcs(g|]}|jkr|qSr!)strip)rcl)r@r!r"rds z7ZipCommand.remove_filename_from_pth..z*Removing reference to %s from .pth file %scSsg|]}|r|qSr!r!)rcliner!r!r"rds z %s file would be empty: deletingrDz.Cannot find a reference to %s in any .pth file) pth_filesrT readlinesrVrrWrr7r(rX writelinesrJ)rr@pthr_lines new_linesr!)r@r"rYs$        z#ZipCommand.remove_filename_from_pthcCstjj|}|d}||jkrHtjdt|n|jstjj|rt |}|j }|j |r|dj d r|dd7Lsz!ZipCommand.list..zUnzipped packages:z%s (%i files)zNo unzipped packages.)rrr)rsortedrr(r&rQbasenamerstriprOrGrHrIrFrrKrreplacerSrLrsplitextrbrWr2r9r count_packagersort) rr<rr&rzippedunzippedr@extrscountr!r!r"rsf !!       zZipCommand.listcCsPd}xCtj|D]2\}}}dd|D}|t|7}qW|S)NrcSs+g|]!}|jjds|qS)z.pyc)rbrS)rcr_r!r!r"rd\s z,ZipCommand.count_package..)r(rgrh)rr&totalrmrnror!r!r"rYs zZipCommand.count_package)__name__ __module__ __qualname____doc__rusagesummaryrrrBr:r;rYrjrxr8rrr!r!)r r"r s *   3 ,     ;r)r%r+r-r(rerHpip.utilrrrpip.logrpip.exceptionsrpip.basecommandrrr!r!r!r"s