xkdeddlmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z mZmZmZmZmZmZmZmZddlZddlmZmZddlmZedZgdZd ed ed efd Z d eed eefdZ!Gdde"Z#Gdde"Z$ded efdZ%GddZ&GddZ'ee'e&fZ(Gdde)Z*Gdde)Z+Gdde)Z,e-dkrej.e+Z/e/D]'Z0ej1d e0z(e d!d"Z2ej1d#e2zej1e d$d"ej1e d!d%dSdS)&)absolute_importprint_functionN) AnyDictCallableIterableIteratorListOptionalTupleTypeVarUnion)DistInfoTemplate)_deb822T) is_mirrorDeb822SourceEntry SourceEntry NullMatcher SourcesListSourceEntryMatcher master_uri compare_urireturncP|d}|d}||krdS |dd}|dd}n#t$rYdSwxYwd|vr&||ddzd|krdSdS)zcheck if the given add_url is idential or a mirror of orig_uri e.g.: master_uri = archive.ubuntu.com compare_uri = de.archive.ubuntu.com -> True z/ Tz//rF.N)rstripsplit IndexErrorindex)rr compare_srv master_srvs 8/usr/lib/python3/dist-packages/aptsources/sourceslist.pyrrDs$$T**K""4((Jj  t!''--a0 %%d++A. uu kk+*;*;C*@*@1*D*F*FG:UUt 5s6A++ A98A9sc:tt|S)a-simple and efficient way to return uniq collection This is not intended for use with a SourceList. It is provided for internal use only. It does not have a leading underscore to not break any old code that uses it; but it should not be used in new code (and is not listed in __all__).)listset)r&s r%uniqr*as A<<cneZdZdedefdZ d dddeedeefd Zddd eeddfd ZdS) SingleValuePropertykeydocc"||_||_dSNr.__doc__selfr.r/s r%__init__zSingleValueProperty.__init__l r+NobjrobjtypercB|j|jdSr1)sectiongetr.r5r8r9s r%__get__zSingleValueProperty.__get__ps{tx...r+valuecF||j|j=dS||j|j<dSr1)r;r.)r5r8r?s r%__set__zSingleValueProperty.__set__us- = DH%%%$)CK ! ! !r+r1) __name__ __module__ __qualname__strr6r typer>rAr+r%r-r-ksCc CG//&/19$/ #//// *.*x}*******r+r-cneZdZdedefdZ d dddeedeefd Zddd eeddfd Z dS) MultiValuePropertyr.r/c"||_||_dSr1r2r4s r%r6zMultiValueProperty.__init__}r7r+Nr8rr9rcrt|j|jdSN)rmysplitr;r<r.r=s r%r>zMultiValueProperty.__get__s*""3;??48R#@#@AAAr+valuescJd||j|j<dS)N )joinr;r.)r5r8rOs r%rAzMultiValueProperty.__set__s" # 0 0 DHr+r1) rBrCrDrEr6r rFr r>rArGr+r%rIrI|sCc CGBB&B19$B cBBBB 1.1S 1d111111r+rIpropc|Sr1rG)rSs r%DeprecatedPropertyrUs Kr+ceZdZdeeejefdefdZde de fdZ e ddZ e d d Z eed d Ze d d Zeed d Ze d dZeed dZe ddZedefdZejdeddfdZedeefdZejdeeddfdZedefdZejdeddfdZedefdZedefdZdefdZdefdZdeddfdZdS) rr;filec|tjd|_n6t|trtj||_n||_t |j|_||_d|_dSrL)rSectionr; isinstancerE_linerWtemplate)r5r;rWs r%r6zDeb822SourceEntry.__init__si ?"?2..DLL  % % #"?733DLL"DL&&  ,0 r+otherrc|j|jkol|j|jko\|joU|jd|jdko|j|jko|j|jkSz+equal operator for two sources.list entries/disabledrFurirdistcompsr5r]s r%__eq__zDeb822SourceEntry.__eq__s MU^ + * UZ' * *$$ (8(8(=(== * UZ'  *  ek)  r+ ArchitectureszThe list of architecturesTypeszThe list of typesURIszURIs in the sourceSuiteszSuites in the source ComponentszComponents in the sourcec|jjS)1Legacy attribute describing the paragraph header.r;headerr5s r%commentzDeb822SourceEntry.comments|""r+rrNc||j_dS)rnNro)r5rrs r%rrzDeb822SourceEntry.comments& r+cd tj|jdS#t$rYdSwxYw)NTrusted)apt_pkgstring_to_boolr;KeyErrorrqs r%trustedzDeb822SourceEntry.trustedsA )$,y*ABB B   44 s ! //r?c^| |jd=dS#t$rYdSwxYw|rdnd|jd<dS)Nruyesnor;rxr5r?s r%ryzDeb822SourceEntry.trusteds[ = L+++    05&>ee$DL # # #s  c^tj|jdd S)zCheck if Enabled: no is set.Enabledr{)rvrwr;r<rqs r%rbzDeb822SourceEntry.disableds*)$,*:*:9e*L*LMMMMr+cV|r d|jd<dS |jd=dS#t$rYdSwxYw)Nr|rr}r~s r%rbzDeb822SourceEntry.disabledsS  &*DL # # # L+++    s  ((c|j S)z7A section is invalid if it doesn't have proper entries.)r;rqs r%invalidzDeb822SourceEntry.invalids<r+c|jS)z The entire (original) paragraph.)r[rqs r%linezDeb822SourceEntry.lines zr+cN|Sr1rEstriprqs r%__str__zDeb822SourceEntry.__str__sxxzz!!!r+c*t|jS)z(Section as a string, newline terminated.)rEr;rqs r%rEzDeb822SourceEntry.strs4<   r+enabledc| |_dS)z.Deprecated (for deb822) accessor for .disabledN)rb)r5rs r% set_enabledzDeb822SourceEntry.set_enableds#  r+) rBrCrDr rrrYrEr6rrgrI architecturestypesrUr-rFurisrcsuitesrdrepropertyrrsetterboolryrbrrrrrGr+r%rrs 1w/C)D E 1S 1 1 1 1  C  C     '&8STTM  w(; < **:669L9L&::D  4,0 +- r+r]rc|j|jkoe|j|jkoU|jd|jdko|j|jko|j|jkSr_rarfs r%rgzSourceEntry.__eq__sw MU^ + * UZ' *$$ (8(8(=(== * UZ' * ek)  r+cH|}g}d}d}d}tt|D]}||dkr2|r"d}d}||||}2d}|||z }@||dkrd}|||z }Z|r:||s d}||||}||r|sd}|||z }t|dkr|||S)z|a split() implementation that understands the sources.list format better and takes [] into account (for e.g. cdroms)rMF[T]r)rrangelenappendisspace)rpiecestmpp_found space_foundis r%rNzSourceEntry.mysplitsKzz|| s4yy!!  AAw#~~#"'K"GMM#&&&q'CC"G47NCCaCtAw T!W__%6%6 #  c"""1ga"" 7 " tAw s88a<< MM#    r+c||_|}|dks|dkr d|_dS|ddkrRd|_|dd}|ddvr d|_dS|dd}|d}|dkr||dzd|_|d|}||}t|dkr d|_dS|d|_ |j d vr d|_dS|ddd kr| dd }|D]{} |d d\}}|d kr|d|_ =|dkrtj ||_]d|_e#t$r d|_YxwxYw|d|_t|jdkrd|_|d|_t|dkr|dd|_dSg|_dS)zXparse a given sources.list (textual) line and break it up into the field we haverM#TNrr)rpmrpm-srcdebdeb-src)rrrrrz[]=arch,ry)rrrrbr rrrrNrrFpoprrvrwry Exceptionrcrdre)r5rrroptionsoptionr.r?s r%rzSourceEntry.parse7s zz|| 2::DL F 7c>> DM!""X^^%%++--F!9 DDD# ABBx IIcNN q55A=DL8Dd## v;;??DL F1IOO%% 9@ @ @DL F !9??  Q 3 & &jjmm))$//5577G! , , ,!'c1!5!5JCf}}-2[[-=-=** ))'.'=e'D'D '+ !(((#'DLLL(!9??$$ tx==1  DL1IOO%% v;;??DJJJDJJJs G--HH new_valuec| |_|r3|jd|_dS|jddkrd|jz|_dSdS)z!set a line to enabled or disabledrrN)rbrlstripr)r5rs r%rzSourceEntry.set_enabledwsq%   , ((**11#66DIIIy  #s**$)O +*r+cN|S)z debug helperrrqs r%rzSourceEntry.__str__sxxzz!!!r+c|jr|jSd}|jrd}||jz }|jr5|j.|dd|jd|jrdndd z }n@|j|d |jrdndzz }n'|jr |d d|jzz }|d |jd |jz }t|j d kr |d d |j zz }|j dkr |d|j zz }|dz }|S)z!return the current line as stringrMz# Nz [arch=rz trusted=r{r|rz [trusted=%s]z [arch=%s]rQrz # ) rrrbrFrryrRrcrdrrerr)r5rs r%rEzSourceEntry.strsM < 9  = D     @$,": D+,,,,/4// DD\ % O 'Fuu$G GDD   @ L388D,>#?#?? ?D DHHHdii00 tz??Q   C#((4:... .D <2   D4<' 'D   r+r1)rBrCrDr3rEr r6rrg staticmethodr rNrrrrrGr+r%rrs##..S. ....( C C    #c#d3i###\#J>#>$>>>>@ ,T ,d , , , ,"""""Sr+rc"eZdZdZdedefdZdS)rza Matcher that does nothingr&rcdS)NTrG)r5r&s r%matchzNullMatcher.matchstr+N)rBrCrDr3AnySourceEntryrrrGr+r%rrs<%%~$r+rceZdZdZ d%dddededefd Zd&d Zd ee fd Z de e gefde d ee fdZ ddd gfdedededeedededeedeed e fdZded d fdZded d fdZd'deed efd Zded d fd!Zd&d"Zd#ee d eee eeee fffd$Zd S)(rz6represents the full sources.list + sources.list.d fileT /usr/share/python-apt/templates/F)deb822 withMatcher matcherPathrcg|_||rt||_nt|_||_|dSr1)r(rmatcherrrrefresh)r5rrrs r%r6zSourcesList.__init__sM+-  <  )-k::DLL&==DL  r+rNcg|_tjd}tj|r||tjd}tj|r{t j |D]f}|j r| ds| dr3|tj ||g|jD]#}|j s|j|$dS)z update the list of known entriesrDir::Etc::sourceparts.sourcesz.listN)r(rvr find_fileospathexistsloadrlistdirrendswithrRrrr)r5rWpartsdirsources r%rzSourcesList.refreshs! ~''(>?? 7>>$    IIdOOO>**+BCC 7>>( # # < 8,, < <K + ""6*** + +r+c#&K|jD]}|VdS)zGsimple iterator to go over self.list, returns SourceEntry typesN)r()r5entrys r%__iter__zSourcesList.__iter__s.Y  EKKKK  r+ predicatesattrsc/:Kdd}|jD]x|r9jr2|djdkr=t fdDrt fd|DrVydS)Nrcr`c3LK|]}t||kVdSr1)getattr).0r.rrs r% z%SourcesList.__find..s6GG#763''5:5GGGGGGr+c3.K|]}|VdSr1rG)r predicaters r%rz%SourcesList.__find..sFPP&/ &!!PPPPPPr+)rr(rcrall)r5rrrcrs ` @r%__findzSourcesList.__findsiit$$i  F vz cjjoo9J9J39O9O&O&OGGGGGGGGGG CPPPP3=PPPMM    r+rMrFrcrd orig_compsrrposrWrc |}|d} | r|dd}t|dd} |fd| d|||} | D]?} | D]:} | | jvr/| | | =t| dkr| ccS;@|fdd||| } | D]} | j| krEt| jt| krt| j| z| _| cS| jr2| s0t| jt| kr d| _| cS|o| d rZtd| }|g|_ |g|_ |g|_| |_rt|_||j_| |_n| rdnd |rd dznd ||g}|| |r|d|zdd|Ddz}t-|}|||_|j||dkr|j|n|j|||S)z Add a new source to the sources.list. The method will search for existing matching repos and will try to reuse them as far as possible rrNc4t|jkSr1r)rr&rs r%z!SourcesList.add..c!/**m;r+F)rbrrFrcrdrc4t|jkSr1rrs r%rz!SourcesList.add..rr+)rrFrcrdr)rWrMz [arch=%s]rrQc3K|]}||V dSr1rG)rparts r%rz"SourcesList.add..<s';;Td;D;;;;;;r+r)r startswithrr)_SourcesList__findrer"rrbr*rrrrrr(rr;rprRextendrrrWrrinsert)r5rFrcrdrrrrrWrrbresourcesrnew_comp new_entrypartsrs ` r%addzSourcesList.adds>"zz||??3''  %8??$$DM** 111 ++ ; ; ; ;    & &F! & &v|++ekk(3345zzQ%  &++ ; ; ; ;    " "F(**v|$$E 22#' u(<#=#=FL  " "v|$$E 22&+FO!MMM   j 9 9 )$T:::I#fIO!UIN $vI #IO >*.}*=*= ''.I  $!)I   'R;HPsxx 6666b E LL    , S7]+++88;;U;;;;;dBD#D))I!%  9%%% 77 I  Y ' ' ' ' I  S) , , ,r+ source_entryc:|j|dS)z0remove the specified entry from the sources.listN)r(remove)r5rs r%rzSourcesList.removeIs &&&&&r+ backup_extctjd}tj||zr7tj|rt j||z|tjd}tj d|zD]<}tj||zrt j||z|=dS)z8restore sources.list files based on the backup extensionrrz%s/*N) rvrrrrrshutilcopyrglob)r5rrWrs r%restore_backupzSourcesList.restore_backupMs~''(>?? 7>>$+ , , 11E1E 1 Kz)4 0 0 0>**+BCCIfx/00 5 5Dw~~dZ/00 5 D:-t444 5 5r+ct}|tjd}|jD]R}|j|vrGt j|jr#tj |j|j|S|S)zmake a backup of the current source files, if no backup extension is given, the current date/time is used (and returned)Nz %y%m%d.%H%M) r)timestrftimer(rWrrrrr)r5ralready_backupedrs r%backupzSourcesList.backupXs+.%%  }55Ji M MF{"222rw~~fk7R7R2 FK6;; )KLLLr+c t|d5}|dr@tj|D]*}|jt ||+n/|D],}t||}|j|-ddddS#1swxYwYdS#t$r&}tj d|d|dYd}~dSd}~wwxYw)z(re)load the current sourcesrrNzcould not open file 'z': r) openrrFiler(rrrrloggingwarning)r5rWfr;rrexcs r%rzSourcesList.loadcs] LdC 1A==,,1#*<??KK (():7D)I)IJJJJK!"11!,T4!8!8 ((0000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 L L L OOcccJ K K K K K K K K K Ls;B1BB$ B1$B((B1+B(,B11 C!;CC!ci}t|jdkr`tjd}d}t |d5}||dddn #1swxYwYdS |jD]}|j|vrt |jd||j<n:|jdr ||jd||j|  | D]}| dS#| D]}| wxYw)zsave the current sourcesrrz## See sources.list(5) for more information, especialy # Remember that you can only use http, ftp or file URIs # CDROMs are managed through the apt-cdrom tool. wNrr) rr(rvrrr writerWrrErOclose)r5filesrrprrs r%savezSourcesList.saveqs-/ ty>>Q  >++,BCCDE  dC A               F ) 7 7;e++)-fk3)?)?E&+&&[))*553&+&,,T222fk"((6666  7\\^^     U\\^^    s A..A25A22 #^$4d$:; FI  . !    $"')aaaa a I a  aasma }a aaaaF';'4'''' 5 5 5 5 5 5  # #     L L L L L L6/$^4/ tN#T(D4H*H%II J//////r+rc.eZdZdZdefdZdedefdZdS)rztmatcher class to make a source entry look nice lots of predefined matchers to make it i18n/gettext friendly rc@g|_tjd|z}|D]|}tj|}|d}|d|}t ||}|jD]#}|j|j|$}dS)Nz %s/*.infoz.infor)base_dir) templatesrrrbasenamerr match_urir)r5r spec_filesrrrdr\s r%r6zSourceEntryMatcher.__init__s)+Y{[899  4 4A  ##AwA!A#AA 444D N 4 4%1N))(333 4 r+rrcd}|jD]}|j|j|jy|jr|jk|jdt j|j|jrEt j|j|jr&|j|jks |jdkr d}||_ nS| |jr8|j1|j*t j|j|jr d}||_ n|S)z%Add a matching template to the sourceFNrT) r"rcrdr$ match_nameresearchrrFr\r)r5rfoundr\s r%rzSourceEntryMatcher.matchs  Hz!V[%8".'3J*K+Ih0&*==,HX0&+>>,  --%1G1G"*""6:.. '3K+HX0&+>>,"* r+N) rBrCrDr3rEr6rrrrGr+r%rrs[ C    Ntr+r__main__zentry %sz!http://archive.ubuntu.com/ubuntu/z$http://de.archive.ubuntu.com/ubuntu/zis_mirror(): %sz http://archive.ubuntu.com/ubuntuz#http://de.archive.ubuntu.com/ubuntu)3 __future__rrrior os.pathrr(rrtypingrrrrr r r r r rrvdistinforrrMrr__all__rErrr*rr-rIrUrrrobjectrrrrB init_configrrinfomirrorrGr+r%r6s476666666                          (((((((( GCLL   #CD:HQKDG*****(***" 1 1 1 1 1 1 1 1Q1_$_$_$_$_$_$_$_$Dooooooood{$556&x/x/x/x/x/&x/x/x/v11111111j zGkmmG// Z%))++-....Y+-SFGL"V+,,,GL .0V   GL /1V  %r+