o 4f/8@sddlmZddlZddlZddlZddlZddlmZmZddl Z ddl Z ddl m Z ddZ GdddeZGd d d eZGd d d eZGd ddeZddZGdddeZedkreddZeejejD]VZedejedejedejedejejikrede ej!ej"D]Z#ede#je#je#j$fqej%D] Z&ede&jqqndSdS))print_functionN)PopenPIPE)gettextc #slt}t|P}|D],}d|vr||ddd|vr/d|dvr(n||dt|EdHq WddS|D] }d|vrQ||dqDWdn1s\wYt|}t t t |}Wdn1sywY|D]l}|d|vrqdV|d d d|d<t|I}|D]>}d|vsd|dvrqd |vr|dtfd d |d dDrqt|jd i|D] }|d rq|VqqWdn1swYqt|9}|D]}d|vrd|dvrnq|D]}d|vrd|dvrqt|EdHqWddS1s/wYdS)a~Expand the given template. A template file consists of a header, followed by paragraphs of templated suites, followed by a footer. A templated suite is any paragraph where the Suite field contains {. This function expands all templated suites using the information found in the CSV file supplied by distro-info-data. It yields lines of template info. zX-Exclude-Suitesz, Suite{Nseriesversionz LTSz X-Versionc3sT|]%}|drt|dddkp%|do%t|dddkVqdS)leNrge) startswithapt_pkgversion_compare).0fieldver5/usr/lib/python3/dist-packages/aptsources/distinfo.py Zs   z#_expand_template..r)setrTagFileupdatesplitaddstr splitlinesopenreversedlistcsv DictReaderreplaceanyformatr) templatecsv_path known_suitestmplsection csv_objectreleasesrellinerrr_expand_template&sp         $r0c@$eZdZddZddZddZdS)TemplatecCsXd|_d|_g|_d|_d|_d|_d|_g|_g|_d|_ i|_ d|_ d|_ d|_ dSNFT)namechildparents match_name descriptionbase_uritype componentschildren match_uri mirror_set distribution availableofficialselfrrr__init__ys zTemplate.__init__cCs|dd|jDvS)z8 Check if the distribution provides the given component css|]}|jVqdSN)r4)rcrrrrsz)Template.has_component..)r;)rCcomprrr has_componentszTemplate.has_componentcCs.t|\}}}||jvr|j|||SdS)z8 Check if a given url of a repository is a valid mirror F) split_urlr>has_repository)rCurlprotohostnamedirrrr is_mirrors zTemplate.is_mirrorN)__name__ __module__ __qualname__rDrHrOrrrrr2ws r2c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS) ComponentNcCs||_||_||_||_dSrE)r4r8description_longparent_component)rCr4desc long_descrUrrrrDs zComponent.__init__cC|jSrErUrBrrrget_parent_componentzComponent.get_parent_componentcC ||_dSrErY)rCparentrrrset_parent_component zComponent.set_parent_componentcCs$|jdur|jS|jdur|jSdSrE)rTr8rBrrrget_descriptions  zComponent.get_descriptioncCr\rE)r8rCrVrrrset_descriptionr_zComponent.set_descriptioncCr\rErTrarrrset_description_longr_zComponent.set_description_longcCrXrErcrBrrrget_description_longr[zComponent.get_description_long)NNN) rPrQrRrDrZr^r`rbrdrerrrrrSs  rSc@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)Mirrorz( Storage for mirror related information NcCs"||_g|_|||||_dSrE)rM repositoriesadd_repositorylocation)rCrLrMrNrirrrrDs  zMirror.__init__cCs|jt||dSrE)rgappend RepositoryrCrLrNrrrrhszMirror.add_repositorycsfdd|jDS)Ncsg|] }|jkr|qSrrLrrrmrr sz5Mirror.get_repositories_for_proto..rg)rCrLrrmrget_repositories_for_protoz!Mirror.get_repositories_for_protocCs6|durdS|jD]}|j|kr||jvrdSq dSr3)rgrLrN)rCrLrNrorrrrJs zMirror.has_repositorycsfddjDS)Ncsg|]}|jqSr)get_urlrMrnrBrrrpsz(Mirror.get_repo_urls..rqrBrrBr get_repo_urlsrszMirror.get_repo_urlscCrXrErirBrrr get_locationr[zMirror.get_locationcCr\rErv)rCrirrr set_locationr_zMirror.set_locationrE) rPrQrR__doc__rDrhrrrJrurwrxrrrrrfs  rfc@r1)rkcCs||_||_dSrErLrNrlrrrrDs zRepository.__init__cCs |j|jfSrErzrBrrrget_infos zRepository.get_infocCsd|j||jfS)Nz %s://%s/%srz)rCrMrrrrtszRepository.get_urlN)rPrQrRrDr{rtrrrrrks rkcCs6tjd|dd}t|dkr|dt|dks|S)zE split a given URL into the protocoll, the hostname and the dir part z:*\/+)maxsplitr N)rerlenrj)rKrrrrrIs    rIc@seZdZdddZddZdS)DistInfoN/usr/share/python-apt/templatesc Cs8d|_g|_tjd|_d}td}td}|sPztgddt d d }Wn#t t fyO}z|jtjkrCtd |d }WYd}~nd}~ww||_i}d ||f}d |} d} d} t|| D]} | d d} t| dkr{qk| d }| d }|dkrt||_qk|dkr||_qk|dkr|| | d} t} || _|| _d|| _qk|dkr|| _qk|dkrd| _|jD]}|j|kr| j !||j"!| qqk|dkrt#|| _$qk|dkrt#|| _%qk|dkr|| _&qk|dkr| j's|| _'qk|d|jkr|| _'qk|dkr| j(s|| _(qk|d|jkr+|| _(qk|dks8|d|jkrt)j*+|rB|pLt)j*,t)j*-||}||vri}z$t.|}t/t0|j1dd |D}Wdn 1srwYWnt2yt3d!g}Ynw|D]0} | 4d"r|5d#| }qt6| \}}}||vr||7||qt8||||||<q|||<||| _9qk|d$krt|| _:qk|d%kr| r| ;| js| jt|qk|d'kr| ?t|qk|d(kr| @|qk|| | d} d} dS))Nr zAPT::Architecturez ^#LOC:(.+)$zS^(#LOC:.+)|(((http)|(ftp)|(rsync)|(file)|(mirror)|(https))://[A-Za-z0-9/\.:\-_@]+)$) lsb_releasez-iz-sT)universal_newlinesstdoutrz#lsb_release failed, using defaults:Debianz %s/%s.infoz/usr/share/distro-info/{}.csv:r| ChangelogURIMetaReleaseURIrz^%s$ MatchName ParentSuite AvailableOfficialRepositoryTypeBaseURIz BaseURI-%sMatchURIz MatchURI-%s MirrorsFilezMirrorsFile-%scSsg|]}|qSr)strip)rxrrrrpAsz%DistInfo.__init__..z#WARNING: Failed to read mirror filez#LOC:z\1 DescriptionrSCompDescriptionCompDescriptionLongParentComponent)Ametarelease_uri templatesrconfigfindarchr~compilerr communicaterOSErrorIOErrorerrnoENOENTloggingwarningdistr&lowerr0rr_changelogs_urifinish_templater2r4r?r7r5r6rjr<string_to_boolr@rAr:r9r=ospathisabsabspathjoinrr!filtermatch ExceptionprintrsubrIrhrfr>r8rHr;rSrbrdr^)rCrbase_dirri match_locmatch_mirror_lineexcmap_mirror_sets dist_fname csv_fnamer' componentr/tokensrvaluenannyr>value_f mirror_datarLrMrNrrrrDs                                  zDistInfo.__init__cCs|sdS|jdur|jr|jD] }|jr|j|_nq|jikr2|jr2|jD] }|jr1|j|_nq&|rB||jsB|j|d}|jD]}|j|_qE|j |dS)z finish the current tempalte N) r=r5r6r>rHr4r;rjrAr)rCr'rtrrrrbs(     zDistInfo.finish_template)Nr)rPrQrRrDrrrrrrs  tr__main__Ubunturz Suite: %szDesc: %sz BaseURI: %sz MatchURI: %sz Mirrors: %sz %s -%s -%sz %s)' __future__rr"rrr subprocessrrr~rrrr0objectr2rSrfrkrIrrPdinforrr'r4r8r9r=r>r!keysr;rGrTr<r5rrrrsJ  Q !