3  fL@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddZ ddZ ddZdd Zd d ZdS) NcCstjdd}|jddd|jdddd tjjd |j}d }yttft |Wn4t k r}ztd j |d }WYdd}~XnXt j d dS)Nz,Recreate wheel of package with given RECORD.)Z description record_pathzPath to RECORD file)helpz-oz --output-dirz>Dir where to place the wheel, defaults to current working dir.outdir)rdestdefaultrz Failed: {})argparseArgumentParser add_argumentospathcurdir parse_argsprintrewheel_from_recordvars BaseExceptionformatsysexit)parsernsZretcodeer?/opt/alt/python36/lib64/python3.6/ensurepip/rewheel/__init__.pyrun s  rcsg}tjtjtjg}dd|D}x|D]}d}xd|D]\tjj|djtj fddtj D}fdd|D}t |dkr8|d}q8W|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 cSsg|]}tjj|r|qSr)r r exists).0sprrr (sz'find_system_records..Nz-[^\{0}]+\.dist-infocsg|]}tjj|qSr)r r join)rp)rrrr.scsg|]}tj|r|qSr)rematch)rc) dist_info_rerrr0srrZRECORD) sitegetsitepackagesr base_prefixbase_exec_prefixr r r rseplistdirlenappend)ZprojectsZrecordsZ sys_sitepackZprojectr Z candidatesZfilteredr)r%rrfind_system_recordss    r.cCstjjtjj|}|t|djtjj}t||\}}t|}tjj||d}t j |dt j d}t j } tj| } x:|D]2\} } } |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.whlw)modeZ compression)Zarcname)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 }WdQRXtjjtjj|d}tj|dd}tjjj |j }WdQRX|j d}|j d}d} g} x&|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.ZWHEELzutf-8)encodingNZMETADATANameZVersionr1ZTag-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 Cstjj||}tj|dd}|j}WdQRXtjj|jtjj}|dt d d}g}g}x|j D]}|j d} t | dkrntjj | ds| dj d s| djd s| djd s| d|ks| dj |r|j| q|j| qnqnW||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) zutf-8)rENz 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