mfc@sdZddlZddlZejZddddddd d d d d dddgZdZdekrdZdZddl Tyddl m Z Wne k rnXddl Z ddl Z ejee [ n,dekrVdZdZddlTyddlm Z Wne k r$nXddlZ ddlZejee[ndekrdZdZddlTyddlm Z Wne k rnXejjddkrddlZ nddlZ ddlmZddlZejee[ndekrdZdZddlTyddlm Z Wne k rQnXddlZ ddlZejee[ndekrdZdZddlTyddlm Z Wne k rnXddlZ ddlZejee[n e de ejdZ>ej.d?d@Z?e?dArle?dB rle?dCrld Z@d!ZAZBdDZCdEZDdFZEdGZFdHZGne?dBrdIZHdJZIejdBdKdLdMgne?dNrdOZJdPZKejdNdQdRdSgne?dArpe?dTsdUddVZLej.dTne?dWsBdUddXZMej.dWne?dYspdUddZZNej.dYqpnddlOZPd[ZQd\ZRyePjSeTeReQWne0k rnXd]ZUd^ZVyePjSeWeVeUWne0k rnXdS(asOS routines for Mac, NT, or Posix depending on what system we're on. This exports: - all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc. - os.path is one of the modules posixpath, or ntpath - os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos' - os.curdir is a string representing the current directory ('.' or ':') - os.pardir is a string representing the parent directory ('..' or '::') - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\') - os.extsep is the extension separator ('.' or '/') - os.altsep is the alternate pathname separator (None or '/') - os.pathsep is the component separator used in $PATH etc - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n') - os.defpath is the default search path for executables - os.devnull is the file path of the null device ('/dev/null', etc.) Programs that import and use 'os' stand a better chance of being portable between different platforms. Of course, they must then only use functions that are defined by all platforms (e.g., unlink and opendir), and leave all pathname manipulation to os.path (e.g., split and join). iNtaltseptcurdirtpardirtseptextseptpathseptlineseptdefpathtnametpathtdevnulltSEEK_SETtSEEK_CURtSEEK_ENDcCsSyt|jSWn;tk rNgt|D]}|ddkr.|^q.SXdS(Nit_(tlistt__all__tAttributeErrortdir(tmoduletn((s/usr/lib64/python2.7/os.pyt_get_exports_list#s tposixs (t*(t_exittnts tos2sEMX GCC(tlinktcetriscossno os specific module foundsos.path(RRRRRRRR iiiicCstj|\}}|s3tj|\}}n|r|rtj| ryt||Wn+tk r}|jtjkrqnX|tkrdSnt||dS(smakedirs(path [, mode=0777]) Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. This is recursive. N( R tsplittexiststmakedirstOSErrorterrnotEEXISTRtmkdir(Rtmodetheadttailte((s/usr/lib64/python2.7/os.pyR s   cCst|tj|\}}|s=tj|\}}nxH|r|ryt|Wntk rnPnXtj|\}}q@WdS(sremovedirs(path) Super-rmdir; remove a leaf directory and all empty intermediate ones. Works like rmdir except that, if the leaf directory is successfully removed, directories corresponding to rightmost path segments will be pruned away until either the whole path is consumed or an error occurs. Errors during this latter phase are ignored -- they generally mean that a directory was not empty. N(trmdirR Rterror(RR&R'((s/usr/lib64/python2.7/os.pyt removedirss  cCstj|\}}|r>|r>tj| r>t|nt||tj|\}}|r|ryt|Wqtk rqXndS(s@renames(old, new) Super-rename; create directories as necessary and delete any left empty. Works like rename, except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path segments of the old name will be pruned way until either the whole path is consumed or a nonempty directory is found. Note: this function can fail with the new directory structure made if you lack permissions needed to unlink the leaf directory or file. N(R RRR trenameR+R*(toldtnewR&R'((s/usr/lib64/python2.7/os.pytrenamess    R R+R/ccs:tjtjtj}}}yt|}Wn-tk r\}|dk rX||ndSXgg} } x@|D]8} |||| r| j| qq| j| qqW|r|| | fVnxX| D]P} ||| } |s||  rx%t| |||D] } | Vq WqqW|s6|| | fVndS(s< Directory tree generator. For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), yields a 3-tuple dirpath, dirnames, filenames dirpath is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding '.' and '..'). filenames is a list of the names of the non-directory files in dirpath. Note that the names in the lists are just names, with no path components. To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name). If optional arg 'topdown' is true or not specified, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top down). If topdown is false, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom up). When topdown is true, the caller can modify the dirnames list in-place (e.g., via del or slice assignment), and walk will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, or to impose a specific order of visiting. Modifying dirnames when topdown is false is ineffective, since the directories in dirnames have already been generated by the time dirnames itself is generated. By default errors from the os.listdir() call are ignored. If optional arg 'onerror' is specified, it should be a function; it will be called with one argument, an os.error instance. It can report the error to continue with the walk, or raise the exception to abort the walk. Note that the filename is available as the filename attribute of the exception object. By default, os.walk does not follow symbolic links to subdirectories on systems that support them. In order to get this functionality, set the optional argument 'followlinks' to true. Caution: if you pass a relative pathname for top, don't change the current working directory between resumptions of walk. walk never changes the current directory, and assumes that the client doesn't either. Example: import os from os.path import join, getsize for root, dirs, files in os.walk('python/Lib/email'): print root, "consumes", print sum([getsize(join(root, name)) for name in files]), print "bytes in", len(files), "non-directory files" if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories N( R tislinktjointisdirtlistdirR*tNonetappendtwalk(ttopttopdowntonerrort followlinksR0R1R2tnamesterrtdirstnondirsRtnew_pathtx((s/usr/lib64/python2.7/os.pyR6s*9     R6cGst||dS(spexecl(file, *args) Execute the executable file with argument list args, replacing the current process. N(texecv(tfiletargs((s/usr/lib64/python2.7/os.pytexecl3scGs"|d}t||d |dS(sexecle(file, *args, env) Execute the executable file with argument list args and environment env, replacing the current process. iN(texecve(RBRCtenv((s/usr/lib64/python2.7/os.pytexecle:s cGst||dS(sexeclp(file, *args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. N(texecvp(RBRC((s/usr/lib64/python2.7/os.pytexeclpBscGs"|d}t||d |dS(sexeclpe(file, *args, env) Execute the executable file (which is searched for along $PATH) with argument list args and environment env, replacing the current process. iN(texecvpe(RBRCRF((s/usr/lib64/python2.7/os.pytexeclpeIs cCst||dS(sexecvp(file, args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. args may be a list or tuple of strings. N(t_execvpe(RBRC((s/usr/lib64/python2.7/os.pyRHRscCst|||dS(sexecvpe(file, args, env) Execute the executable file (which is searched for along $PATH) with argument list args and environment env , replacing the current process. args may be a list or tuple of strings. N(RL(RBRCRF((s/usr/lib64/python2.7/os.pyRJZsRDRGRIRKRHRJcCsZ|dk r!t}||f}nt}|f}t}tj|\}}|rb|||dSd|kr{|d}nt}|jt}d} d} x|D]} tj| |} y|| |Wqt k r0} t j d}| j t j kr1| j t jkr1| dkr1| } |} q1qXqW| rJt | | nt | |dS(NtPATHi(R4RERAtenvironR RRRR1R*tsystexc_infoR"tENOENTtENOTDIR(RBRCRFtfunctargrestR&R'tenvpathRMt saved_exctsaved_tbRtfullnameR(ttb((s/usr/lib64/python2.7/os.pyRLes:      $ cCst|ddS(Nt(tputenv(tkey((s/usr/lib64/python2.7/os.pytunsetenvs(t_EnvironR^cBseZdZdZdZyeWnek rEdZnXdZdZdZ dZ dZ d d Z d d Zd ZRS( cCsJtjj||j}x*|jD]\}}|||j integer Execute file with arguments from args in a subprocess. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. N(RR4RA(R%RBRC((s/usr/lib64/python2.7/os.pyR~,scCst||||tS(s:spawnve(mode, file, args, env) -> integer Execute file with arguments from args in a subprocess with the specified environment. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. (RRE(R%RBRCRF((s/usr/lib64/python2.7/os.pytspawnve5scCst|||dtS(s8spawnvp(mode, file, args) -> integer Execute file (which is looked for along $PATH) with arguments from args in a subprocess. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. N(RR4RH(R%RBRC((s/usr/lib64/python2.7/os.pytspawnvpAscCst||||tS(s\spawnvpe(mode, file, args, env) -> integer Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. (RRJ(R%RBRCRF((s/usr/lib64/python2.7/os.pytspawnvpeKscGst|||S(sspawnl(mode, file, *args) -> integer Execute file with arguments from args in a subprocess. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. (R~(R%RBRC((s/usr/lib64/python2.7/os.pytspawnlYscGs!|d}t|||d |S(s:spawnle(mode, file, *args, env) -> integer Execute file with arguments from args in a subprocess with the supplied environment. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. i(R(R%RBRCRF((s/usr/lib64/python2.7/os.pytspawnlebs RRRRcGst|||S(sWspawnlp(mode, file, *args) -> integer Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. (R(R%RBRC((s/usr/lib64/python2.7/os.pytspawnlptscGs!|d}t|||d |S(s]spawnlpe(mode, file, *args, env) -> integer Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. If mode == P_NOWAIT return the pid of the process. If mode == P_WAIT return the process's exit code if it exits normally; otherwise return -SIG, where SIG is the signal that killed it. i(R(R%RBRCRF((s/usr/lib64/python2.7/os.pytspawnlpe~s RRRtpopen2ttc Csddl}d}|j|tddddl}|j}|j|dt|td|d|d |d t}|j |j fS( sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout) are returned.iNs4os.popen2 is deprecated. Use the subprocess module.t stacklevelitshelltbufsizetstdintstdoutt close_fds( twarningstwarntDeprecationWarningt subprocesstPIPEtPopent isinstancet basestringtTrueRR(tcmdR%RRtmsgRRtp((s/usr/lib64/python2.7/os.pyRs    tpopen3cCsddl}d}|j|tddddl}|j}|j|dt|td|d|d |d |d t}|j |j |j fS( sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.iNs4os.popen3 is deprecated. Use the subprocess module.RiRRRRtstderrR( RRRRRRRRRRRR(RR%RRRRRR((s/usr/lib64/python2.7/os.pyRs   tpopen4cCsddl}d}|j|tddddl}|j}|j|dt|td|d|d |d |jd t }|j |j fS( sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout_stderr) are returned.iNs4os.popen4 is deprecated. Use the subprocess module.RiRRRRRR( RRRRRRRRtSTDOUTRRR(RR%RRRRRR((s/usr/lib64/python2.7/os.pyRs   cCs t||S(N(t stat_result(ttupRs((s/usr/lib64/python2.7/os.pyt_make_stat_resultscCs|j\}}t|fS(N(t __reduce__R(tsrttypeRC((s/usr/lib64/python2.7/os.pyt_pickle_stat_resultscCs t||S(N(tstatvfs_result(RRs((s/usr/lib64/python2.7/os.pyt_make_statvfs_resultscCs|j\}}t|fS(N(RR(RRRC((s/usr/lib64/python2.7/os.pyt_pickle_statvfs_results(sos2snt(sos2snt(Xt__doc__ROR"tbuiltin_module_namest_namesRRRRRRt ImportErrort posixpathR textendRtntpathRtversiontfindt os2emxpatht _emx_linkRRRt riscospathtmodulestos.pathRRRRRRRR R R R R R+R/RR4tFalseR6R5RNRxRDRGRIRKRHRJRLR[R_R]t riscosenvironR^tIterableUserDictRzR|tP_WAITRt P_NOWAITORR~RRRRRRRRRRtcopy_regt _copy_regRRtpickleRRRR(((s/usr/lib64/python2.7/os.pyts,                              :   Z         #      5*    %