D[,-@sddlmZddlZddlZddlZddlmZmZddlZddl Z ddl m Z Gddde Z Gddde ZGd d d e ZGd d d e Zd dZGddde ZedkreddZejejxejD]Zejdejejdejejdejejdejejikrejdeejjnx4ej D])Z!ejde!je!je!j"fqWx%ej#D]Z$ejde$jqWq!WndS))print_functionN)PopenPIPE)gettextc@s4eZdZddZddZddZdS)TemplatecCsd|_d|_g|_d|_d|_d|_d|_g|_g|_d|_ i|_ d|_ d|_ d|_ dS)NFT)namechildparents match_name descriptionbase_uritype componentschildren match_uri mirror_set distribution availableofficial)selfr6/usr/lib/python3/dist-packages/DistUpgrade/distinfo.py__init__'s             zTemplate.__init__cCs|dd|jDkS)z8 Check if the distribution provides the given component css|]}|jVqdS)N)r).0crrr 9sz)Template.has_component..)r)rcomprrr has_component7szTemplate.has_componentcCsCt|\}}}||jkr;|j|j||SdSdS)z8 Check if a given url of a repository is a valid mirror FN) split_urlrhas_repository)rurlprotohostnamedirrrr is_mirror;szTemplate.is_mirrorN)__name__ __module__ __qualname__rrr$rrrrr%s   rc@smeZdZdddddZddZddZdd Zd d Zd d ZddZ dS) ComponentNcCs(||_||_||_||_dS)N)rr description_longparent_component)rrdescZ long_descr*rrrrFs   zComponent.__init__cCs|jS)N)r*)rrrrget_parent_componentLszComponent.get_parent_componentcCs ||_dS)N)r*)rparentrrrset_parent_componentOszComponent.set_parent_componentcCs4|jdk r|jS|jdk r,|jSdSdS)N)r)r )rrrrget_descriptionRs zComponent.get_descriptioncCs ||_dS)N)r )rr+rrrset_descriptionZszComponent.set_descriptioncCs ||_dS)N)r))rr+rrrset_description_long]szComponent.set_description_longcCs|jS)N)r))rrrrget_description_long`szComponent.get_description_long) r%r&r'rr,r.r/r0r1r2rrrrr(Ds      r(c@smeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)Mirrorz( Storage for mirror related information NcCs/||_g|_|j||||_dS)N)r" repositoriesadd_repositorylocation)rr!r"r#r6rrrrgs  zMirror.__init__cCs|jjt||dS)N)r4append Repository)rr!r#rrrr5mszMirror.add_repositorycsfdd|jDS)Ncs%g|]}|jkr|qSr)r!)rr)r!rr qs z5Mirror.get_repositories_for_proto..)r4)rr!r)r!rget_repositories_for_protopsz!Mirror.get_repositories_for_protocCsJ|dkrdSx3|jD](}|j|kr||jkrdSqWdS)NFT)r4r!r#)rr!r#r9rrrrss  zMirror.has_repositorycsfddjDS)Ncs"g|]}|jjqSr)get_urlr")rr9)rrrr:|s z(Mirror.get_repo_urls..)r4)rr)rr get_repo_urls{szMirror.get_repo_urlscCs|jS)N)r6)rrrr get_location~szMirror.get_locationcCs ||_dS)N)r6)rr6rrr set_locationszMirror.set_location) r%r&r'__doc__rr5r;rr=r>r?rrrrr3ds      r3c@s4eZdZddZddZddZdS)r8cCs||_||_dS)N)r!r#)rr!r#rrrrs zRepository.__init__cCs|j|jfS)N)r!r#)rrrrget_infoszRepository.get_infocCsd|j||jfS)Nz %s://%s/%s)r!r#)rr"rrrr<szRepository.get_urlN)r%r&r'rrAr<rrrrr8s   r8cCsBtjd|dd}x#t|dkr=|jdqW|S)zE split a given URL into the protocoll, the hostname and the dir part z:*\/+maxsplitN)resplitlenr7)r rFrrrrsrc@s.eZdZddddZddZdS)DistInfoNz/usr/share/python-apt/templatesc(Csd|_g|_tjjd|_d}tjd}tjd}|sy/tdddgdt j d j }Wqt k r}z1|j t jkrtjd |nd }WYdd}~XqXn||_i}d ||f}t|} d} d} xe| D]]} | jd d} t| dkrHqn| d j }| dj }|dkrt||_q|dkr||_q|dkr|j| | d} t} || _|| _d|| _q|dkr|| _q|dkrad| _xZ|jD]8}|j|kr"| jj||jj| q"q"Wq|dkrtj || _!q|dkrtj || _"q|dkr|| _#q|dkr| j$ r|| _$q|d|jkr|| _$q|dkr| j% r|| _%q|d|jkr=|| _%q|dks\|d|jkrt&j'j(|rt|pt&j'j)t&j'j*||}||kri}y>t|,}t+t,|j-d d!|D}WdQXWn"t.k r t/d"g}YnXx|D]~} | j0d#r>|j1d$| }qnt2| \}}}||krv||j3||qt4||||||.z#WARNING: Failed to read mirror filez#LOC:z\1Z Descriptionr(ZCompDescriptionZCompDescriptionLongZParentComponent)=Zmetarelease_uri templatesapt_pkgconfigfindZarchrEcompilerrZ communicaterMOSErrorerrnoENOENTloggingZwarningdistopenrFrG_changelogs_urifinish_templaterrrr rr r7rZstring_to_boolrrr r rospathisabsabspathjoinlistfiltermatch Exceptionprint startswithsubrr5r3rr rrr(r0r1r.)rrXZbase_dirr6Z match_locZmatch_mirror_lineexcZmap_mirror_setsZ dist_fnameZ dist_filetemplate componentlinetokensZfieldvalueZnannyrZvalue_fZ mirror_datar!r"r#rrrrs                         ! #           zDistInfo.__init__cCs|s dS|jdkrR|jrRx-|jD]}|jr,|j|_Pq,q,Wn|jikr|jrx-|jD]}|jrt|j|_PqtqtWn|r|j|j r|jj|d}nx|jD]}|j|_qW|j j|dS)z finish the current tempalte N) rrr rrrrr7rrO)rrjrktrrrr\s$       zDistInfo.finish_template)r%r&r'rr\rrrrrHs rrH__main__ZUbuntuz/usr/share/python-apt/templatesz Suite: %szDesc: %sz BaseURI: %sz MatchURI: %sz Mirrors: %sz %s -%s -%sz %s)%Z __future__rrUrWr] subprocessrrrErPrrZobjectrr(r3r8rrHr%dinfor[rOrjrr r rrrbkeysrrr)rrrrrrs:      !  #