3 fn@sBdZdZdZddlZddlZddlZddlZddlZddlZy ej Z Wn(e k rnej dkrfdZ nd Z YnXd Z d d d d d dddddd ZejdZddZejdejZejdddfddZddZejdejZejdejZejdejZdZd/d0Zddded1fd2d3Zd4d5Zdddefd6d7Zdd9d:Zdd;d<Z ejd=Z!dd>d?Z"ddAddBddDddEddGddHddIddKddLddMddNi Z#ddDddOddPddQddRddSiZ$ddTdUZ%dVdWZ&ddXdYZ'dZd[Z(dd\d]Z)d^d_Z*d`daZ+ddbdcZ,dddeZ-ddfdgZ.ddhdiZ/ddddmZ0ejddfdndoZ1ej2dpdqZ3da4drdsZ5dtduZ6dvdwZ7dxdyZ8dzd{Z9d|d}Z:d~dZ;ejdejZejdZ?iZ@dddZAddZBddZCddZDddZEddZFddZGddZHiZIdddZ eJdkr>dejKkpdejKkZLdejKko$dejKkZMeNe eMeLejOddS)a8 This module tries to retrieve as much platform-identifying data as possible. It makes this information available via function APIs. If called from the command line, it prints the platform information concatenated as single string to stdout. The output format is useable as part of a filename. a Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com Copyright (c) 2000-2010, eGenix.com Software GmbH; mailto:info@egenix.com Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. EGENIX.COM SOFTWARE GMBH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! z1.0.8Ndoswin32win16ZNULz /dev/nullz/etc (2) ZdevZalphaaZbetabcZRCrcplpz([0-9]+|[._+-])c Csfg}x\tj|D]N}|dkryt|d}d}Wn tk rNtj|d}YnX|j||fqW|S)Nz._+-rdr) _component_resplitint ValueError _ver_stagesgetextend)versionresultvtr /usr/lib64/python3.6/platform.py_comparable_versions rsC(__libc_init)|(GLIBC_([0-9.]+))|(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)i@c Cst}ttjdrtjj|}t|d`}|j|}d}xH|t|krd|ksZd|krhtj ||}nd}| s|j t|kr|j|} | r|t |t|dd| }d}q<|sPdd |j D\} } } } }}| r| rd }n| r|d krd }| }n|| ||krx| }n^| rx|d krxd }|rR| sN||||krR|}|rx|t| d|krx||}|j }qszlibc_ver..Zlibcglibc) rhasattrospathr!openreadlen _libc_searchsearchendmaxgroups) executablelibrZ chunksizeVfZbinaryposmchunkZlibcinitr(Z glibcversionZsoZthreadsZ soversionrrrlibc_versJ        r;c Csptjjdrd}td`}xX|D]P}|j}t|dkr |\}}nq |dkrV|j}q |dkr |jd}|d}q WWdQRX|||fStjjdrtdD}x<|D]4}|jd} t| dkr| d d krd | d |fSqWWdQRXtjjd rftjd } x:t t| d ddD]"} | | dd dkr| | =qW| rf| j d}| dd d}|||fS|||fS)z Tries some special tricks to get the distribution information in case the default method fails. Currently supports older SuSE Linux, Caldera OpenLinux and Slackware Linux distributions. z/var/adm/inst-log/infoSuSEZMIN_DIST_VERSIONZ DIST_IDENT-Nz/etc/.installedrZ OpenLinuxz/usr/lib/setupzslack-version- slackwarerBrB) r*r+existsr,rr.stripisdirlistdirrangesort) distnameridr7lineZtvtagvaluevaluesZpkgZverfilesnrrr_dist_try_harders>               rPz(\w+)[-_](release|version)z'(.+) release ([\d.]+)[^(]*(?:\((.+)\))?z1([^0-9]+)(?: release )?([\d.]+)[^(]*(?:\((.+)\))?r<debianfedoraredhatcentos almalinuxmandrakemandrivarocksrA yellowdoggentoo UnitedLinux turbolinuxarchmageiacCszd}d}tj|}|dk r&t|jStj|}|dk rDt|jS|jj}|rp|d}t|dkrp|d}d||fS)Nr rr?)_lsb_release_versionmatchtupler3_release_versionrDrr.) firstlinerrJr9lrrr_parse_release_file0s      rer?cCs(ddl}|jdtddt|||||S)NrzFdist() and linux_distribution() functions are deprecated in Python 3.5r=) stacklevel)warningswarnPendingDeprecationWarning_linux_distribution)rIrrJsupported_distsfull_distribution_namergrrrlinux_distributionKs   rmcCsytjt}Wntk r(|||fSX|jxD|D]0}tj|}|dk r8|j\}} ||kr8|}Pq8Wt|||St tj j t|dddd} | j } WdQRXt | \}} } |r|r|}| r| }| r| }|||fS)a Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. supported_dists may be given to define the set of Linux distributions to look for. It defaults to a list of currently supported Linux distributions identified by their release file name. If full_distribution_name is true (default), the full distribution read from the OS is returned. Otherwise the short name taken from supported_dists is used. Returns a tuple (distname, version, id) which default to the args given as parameters. Nrzutf-8surrogateescape)encodingerrors)r*rF _UNIXCONFDIROSErrorrH_release_filenamer`r3rPr,r+joinreadlinere)rIrrJrkrlZetcfiler9Z _distnameZdummyr7rcZ_versionZ_idrrrrjUs0      rjcCs*ddl}|jdtddt||||ddS)aS Tries to determine the name of the Linux OS distribution name. The function first looks for a distribution release file in /etc and then reverts to _dist_try_harder() in case no suitable files are found. Returns a tuple (distname, version, id) which default to the args given as parameters. rNzFdist() and linux_distribution() functions are deprecated in Python 3.5r=)rf)rkrl)rgrhrirj)rIrrJrkrgrrrdists  rxrncCs&ddl}|jdtddtj|||S)z! Portable popen() interface. rNzuse os.popen insteadr=)rf)rgrhDeprecationWarningr*popen)cmdmodebufsizergrrrrzsrzc Csd|jd}|r|j|ytt|}Wntk r>|}YnXttt|}dj|dd}|S)z Normalize the version and build strings and return a single version string using the format major.minor.build (or patchlevel). .N)rappendmaprrliststrru)rbuildrdZintsZstringsrrr _norm_versions   rz'(?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\])c Cstj|kr|||fSxddD]R}y&tj|}|j}|jrBtdWn$tk rh}zwWYdd}~XqXPqW|||fS|j}tj |}|dk r|j \}}}|d dkr|dd }|d dkr|dd }t |}|||fS) a+ Tries to figure out the OS version used and returns a tuple (system, release, version). It uses the "ver" shell command for this which is known to exists on Windows, DOS. XXX Others too ? In case this fails, the given parameters are used as defaults. vercommand /c ver cmd /c verzcommand failedNr?r~)rrrrBrBrBrB) sysplatformr*rzr-closersrD _ver_outputr`r3r) systemreleaserZsupported_platformsr{pipeinfoZwhyr9rrr _syscmd_vers,           rZ2000ZXPr=Z 2003ServerZpost2003Vista78rz8.1zpost8.1Z10Zpost10Z 2008ServerZ 2008ServerR2Z 2012ServerZ 2012ServerR2Zpost2012ServerR2c(Csyddlm}Wntk r,||||fSXyddlm}m}m}m}Wn,tk rvddlm}m}m}m}YnX|} | j p| dd\} } } dj | | | }t j | | fpt j | dfp|}| dd| | fkr$ydj | j }Wn8tk r"|ddd krd |dd}YnXt| d ddkrZtj | | fpXtj | dfpX|}d} z.y||d } || d d}Wn YnXWd| r|| X||||fS)Nr)getwindowsversion) OpenKeyEx QueryValueExCloseKeyHKEY_LOCAL_MACHINErz {0}.{1}.{2}r=zSP{} z Service Pack ZSPZ product_typez,SOFTWARE\Microsoft\Windows NT\CurrentVersionZ CurrentType)rr ImportErrorwinregrrrr_winregZplatform_versionformat_WIN32_CLIENT_RELEASESrZservice_pack_majorAttributeErrorgetattr_WIN32_SERVER_RELEASES)rrcsdptyperrrrrZwinverZmajminrkeyrrr win32_versD  rcCsd}tjj|sdSy ddl}Wntk r4dSXt|d}|j|}WdQRX|d}d }tjj}|d krxd}|||fS) Nz0/System/Library/CoreServices/SystemVersion.plistrr"ZProductVersionr ppcPower MacintoshZPowerPC)r r r )rr) r*r+rCplistlibrr,loadunamemachine)fnrr7rr versioninforrrr _mac_ver_xmlEs    rcCst}|dk r|S|||fS)a< Get MacOS version information and return it as tuple (release, versioninfo, machine) with versioninfo being a tuple (version, dev_stage, non_release_version). Entries which cannot be determined are set to the parameter values which default to ''. All tuple entries are strings. N)r)rrrrrrrmac_ver[s rc Cs@ddlm}y|j|}|dkr$|S|Stk r:|SXdS)Nr)System) java.langrZ getPropertyr)namedefaultrrMrrr _java_getpropns  rc Csy ddl}Wntk r(||||fSXtd|}td|}|\}}}td|}td|}td|}|||f}|\}} } td| } td |}td | } || | f}||||fS) a] Version interface for Jython. Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being a tuple (vm_name, vm_release, vm_vendor) and osinfo being a tuple (os_name, os_version, os_arch). Values which cannot be determined are set to the defaults given as parameters (which all default to ''). rNz java.vendorz java.versionz java.vm.namezjava.vm.vendorzjava.vm.versionz java.os.archz java.os.namezjava.os.version)rrr) rvendorvminfoosinfojavaZvm_nameZ vm_releaseZ vm_vendoros_name os_versionos_archrrrjava_verys"              rc Cs|dkrd|||fS|dkr|dkr0|||fS|jd}|ryt|d}Wntk rbYn X|d}t||d<dj|}|dkrd }qd }n,|d krd }|r|d }qd }n |dkrd}|||fS)z Returns (system, release, version) aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion. ZRhapsodyzMacOS X ServerZSunOS5r~rr6ZSolarisZIRIX64ZIRIXz (64bit)64bitrrWindows)rr)rrrrru)rrrrdmajorrrr system_aliass2      rcGsdjddtt|D}|jdd}|jdd}|jdd}|jdd}|jd d}|jd d}|jd d}|jd d}|jd d}x|jdd}||krP|}qWx|ddkr|dd}qW|S)zq Helper to format the platform string in a filename compatible format e.g. "system-version-machine". r>css|]}|jVqdS)N)rD)r%xrrr sz_platform.. _/\:;"()unknownr z--r?NrBrB)rufilterr.replace)argsrZcleanedrrr _platforms$          rcCsDy ddl}Wntk r |SXy|jStk r>|SXdS)z8 Helper to determine the node name of this machine. rN)socketrZ gethostnamers)rrrrr_nodes rcCsFtjj|}x4tjj|r@tjjtjjtjj|tj|}qW|S)zT In case filepath is a symlink, follow it until a real file is reached. )r*r+abspathislinknormpathrudirnamereadlink)filepathrrr_follow_symlinkss  "rc Cshtjdkr|Sytjd|tf}Wnttfk r<|SX|jj}|j }| s\|r`|S|SdS)z. Interface to the system's uname command. rrrzuname %s 2> %sN)rrr) rrr*rzDEV_NULLrrsr-rDr)Zoptionrr7outputrrrr _syscmd_uname s   rc Cs|tjd kr|St|}ytjd|gtjtjd}Wnttfk rJ|SX|j dj d}|j }| sp|rt|S|SdS) z Interface to the system's file command. The function uses the -b option of the file command to have it omit the filename in its output. Follow the symlinks. It returns default in case the command should fail. rrrrw)stdoutstderrrzlatin-1N)rrr) rrr subprocessPopenPIPEZSTDOUTrrsZ communicater$wait)targetrprocrrrrr _syscmd_files   r WindowsPErMSDOS)rrrc Cs.|sLddl}y|jd}Wn |jk r:|jd}YnXt|dd}|r\t|d}nd}| r|tjkrtjtkrttj\}}|r|}|r|}||fSd|kr||fSd |krd }nd |krd }n d |krd}d|krd}n@d|krd|krd}nd}n d|krd}nd|kr&d}n||fS)a Queries the given executable (defaults to the Python interpreter binary) for various architecture information. Returns a tuple (bits, linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are returned as strings. Values that cannot be determined are returned as given by the parameter presets. If bits is given as '', the sizeof(pointer) (or sizeof(long) on Python version < 1.5.2) is used as indicator for the supported pointer size. The function relies on the system's "file" command to do the actual work. This is available on most if not all Unix platforms. On some non-Unix platforms where the "file" command does not exist and the executable is set to the Python interpreter binary defaults from _default_architecture are used. rNPrdbitr r4z32-bit32bitZN32Zn32bitz64-bitrZELFZPErrZCOFFzMS-DOSr) structZcalcsizeerrorrrrr4r_default_architecture)r4bitslinkagersizeZfileoutr rdrrr architectureBsL       r uname_resultz-system node release version machine processorcCsd}tdk rtSd}ytj\}}}}}Wntk rBd}YnX|sdttd|||||f r|rtj}d}d}t}d}d}|dkrt \}}}} |r|rd}|sdtj krtj j dd}ntj j dd}|stj j d|}|r se      :2 6    0 0  #6   T       k      [