3 ¦ fLã@s„ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z dd„Z dd„Z dd„Zdd „Zd d „ZdS) éNcCs˜tjdd�}|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)rÚdestÚdefaultrz Failed: {}é)ÚargparseÚArgumentParserÚ add_argumentÚosÚpathÚcurdirÚ parse_argsÚprintÚrewheel_from_recordÚvarsÚ BaseExceptionÚformatÚsysÚexit)ÚparserÚnsZretcodeÚe©rú?/opt/alt/python36/lib64/python3.6/ensurepip/rewheel/__init__.pyÚrun s  rcsÈg}tjtjtjgƒ}dd„|Dƒ}xž|D]–}d}xd|D]\‰tjjˆ|ƒdjtj ƒ‰‡fdd„tj ˆƒDƒ}‡fdd„|Dƒ}t |ƒdkr8|d}q8W|dk r¶|j tjj|d ƒƒq*|j dƒq*W|S) z±Return 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)Ú.0Úsprrrú (sz'find_system_records..Nz-[^\{0}]+\.dist-infocsg|]}tjjˆ|ƒ‘qSr)r r Újoin)rÚp)rrrr.scsg|]}tjˆ|ƒr|‘qSr)ÚreÚmatch)rÚc)Ú dist_info_rerrr0srrZRECORD) ÚsiteÚgetsitepackagesrÚ base_prefixÚbase_exec_prefixr r r rÚsepÚlistdirÚlenÚappend)ZprojectsZrecordsZ sys_sitepackZprojectr Z candidatesZfilteredr)r%rrÚfind_system_recordss    r.cCsätjjtjj|ƒƒ}|t|ƒd…jtjjƒ}t||ƒ\}}t|ƒ}tjj||dƒ}t j |dt j d�}t j ƒ} tj| ƒ} x:|D]2\} } } |jtjj|| ƒ| d�| j| | | gƒq€W| j|ddgƒ|j|| jƒƒ|jƒ|jS)zcRecreates a whee of package with given record_path and returns path to the newly created wheel.Nz.whlÚw)ÚmodeZ compression)ZarcnameÚ)r r Údirnamer,Ústripr*Úget_records_to_packÚget_wheel_namer ÚzipfileZZipFileZ ZIP_DEFLATEDÚioÚStringIOÚcsvÚwriterÚwriteZwriterowZwritestrÚgetvalueÚcloseÚfilename)rrÚsite_dirÚrecord_relpathÚto_writeÚto_omitZnew_wheel_nameZnew_wheel_pathZ new_wheelZ new_recordr:ÚfZsha_hashÚsizerrrr:s rcCstjjtjj|ƒdƒ}tj|dd��}tjjƒj |j ƒƒ}WdQRXtjjtjj|ƒdƒ}tj|dd��}tjjƒj |j ƒƒ}WdQRX|j dƒ}|j dƒ}d} g} x&|j d ƒD]} | j | jd ƒd ƒq°Wd j| ƒ} |j d ƒjd ƒd d…\} } td||| | | | gƒ}d jt|ƒƒS)z.Return proper name of the wheel, without .whl.ZWHEELzutf-8)ÚencodingNZMETADATAÚNameZVersionr1ZTagú-rÚ.ré)r r r r2ÚcodecsÚopenÚemailrZParserZparsestrÚreadÚgetZget_allr-ÚsplitÚfilterÚlist)rZwheel_info_pathZwheel_info_fileZ wheel_infoZ metadata_pathZ metadata_fileZmetadataZ distributionÚversionZ build_tagZlang_tagÚtZabi_tagZplat_tagZto_joinrrrr5Vs    r5c Cstjj||ƒ}tj|dd��}|jƒ}WdQRXtjj|ƒjtjjƒ}|dt dƒ …d}g}g}x’|j ƒD]†}|j dƒ} t | ƒdkrntjj | dƒsÜ| 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-infoÚdataú,rIrz..z.pycz.pyo)r r r rJrKrMr2r3r*r,Ú splitlinesrOÚisabsÚ startswithÚendswithr-) r?r@Zrecord_file_pathZ record_fileZrecord_contentsZdata_dirrArBÚlZsplrrrr4ns"    r4)rrJr9Z email.parserrLr r7r"r&Ú subprocessrr6rr.rr5r4rrrrÚs