lJc@s!dZdZddkZddkZddkZddkZddklZddkl Z ddk l Z ddk l Z dZd Zd Zd ad Zd ZddZdaaadZdZdd d dZdZd d dddd ddZdZdS(sudistutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules. s4$Id: util.py 46157 2006-05-23 21:54:23Z tim.peters $iN(tDistutilsPlatformError(tnewer(tspawn(tlogc Cstidjpttd o tiSnti\}}}}}ti|}ti|dd}ti|dd}ti|dd}|d d jod ||fSnH|d d joA|d d jo,d}dt |d d|df}qn|d djod ||fSn|d djod|||fSn|d djo?d}t i d}|i |}|o|i }qn]|d djoKddkl}|}tiid} | p|id} n| pytd} Wntj oqXt idd| i}| i|d*j o)d i|i d!id d } qn| onddkl}| }d"}|d d#jo&|id$dio d%}q|d+jo d(}qqnd)|||fS(,sReturn a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact information included depends on the OS; eg. for IRIX the architecture isn't particularly important (IRIX only runs on SGI hardware), but for Linux the kernel version isn't particularly important. Examples of returned values: linux-i586 linux-alpha (?) solaris-2.6-sun4u irix-5.3 irix64-6.2 For non-POSIX platforms, currently just returns 'sys.platform'. tposixtunamet/tt t_t-itlinuxs%s-%stsunosit5tsolariss%d.%siiitirixtaixs%s-%s.%sitcygwins[\d.]+tdarwini(tget_config_varstMACOSX_DEPLOYMENT_TARGETs0/System/Library/CoreServices/SystemVersion.plists'ProductUserVisibleVersion\s*s(.*?)t.itmacosxs10.4.t UNIVERSALSDKtfattPowerPCtPower_Macintoshtppcs%s-%s-%sN(RR(tostnamethasattrtsystplatformRtstringtlowertreplacetinttretcompiletmatchtgrouptdistutils.sysconfigRtenvirontgettopentIOErrortsearchtreadtclosetNonetjointsplittstrip( tosnamethosttreleasetversiontmachinetrel_retmRtcfgvarstmacvertf((s!/sys/lib/python/distutils/util.pyt get_platformsd! *   -  cCstidjo|Sn|p|Sn|ddjotd|n|ddjotd|nti|d}xd|jo|idqW|p tiSnttii |S(sReturn 'pathname' as a name that will work on the native filesystem, i.e. split it on '/' and put it back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. Rispath '%s' cannot be absoluteispath '%s' cannot end with '/'R( Rtsept ValueErrorR!R3tremovetcurdirtapplytpathR2(tpathnametpaths((s!/sys/lib/python/distutils/util.pyt convert_path|s  cCstidjoEtii|ptii||Sqtii||dSnDtidjoNtii|\}}|ddjo|d}ntii||SntidjoQtii|\}}|dtijo|d}ntii||Sntidjodtii|ptii||Sqti|dd}d|d}tii||Snt d tid S( s Return 'pathname' with 'new_root' prepended. If 'pathname' is relative, this is equivalent to "os.path.join(new_root,pathname)". Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. Ritntis\tos2tmact:s!nothing known about platform '%s'N( RRREtisabsR2t splitdriveR@R!R3R(tnew_rootRFtdriveREtelements((s!/sys/lib/python/distutils/util.pyt change_roots,icCstodSntidjoDtiid o0ddk}|itidtidtfalsetofft0isinvalid truth value %rN(RRRRRR(RRR>RRR(R!R"RA(tval((s!/sys/lib/python/distutils/util.pyt strtobool^s   ic Cs|djoto |dj}n|py&ddkl}|d\} } Wn6tj o*ddkl} d| d} } nXtid| |p| dj oti | d} nt | d} | i d| i t i tt|d d | i d |||||f| inti| g} |d jo| id d n"|djo| id dnt| d|tti| fd| d|n:ddkl}x&|D]}|ddjoqn|todpd}|}|oB|t| |jotd||fn|t|}n|otii ||}ntii|}|o`|pt||o2tid|||p||||qqtid||qqWdS(sByte-compile a collection of Python source files to either .pyc or .pyo files in the same directory. 'py_files' is a list of files to compile; any files that don't end in ".py" are silently skipped. 'optimize' must be one of the following: 0 - don't optimize (generate .pyc) 1 - normal optimization (like "python -O") 2 - extra optimization (like "python -OO") If 'force' is true, all files are recompiled regardless of timestamps. The source filename encoded in each bytecode file defaults to the filenames listed in 'py_files'; you can modify these with 'prefix' and 'basedir'. 'prefix' is a string that will be stripped off of each source filename, and 'base_dir' is a directory name that will be prepended (after 'prefix' is stripped). You can supply either or both (or neither) of 'prefix' and 'base_dir', as you wish. If 'dry_run' is true, doesn't actually do anything that would affect the filesystem. Byte-compilation is either done directly in this interpreter process with the standard py_compile module, or indirectly by writing a temporary script and executing it. Normally, you should let 'byte_compile()' figure out to use direct compilation or not (see the source for details). The 'direct' flag is used by the script generated in indirect mode; unless you know what you're doing, leave it set to None. ii(tmkstemps.py(tmktemps$writing byte-compilation script '%s'tws2from distutils.util import byte_compile files = [ s, s] s byte_compile(files, optimize=%r, force=%r, prefix=%r, base_dir=%r, verbose=%r, dry_run=0, direct=1) is-Ois-OORs removing %s(R&itctos1invalid prefix: filename %r doesn't start with %rsbyte-compiling %s to %ss%skipping byte-compilation of %s to %sN(R1t __debug__ttempfileRt ImportErrorRRR}RtfdopenR,twriteR!R2tmaptreprR0Rt executabletinsertRRRBt py_compileR&RrRAREtbasenameRtdebug(tpy_filestoptimizetforceRgtbase_dirRRtdirectRt script_fdt script_nameRtscripttcmdR&tfiletcfiletdfilet cfile_base((s!/sys/lib/python/distutils/util.pyt byte_compilensf,  &    cCs>ti|d}tti|}ti|dd}|S(sReturn a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline. s iRs (R!R3RR4R2(theadertlines((s!/sys/lib/python/distutils/util.pyt rfc822_escapes(t__doc__t __revision__RRR!R%tdistutils.errorsRtdistutils.dep_utilRtdistutils.spawnRt distutilsRR?RHRRRURZRcRiR1RkRlRmRnRzRRRR(((s!/sys/lib/python/distutils/util.pyss.0 m  &     ?