Lines Matching refs:os
7 import os
35 _WINDOWS = os.name == 'nt'
37 if os.name == 'posix':
45 _USE_CP_SENDFILE = hasattr(os, "sendfile") and sys.platform.startswith("linux")
133 blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB
144 sent = os.sendfile(outfd, infd, offset, blocksize)
161 if offset == 0 and os.lseek(outfd, 0, os.SEEK_CUR) == 0:
204 if isinstance(src, os.DirEntry) and hasattr(os.path, 'samestat'):
206 return os.path.samestat(src.stat(), os.stat(dst))
210 if hasattr(os.path, 'samefile'):
212 return os.path.samefile(src, dst)
217 return (os.path.normcase(os.path.abspath(src)) ==
218 os.path.normcase(os.path.abspath(dst)))
221 return fn.stat() if isinstance(fn, os.DirEntry) else os.stat(fn)
224 return fn.is_symlink() if isinstance(fn, os.DirEntry) else os.path.islink(fn)
248 fn = fn.path if isinstance(fn, os.DirEntry) else fn
254 os.symlink(os.readlink(src), dst)
283 if not os.path.exists(dst):
300 if not follow_symlinks and _islink(src) and os.path.islink(dst):
301 if hasattr(os, 'lchmod'):
302 stat_func, chmod_func = os.lstat, os.lchmod
306 stat_func, chmod_func = _stat, os.chmod
311 if hasattr(os, 'listxattr'):
322 names = os.listxattr(src, follow_symlinks=follow_symlinks)
329 value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
330 os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
357 follow = follow_symlinks or not (_islink(src) and os.path.islink(dst))
361 return getattr(os, name, _nop)
366 fn = getattr(os, name, _nop)
367 if fn in os.supports_follow_symlinks:
371 if isinstance(src, os.DirEntry):
417 if os.path.isdir(dst):
418 dst = os.path.join(dst, os.path.basename(src))
434 if os.path.isdir(dst):
435 dst = os.path.join(dst, os.path.basename(src))
455 ignored_names = ignore(os.fspath(src), [x.name for x in entries])
459 os.makedirs(dst, exist_ok=dirs_exist_ok)
466 srcname = os.path.join(src, srcentry.name)
467 dstname = os.path.join(dst, srcentry.name)
471 if is_symlink and os.name == 'nt':
478 linkto = os.readlink(srcname)
483 os.symlink(linkto, dstname)
487 if not os.path.exists(linkto) and ignore_dangling_symlinks:
533 platforms that don't support os.symlink.
538 `src` contents, as returned by os.listdir():
559 with os.scandir(src) as itr:
566 if hasattr(os.stat_result, 'st_file_attributes'):
581 st = os.lstat(path)
595 return os.path.islink(path)
600 with os.scandir(path) as scandir_it:
603 onerror(os.scandir, path, sys.exc_info())
612 # os.scandir or entry.is_dir above.
615 onerror(os.path.islink, fullname, sys.exc_info())
620 os.unlink(fullname)
622 onerror(os.unlink, fullname, sys.exc_info())
624 os.rmdir(path)
626 onerror(os.rmdir, path, sys.exc_info())
631 with os.scandir(topfd) as scandir_it:
635 onerror(os.scandir, path, sys.exc_info())
638 fullname = os.path.join(path, entry.name)
649 onerror(os.lstat, fullname, sys.exc_info())
653 dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd)
656 onerror(os.open, fullname, sys.exc_info())
659 if os.path.samestat(orig_st, os.fstat(dirfd)):
662 os.close(dirfd)
664 os.rmdir(entry.name, dir_fd=topfd)
666 onerror(os.rmdir, fullname, sys.exc_info())
671 # os.scandir or stat.S_ISDIR above.
675 onerror(os.path.islink, fullname, sys.exc_info())
678 os.close(dirfd)
681 os.unlink(entry.name, dir_fd=topfd)
683 onerror(os.unlink, fullname, sys.exc_info())
685 _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
686 os.supports_dir_fd and
687 os.scandir in os.supports_fd and
688 os.stat in os.supports_follow_symlinks)
716 path = os.fsdecode(path)
720 orig_st = os.lstat(path, dir_fd=dir_fd)
722 onerror(os.lstat, path, sys.exc_info())
725 fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
728 onerror(os.open, path, sys.exc_info())
731 if os.path.samestat(orig_st, os.fstat(fd)):
734 os.close(fd)
736 os.rmdir(path, dir_fd=dir_fd)
738 onerror(os.rmdir, path, sys.exc_info())
744 onerror(os.path.islink, path, sys.exc_info())
747 os.close(fd)
756 onerror(os.path.islink, path, sys.exc_info())
772 >>> os.path.basename('/bar/foo')
774 >>> os.path.basename('/bar/foo/')
779 path = os.fspath(path)
780 sep = os.path.sep + (os.path.altsep or '')
781 return os.path.basename(path.rstrip(sep))
793 overwritten depending on os.rename() semantics.
797 recreated under the new name if os.rename() fails because of cross
811 if os.path.isdir(dst):
815 os.rename(src, dst)
818 # Using _basename instead of os.path.basename is important, as we must
820 real_dst = os.path.join(dst, _basename(src))
822 if os.path.exists(real_dst):
825 os.rename(src, real_dst)
827 if os.path.islink(src):
828 linkto = os.readlink(src)
829 os.symlink(linkto, real_dst)
830 os.unlink(src)
831 elif os.path.isdir(src):
836 or (not os.access(src, os.W_OK) and os.listdir(src)
846 os.unlink(src)
850 src = os.path.abspath(src)
851 dst = os.path.abspath(dst)
852 if not src.endswith(os.path.sep):
853 src += os.path.sep
854 if not dst.endswith(os.path.sep):
855 dst += os.path.sep
931 archive_dir = os.path.dirname(archive_name)
933 if archive_dir and not os.path.exists(archive_dir):
937 os.makedirs(archive_dir)
959 base_dir = os.path.join(root_dir, base_dir)
966 archive_name = os.path.abspath(archive_name)
979 archive_dir = os.path.dirname(base_name)
981 if archive_dir and not os.path.exists(archive_dir):
985 os.makedirs(archive_dir)
994 arcname = os.path.normpath(base_dir)
996 base_dir = os.path.join(root_dir, base_dir)
997 base_dir = os.path.normpath(base_dir)
998 if arcname != os.curdir:
1002 for dirpath, dirnames, filenames in os.walk(base_dir):
1005 arcdirpath = os.path.relpath(arcdirpath, root_dir)
1006 arcdirpath = os.path.normpath(arcdirpath)
1008 path = os.path.join(dirpath, name)
1009 arcname = os.path.join(arcdirpath, name)
1014 path = os.path.join(dirpath, name)
1015 path = os.path.normpath(path)
1016 if os.path.isfile(path):
1017 arcname = os.path.join(arcdirpath, name)
1023 zip_filename = os.path.abspath(zip_filename)
1115 base_dir = os.curdir
1122 base_name = os.fspath(base_name)
1125 save_cwd = os.getcwd()
1128 base_name = os.path.abspath(base_name)
1130 os.chdir(root_dir)
1138 os.chdir(save_cwd)
1200 dirname = os.path.dirname(path)
1201 if not os.path.isdir(dirname):
1202 os.makedirs(dirname)
1221 targetpath = os.path.join(extract_dir, *name.split('/'))
1298 extract_dir = os.getcwd()
1300 extract_dir = os.fspath(extract_dir)
1301 filename = os.fspath(filename)
1326 if hasattr(os, 'statvfs'):
1340 st = os.statvfs(path)
1392 os.chown(path, _user, _group)
1403 by invoking os.get_terminal_size.
1411 The value returned is a named tuple of type os.terminal_size.
1415 columns = int(os.environ['COLUMNS'])
1420 lines = int(os.environ['LINES'])
1427 size = os.get_terminal_size(sys.__stdout__.fileno())
1430 # os.get_terminal_size() is unsupported
1431 size = os.terminal_size(fallback)
1437 return os.terminal_size((columns, lines))
1442 # directories pass the os.access check.
1444 return (os.path.exists(fn) and os.access(fn, mode)
1445 and not os.path.isdir(fn))
1448 def which(cmd, mode=os.F_OK | os.X_OK, path=None):
1453 `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
1454 of os.environ.get("PATH"), or can be overridden with a custom search
1461 if os.path.dirname(cmd):
1469 path = os.environ.get("PATH", None)
1472 path = os.confstr("CS_PATH")
1474 # os.confstr() or CS_PATH is not available
1475 path = os.defpath
1476 # bpo-35755: Don't use os.defpath if the PATH environment variable is
1484 path = os.fsencode(path)
1485 path = path.split(os.fsencode(os.pathsep))
1487 path = os.fsdecode(path)
1488 path = path.split(os.pathsep)
1492 curdir = os.curdir
1494 curdir = os.fsencode(curdir)
1499 pathext_source = os.getenv("PATHEXT") or _WIN_DEFAULT_PATHEXT
1500 pathext = [ext for ext in pathext_source.split(os.pathsep) if ext]
1503 pathext = [os.fsencode(ext) for ext in pathext]
1519 normdir = os.path.normcase(dir)
1523 name = os.path.join(dir, thefile)