e fL@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddZ ddZ ddZdd Zd d ZdS) NcCstjdd}|jddd|jddddd d d tjj|j}d }yttt |Wn>t k r}ztd j |d}WYdd}~XnXt j ddS)NZ descriptionz,Recreate wheel of package with given RECORD. record_pathhelpzPath to RECORD filez-oz --output-dirz>Dir where to place the wheel, defaults to current working dir.destoutdirdefaultrz Failed: {})argparseArgumentParser add_argumentospathcurdir parse_argsprintrewheel_from_recordvars BaseExceptionformatsysexit)parsernsZretcodeer?/opt/alt/python34/lib64/python3.4/ensurepip/rewheel/__init__.pyrun s   rcsg}tjtjtjg}dd|D}x|D]}d}x|D]tjj|djtj fddtj D}fdd|D}t |dkrN|d}qNqNW|dk r|j tjj|d q;|j dq;W|S) zReturn list of paths to RECORD files for system-installed projects. If a project is not installed, the resulting list contains None instead of a path to its RECORD cSs(g|]}tjj|r|qSr)r r exists).0sprrr (s z'find_system_records..Nz-[^\{0}]+\.dist-infocs%g|]}tjj|qSr)r r join)rp)rrrr.s cs(g|]}tj|r|qSr)rematch)rc) dist_info_rerrr0s rrZRECORD) sitegetsitepackagesr base_prefixbase_exec_prefixr r r rseplistdirlenappend)ZprojectsZrecordsZ sys_sitepackZprojectr Z candidatesZfilteredr)r%rrfind_system_recordss  %" r.cCsEtjjtjj|}|t|djtjj}t||\}}t|}tjj||d}t j |dddt j }t j } tj| } xO|D]G\} } } |jtjj|| d| | j| | | gqW| j|ddg|j|| j|j|jS)zcRecreates a whee of package with given record_path and returns path to the newly created wheel.Nz.whlmodewZ compressionZarcname)r r dirnamer,stripr*get_records_to_packget_wheel_namer zipfileZZipFileZ ZIP_DEFLATEDioStringIOcsvwriterwriteZwriterowZwritestrgetvalueclosefilename)rrsite_dirrecord_relpathto_writeto_omitZnew_wheel_nameZnew_wheel_pathZ new_wheelZ new_recordr:fZsha_hashsizerrrr:s%  " rcCstjjtjj|d}tj|dd%}tjjj |j }WdQXtjjtjj|d}tj|dd%}tjjj |j }WdQX|j d}|j d}d} g} x1|j d D] } | j | jd d qWd j| } |j d jd d d\} } td||| | | | g}d jt|S)z.Return proper name of the wheel, without .whl.ZWHEELencodingzutf-8NZMETADATANameZVersionr1ZTag-r.r)r r r r2codecsopenemailrZParserZparsestrreadgetZget_allr-splitfilterlist)rZwheel_info_pathZwheel_info_fileZ wheel_infoZ metadata_pathZ metadata_fileZmetadataZ distributionversionZ build_tagZlang_tagtZabi_tagZplat_tagZto_joinrrrr5Vs !$!$(!r5c Cs[tjj||}tj|dd}|j}WdQXtjj|jtjj}|dt d d}g}g}x|j D]}|j d} t | dkrtjj | ds-| dj d s-| djd s-| djd s-| d|ks-| dj |r=|j| qM|j| qqW||fS) aAccepts path of sitedir and path of RECORD file relative to it. Returns two lists: - list of files that can be written to new RECORD straight away - list of files that shouldn't be written or need some processing (pyc and pyo files, scripts) rEzutf-8Nz dist-infodata,rIrz..z.pycz.pyo)r r r rJrKrMr2r3r*r, splitlinesrOisabs startswithendswithr-) r?r@Zrecord_file_pathZ record_fileZrecord_contentsZdata_dirrArBlZsplrrrr4ns"!)&#r4)rrJr9Z email.parserrLr r7r"r& subprocessrr6rr.rr5r4rrrrs