.S+@s:ddlZddlZddlZdadadaddejjddjdDa da dddZ d d Z d d d Z d ddZd ddZd ddZd ddZd ddZGdddeZGdddeZddZddZed kr6endS)!NcCs,g|]"}|jrd|jqS)zpython%s)strip).0Zverr!/usr/share/python3/py3versions.py s rZDEBPYTHON3_SUPPORTED,c Csddlm}m}tsftjjdrf|}td}|j||j |aqfntr|rytj d|}Wn|k rt YnX|SdS)Nr) ConfigParser NoOptionErrorz"/usr/share/python3/debian_defaultsZDEFAULT) Z configparserr r _defaultsospathexistsopenZ read_filecloseget ValueError)namer r configZ defaultsfilevaluerrr read_defaults        rc st|jddkr*tdnddl}i|jd6|jd6|jd6|jd6|jd6}i}t}tt d d }d }xF|jdD]5}|j }|d krqn|dkrqn|j dtt j d}|j|} y| s'tdn| jd| jd} jd\} } t| dkrswn| dkr|jn,d }|| fdd|D}Wqtk rtdYqXqWd|kr||d<|r|j||d=z<=z<< version_onlyTFallcurrent current_extversionsz(>=|<=|<<|=)? *(\d\.\d)$z'error parsing Python3-Version attribute.cs%g|]}|r|qSrr)rav)filtopvrrrGs z"parse_versions..)rr)Nr)lensplitroperatoreqgeleltsetsupported_versionsr setdefaultrecompilematchgroupintadd Exceptionunion) vstringr&Z operatorsvinfoZexact_versionsZ version_rangeZ relop_seenZfieldZvemopZvmajZvminr)r"r#rparse_versions'sL            r:Fc CsotsPy,td}dd|jdDaWqPtk rLgaYqPXn|rgddtDStSdS)Nz old-versionscSsg|]}|jqSr)r)rsrrrrVs z old_versions..rcSs g|]}|ddqS)Nr)rr#rrrrZs ) _old_versionsrr%r)rrrrr old_versionsQs   r>c CsotsPy,td}dd|jdDaWqPtk rLgaYqPXn|rgddtDStSdS)Nzunsupported-versionscSsg|]}|jqSr)r)rr;rrrrds z(unsupported_versions..rcSs g|]}|ddqS)r<Nr)rr#rrrrhs )_unsupported_versionsrr%r)rrrrrunsupported_versions_s   r@cCsVts7y,td}dd|jdDaWq7tk r3ddddg}y=d dl}|j|d d d d d|j}|j}Wn*tk rt j dj |}YnXd}xE|D]=}|j dr|jdd d j jd}qqW|jdd|D}|aYq7Xn|rNddtDStSdS)Nzsupported-versionscSsg|]}|jqSr)r)rr;rrrrrs z&supported_versions..rz/usr/bin/apt-cachez--no-all-versionsZshowz python3-allrbufsizershellFstdout zDepends::cSs%g|]}tjdd|qS)z\s*(\S+)[ (]?.*z\1)r.sub)rr;rrrrs cSs g|]}|ddqS)r<Nr)rr#rrrrs )_supported_versionsrr%r subprocessPopenPIPErC ImportErrorr popenjoin startswithrr)rrcmdrHpfdZdependslinerrrr,ms0        , r,cCsztstjdantd}t|tjjd|fkrXtd|n|a|rrtddStSdS)Nz/usr/bin/python3zdefault-versionz/usr/binzkthe symlink /usr/bin/python3 does not point to the python3 default version. It must be reset to point to %sr<)_default_versionr readlinkrr rMr)rZdebian_defaultrrrdefault_versions ! rUcCsd}t|}tdd}t|dkrI|dj|}n td|sjtdn|rt|Sdd|DSdS) NrTrrz%No python3 versions in version stringzempty set of versionscSsg|]}d|qS)zpython%sr)rr#rrrrs z&requested_versions..)r:r,r$ intersectionr)r6rrr7 supportedrrrrequested_versionss  rXcs`ddl}tfdd|jdD}|j|rXdd|DS|SdS)Nrcs:g|]0}tjj|krtjj|qSr)r r basename)rr;)rWrrrs z&installed_versions..z/usr/bin/python3.[0-9]cSs g|]}|ddqS)r<Nr)rr#rrrrs )globr,sort)rrZrr)rWrinstalled_versionss   r\c@seZdZdS)ControlFileValueErrorN)__name__ __module__ __qualname__rrrrr]s r]c@seZdZdS)MissingVersionValueErrorN)r^r_r`rrrrras rac CsCd}d}d}t|dd}dd|D}WdQXx|D]}|dkrr|dkriPnd}qG|jdrd}qG|jd |r|}qG|jjd rG|dkrtd n|jd d d j}qGqGW|dkrtdn|dkr?|dkr;tdn|S|S)zFread the debian/control file, extract the X-Python3-Version field.Nencodingzutf-8cSsg|]}|jqSr)r)rrRrrrrs z/extract_pyversion_attribute..rSourcezSource:z Package: zx-python3-version:z1attribute X-Python3-Version not in Source sectionrErznot a control filez$no X-Python3-Version in control file)rrNlowerrr%rr]ra)fnpkgversionZsversionZsectionZ controlfilelinesrRrrrextract_pyversion_attributes2       #   ric Csddlm}d}|d|}|jddddd d d d |jd dddd d d d|jddddd d d d|jddddd d d d|jddddd dd d d d|j\}}tjjtjd}|j r{t |dkr{yt t |j Wqtk rw}z#t d||tjdWYdd}~XqXn|jrt |dkrt d jt|j n|jrt |dkrt d jt|j n|jrZt |dkrZt |dkr%d!}n |d}ytjj|r|}y%t|d"} t| |j } Wqtk rtjjd#||ftjdYqtk rtjjd$|t|j } YqXnt||j } t d j| Wqtk rV}z,tjjd%||ftjdWYdd}~XqXn'tjjd&||ftjddS)'Nr) OptionParserz;[-v] [-h] [-d|--default] [-s|--supported] [-i|--installed] usagez-dz --defaulthelpz!print the default python3 versionaction store_truedestdefaultz-sz --supportedz$print the supported python3 versionsrWz-rz --requestedzprint the python3 versions requested by a build; the argument is either the name of a control file or the value of the X-Python3-Version attribute requestedz-iz --installedz.print the installed supported python3 versions installedz-vz --versionz print just the version number(s)Frz%s:rrDzdebian/controlrcz%s: not a control file: %s, zC%s: no X-Python3-Version in control file, using supported versions z%s: %s z usage: %s %s )ZoptparserjZ add_option parse_argsr r rYsysargvrpr$printrUrrexitrWrMr,rrr\rqisfilerirXr]stderrwritera) rjrkparserZoptsargsZprogrammsgrrer6Zvsrrrmainsn    #      #r~__main__)r r.rtr r=r?environrr%rGrSrr:r>r@r,rUrXr\rr]rarir~r^rrrrs,    " *  = A