a Xl`-@sddlZddlZddlZdadadaddejdddDa da d!ddZ d d Z d"d d Z d#ddZd$ddZd%ddZd&ddZd'ddZGdddeZGdddeZddZddZed kredS)(NcCs g|]}|rd|qSzpython%sstrip).0Zverr!/usr/share/python3/py3versions.py srZDEBPYTHON3_SUPPORTED,cCs|ddlm}m}tsDtjdrD|}td}||| |atrx|rxzt d|}Wn|yrt Yn0|SdS)Nr) ConfigParser NoOptionErrorz"/usr/share/python3/debian_defaultsZDEFAULT) Z configparserr r _defaultsospathexistsopenZ read_filecloseget ValueError)namer r ZconfigZ defaultsfilevaluerrr read_defaults    rc sft|ddkrtdddl}|j|j|j|j|jd}i}t}tt dd}d}|dD]}| }|d krxqb|d vrqb| d tt d }||} zx| std | d| d} d\} } t| dkrWqb| dvr|n d}|| fdd|D}Wqbty8td Yqb0qbd |vrb||d <|rb|||d <|S)Nr zDtoo many arguments provided for X-Python3-Version: min and max only.r)N=z>=z<=z<=|<=|<<|=)? *(\d\.\d)$z'error parsing Python3-Version attribute.)Nrcsg|]}|r|qSrr)ravZfiltopvrrrGz"parse_versions..)lensplitroperatoreqgeleltsetsupported_versionsr setdefaultrecompilematchgroupintadd Exceptionunion) vstringr'Z operatorsvinfoZexact_versionsZ version_rangeZ relop_seenZfieldZvemopZvmajZvminrr"rparse_versions'sN     r;FcCsVts.r cSsg|]}|ddqSNrrr#rrrrZr$) _old_versionsrr&rrrrrr old_versionsQs  rCcCsVts.r cSsg|]}|ddqSr>rr@rrrrhr$)_unsupported_versionsrr&rrBrrrunsupported_versions_s  rEc Csttsz td}dd|dDaWntygd}z&ddl}|j|dd|jd }|j}Wn"t yt d |}Yn0d}|D](}| d r|d ddd}q|d d|D}|aYn0ttt}tt||rddtDStSdS)Nzsupported-versionscSsg|] }|qSrrr<rrrrsr$z&supported_versions..r )z/usr/bin/apt-cachez--no-all-versionsZshowz python3-allrrF)bufsizeshellstdout zDepends::cSsg|]}tdd|qS)z\s*(\S+)[ (]?.*z\1)r/subr<rrrrr$cSsg|]}|ddqSr>rr@rrrrr$)default_version_supported_versionsrr&r subprocessPopenPIPErH ImportErrorrpopenjoin startswithrrpopindex_default_versionsortappend) rrcmdrNpfdZdependslinedefaultrrrr-ms8      r-cCsTtstdatd}t|tjd|fvr8td||a|rLtddStSdS)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?)rWrreadlinkrrrSr)rZdebian_defaultrrrrLs  rLcCstd}t|}tdd}t|dkr|d|}g}|D]}||q>z||tdd}Wnd}Yn0| |r||nt d|st d|r|Sd d |DSdS) NTrrrr?r z/No supported python3 versions in version stringzempty set of versionscSsg|] }d|qSrrr@rrrrr$z&requested_versions..) rLr;r-r% intersectionrYrUrVrWrXr)r7rrr8 supportedZvlversionr^rrrrequested_versionss*    rccsHddl}tfdd|dD}||r@dd|DS|SdS)Nrcs(g|] }tj|vrtj|qSr)rrbasenamer<rarrrsz&installed_versions..z/usr/bin/python3.[0-9]cSsg|]}|ddqSr>rr@rrrrr$)globr-rX)rrfrrrerinstalled_versionss rgc@s eZdZdS)ControlFileValueErrorN__name__ __module__ __qualname__rrrrrhsrhc@s eZdZdS)MissingVersionValueErrorNrirrrrrmsrmcCsd}d}d}t|dd}dd|D}Wdn1s<0Y|D]|}|dkrp|dkrp|dkrjqd}qJ|drd}qJ|d |r|}qJ|d rJ|dkrtd |d d d }qJ|durtd|dkr|durtd|S|S)zFread the debian/control file, extract the X-Python3-Version field.Nzutf-8)encodingcSsg|] }|qSrr)rr]rrrrr$z/extract_pyversion_attribute..r SourcezSource:z Package: zx-python3-version:z1attribute X-Python3-Version not in Source sectionrJrznot a control filez$no X-Python3-Version in control file)rrTlowerrr&rrhrm)fnpkgrbZsversionZsectionZ controlfilelinesr]rrrextract_pyversion_attributes2, rtc Csddlm}d}||d}|jddddd d |jd d d ddd |jdddddd |jdddddd |jddddddd|\}}tjtjd}|j r t |dkr zt t |j Wn>ty}z$t d||tdWYd}~n d}~00n|jr8t |dkr8t dt|j nr|jrft |dkrft dt|j nD|jrt |dkrt |dkrd }n|d}ztj|r(|}zt|d!} t| |j } Wn^tytjd"||ftdYn.ty$tjd#|t|j } Yn0n t||j } t d| WnDty}z*tjd$||ftdWYd}~n d}~00ntjd%||ftddS)&Nr) OptionParserz;[-v] [-h] [-d|--default] [-s|--supported] [-i|--installed] )usagez-dz --defaultz!print the default python3 version store_truer^)helpactiondestz-sz --supportedz$print the supported python3 versionsraz-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)Fr)rxr^ryrzz%s:rrIzdebian/controlroz%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 )ZoptparseruZ add_option parse_argsrrrdsysargvr^r%printrLrrexitrarSr-r|rgr{isfilertrcrhstderrwriterm) rurvparserZoptsargsZprogrammsgrrqr7Zvsrrrmain s|   $  "r__main__)N)F)F)F)F)F)F)rr/r~r rArDenvironrr&rMrWrr;rCrEr-rLrcrgrrhrmrtrrjrrrrs. *   !   =A