/Rc@sddlZddlZddlZy eZWn/ek r_ddlZejZejZnXda ddZ e dZ da e dZdae dZgejjddjdD]"Zejrd ej^qae d Zd ejjd datd kr#dane d Ze dZe dZdefdYZdefdYZdZdZ e dZ!dZ"dZ#e$dkre#ndS(iNcCsddlm}m}tstjjdr|}y|jtdWn%t k ru}|GHt j dnX|aqntr|rytj d|}Wn|k rt nX|SdS(Ni(tSafeConfigParsert NoOptionErrors!/usr/share/python/debian_defaultsitDEFAULT(t ConfigParserRRt _defaultstostpathtexiststreadfptfiletIOErrortsystexittgett ValueErrortNone(tnameRRtconfigtmsgtvalue((s/usr/share/python/pyversions.pyt read_default s"     cCsOddl}i|jd6|jd6|jd6|jd6|jd6}i}tg}ttdtt dt}t }xJ|j dD]9}|j }|dkrd|d=s<=s<=|<=|<<|=)? *(\d\.\d)$s&error parsing Python-Version attributeiit.tvexact(scurrentR(NR(toperatorteqRtgetletlttsettsupported_versionstTruet old_versionstFalsetsplittstript setdefaulttretcompiletmatchRtgrouptaddt Exceptiontunion(tvstringt add_exactRt operatorstvinfotexact_versionst version_ranget relop_seentfieldtvetmtoptvtvmajtvmintfiltoptav((s/usr/share/python/pyversions.pytparse_versions sX          ,      cCsts[y8td}g|jdD]}|j^q%aWq[tk rWgaq[Xn|r|gtD]}|d^qhStSdS(Ns old-versionsRi(t _old_versionsRR(R)R(RRtsR=((s/usr/share/python/pyversions.pyR&Vs ,  cCsts[y8td}g|jdD]}|j^q%aWq[tk rWgaq[Xn|r|gtD]}|d^qhStSdS(Nsunsupported-versionsRi(t_unsupported_versionsRR(R)R(RRRDR=((s/usr/share/python/pyversions.pytunsupported_versionsds ,  tDEBPYTHON_SUPPORTEDtRspython%sc Cststy8td}g|jdD]}|j^q%aWqttk rpddddg}y=ddl}|j|dd d td |j}|j }Wn)t k rt j d j |}nXd}xE|D]=}|jd r|jdd d jjd}qqW|j|rXg|D]}tjdd|^q.}|antsqddgaqqqtXn|rgtD]} | d^qStSdS(Nssupported-versionsRs/usr/bin/apt-caches--no-all-versionstshows python-allitbufsizeitshelltstdoutt sDepends:t:s\s*(\S+)[ (]?.*s\1s python2.6s python2.7i(t_supported_versionsRR(R)Rt subprocesstPopenR'tPIPERLt ImportErrorRtpopentjoinRt startswithtcloseR+tsub( RRRDtcmdRPtptfdtdependstlineR=((s/usr/share/python/pyversions.pyR$ts6 ,      , ( tDEBPYTHON_DEFAULTtpythoncCs[tsEytjda}Wntk rdayLdddg}ddl}|j|dddtd|j}|j }Wn t k rtj d }nX|j j }|jtjd |rd |aqnXytd }Wntk r d }nXt|tjjd|fkr<td|n|an|rStdStSdS(Ns/usr/bin/pythons-cs!import sys; print sys.version[:3]iRJiRKRLs6/usr/bin/python -c 'import sys; print sys.version[:3]'s\d\.\d$R_sdefault-versions python2.6s/usr/binsZ/usr/bin/python does not match the python default version. It must be reset to point to %si(t_default_versionRtreadlinktOSErrorRRPRQR'RRRLRSRTtreadlineR)RWR+R-RRRRU(RtlinkRYRPRZR[R]tdebian_default((s/usr/share/python/pyversions.pytdefault_versions6       ! cCsd}t|dt}tdt}t|dkrd|krN|}qd|krotdtg}qd|kr|d}q|dj|}n3d|krd|krtdnd|krd|kr|dj|}n t|}d|kr|j |dqnd|krbtdt}||dkrVtd n|g}nod|kszd|krt}d|kr|dj|}nd|kr|j |dqn td |std n|r|Sg|D]}d |^qSdS( NR3RiRRRRs*both `current' and `all' in version strings+`current' version not in supported versionss$No Python versions in version strings+computed set of supported versions is emptyspython%s( RRBR%R$tlenRft intersectionRR#tupdate(R2RRR5t supportedRR=((s/usr/share/python/pyversions.pytrequested_versionssH                 cCsddl}t}g|jdD]0}tjj||kr%tjj|^q%}|j|rg|D]}|d^qrS|SdS(Nis/usr/bin/python[0-9].[0-9]i(tglobR$RRtbasenametsort(RRlRjRDRR=((s/usr/share/python/pyversions.pytinstalled_versionss  0 tControlFileValueErrorcBseZRS((t__name__t __module__(((s/usr/share/python/pyversions.pyRpstMissingVersionValueErrorcBseZRS((RqRr(((s/usr/share/python/pyversions.pyRsscCsd}d}d}yt|d}Wn/tk rV}d||fGHtjdnXx|D] }|j}|dkr|dkrq^n|dkrPnd}q^|jdrd}q^|jd|r|}q^|jjdr'|dkrtd n|j d d d j}q^|jjd r^||krj|j d d d j}qjq^q^W|dkrt dn|dkr|dkrt dn|S|dkrt d|n|S(sread the debian/control file, extract the X-Python-Version or XS-Python-Version field; check that XB-Python-Version exists for the package.trsCannot open %s: %siRHtSourcesSource:s Package: sxs-python-version:sx-python-version:s3attribute X(S)-Python-Version not in Source sectionRNisxb-python-version:snot a control files&no X(S)-Python-Version in control files$no XB-Python-Version for package `%sN(sxs-python-version:sx-python-version:( RR R R R R)RVtlowerRR(RpRs(tfntpkgtversiontsversiontsectiontfpRR]((s/usr/share/python/pyversions.pytextract_pyversion_attributesN           &       cCs]g|jdD]}t|^q}g|jdD]}t|^q8}t||S(NR(R(tinttcmp(tver1tver2titv1tv2((s/usr/share/python/pyversions.pyt version_cmp"s((cCsag}tdt}x|jdD]}|jd}t|dkr|dsg|d|d|]tusages-ds --defaultthelps print the default python versiontactiont store_truetdesttdefaults-ss --supporteds#print the supported python versionsRjs-rs --requestedsprint the python versions requested by a build; the argument is either the name of a control file or the value of the X(S)-Python-Version attributet requesteds-is --installeds-print the installed supported python versionst installeds-vs --versions print just the version number(s)Ris%s:iRMsdebian/controlRus%s: not a control file: %s, t pyversionssA%s: missing X(S)-Python-Version in control file, fall back to %s sD%s: missing debian/pyversions file, fall back to supported versions s%s: %s is usage: %s %s (!toptparseRt add_optionR't parse_argsRRRmR targvRRgRfRRR RjRUR$RRoRtisfileR}RkRptstderrtwriteRstdirnameRRR ( RRtparsertoptstargstprogramRRRwR2tvste((s/usr/share/python/pyversions.pytmainFs          !    t__main__(%RR+R R#tSetTypet NameErrortsetstSetRRRR'RBRCR&RERFtenvironR R(RR)ROR$R`RfRkRoRRpRsR}RRRRRq(((s/usr/share/python/pyversions.pyts@$       5  "" !   *  /    G