B âxácLã@s„ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z dd„Z dd„Z dd„Zdd „Zd d „ZdS) éNc Cs˜tjdd}|jddd|jdddd tjjd | ¡}d }yttft |ƒŽƒWn4t k rˆ}ztd   |¡ƒd }Wdd}~XYnXt   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/python37/lib64/python3.7/ensurepip/rewheel/__init__.pyÚrun s  rcsÈg}t tjtjg¡}dd„|Dƒ}xž|D]–}d}xd|D]\‰tj ˆ|¡d tj ¡‰‡fdd„t  ˆ¡Dƒ}‡fdd„|Dƒ}t |ƒdkr8|d}q8W|dk r¶|  tj |d ¡¡q*|  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|]}tj |¡r|‘qSr)r r Úexists)Ú.0Úsprrrú (sz'find_system_records..Nz-[^\{0}]+\.dist-infocsg|]}tj ˆ|¡‘qSr)r r Újoin)rÚp)rrrr.scsg|]}t ˆ|¡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ätj tj |¡¡}|t|ƒd… tjj¡}t||ƒ\}}t|ƒ}tj ||d¡}t j |dt j d}t   ¡} t | ¡} x:|D]2\} } } |jtj || ¡| d|  | | | g¡q€W|  |ddg¡| ||  ¡¡| ¡|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 rc Cstj tj |¡d¡}tj|dd}tj ¡  |  ¡¡}WdQRXtj tj |¡d¡}tj|dd}tj ¡  |  ¡¡}WdQRX|  d¡}|  d¡}d} g} x&|  d ¡D]} |   |  d ¡d ¡q°Wd  | ¡} |  d ¡ d ¡d d…\} } td||| | | | gƒ}d  t|ƒ¡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 Cstj ||¡}tj|dd}| ¡}WdQRXtj |¡ tjj¡}|dt dƒ …d}g}g}x’|  ¡D]†}|  d¡} t | ƒdkrntj  | d¡sÜ| d  d ¡sÜ| d d ¡sÜ| d d ¡sÜ| d|ksÜ| d  |¡rè| | ¡qô| | ¡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