MCPcopy Index your code
hub / github.com/python/cpython / chown

Function chown

Lib/shutil.py:1474–1512  ·  view source on GitHub ↗

Change owner user and group of the given path. user and group can be the uid/gid or the user/group names, and in that case, they are converted to their respective uid/gid. If dir_fd is set, it should be an open file descriptor to the directory to be used as the root of *path* if it

(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True)

Source from the content-addressed store, hash-verified

1472
1473
1474def chown(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True):
1475 """Change owner user and group of the given path.
1476
1477 user and group can be the uid/gid or the user/group names, and in that case,
1478 they are converted to their respective uid/gid.
1479
1480 If dir_fd is set, it should be an open file descriptor to the directory to
1481 be used as the root of *path* if it is relative.
1482
1483 If follow_symlinks is set to False and the last element of the path is a
1484 symbolic link, chown will modify the link itself and not the file being
1485 referenced by the link.
1486 """
1487 sys.audit('shutil.chown', path, user, group)
1488
1489 if user is None and group is None:
1490 raise ValueError("user and/or group must be set")
1491
1492 _user = user
1493 _group = group
1494
1495 # -1 means don't change it
1496 if user is None:
1497 _user = -1
1498 # user can either be an int (the uid) or a string (the system username)
1499 elif isinstance(user, str):
1500 _user = _get_uid(user)
1501 if _user is None:
1502 raise LookupError("no such user: {!r}".format(user))
1503
1504 if group is None:
1505 _group = -1
1506 elif not isinstance(group, int):
1507 _group = _get_gid(group)
1508 if _group is None:
1509 raise LookupError("no such group: {!r}".format(group))
1510
1511 os.chown(path, _user, _group, dir_fd=dir_fd,
1512 follow_symlinks=follow_symlinks)
1513
1514def get_terminal_size(fallback=(80, 24)):
1515 """Get the size of the terminal window.

Callers

nothing calls this directly

Calls 4

_get_uidFunction · 0.85
_get_gidFunction · 0.85
chownMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…