craft_parts.permissions module

Specify and apply permissions and ownership to part-owned files.

class craft_parts.permissions.Permissions(**data)[source]

Bases: BaseModel

Description of the ownership and permission settings for a set of files.

A Permissions object specifies that a given pattern-like path should be owned by owner with a given group, and have the read/write/execute bits defined by mode.

Notes

  • path is optional and defaults to “everything”;

  • owner and group are optional if both are omitted - that is, if one of the pair is specified then both must be;

  • mode is a string containing an integer in base 8. For example, “755”, “0755” and “0o755” are all accepted and are the equivalent of calling chmod 755 ....

Parameters:

data (Any) –

applies_to(path)[source]

Whether this Permissions’ path pattern applies to path.

Parameters:

path (Union[Path, str]) –

Return type:

bool

apply_permissions(target)[source]

Apply the permissions configuration to target.

Note that this method doesn’t check if this Permissions’s path pattern matches target; be sure to call applies_to() beforehand.

Parameters:

target (Union[Path, str]) –

Return type:

None

group: Optional[int]
mode: Optional[str]
property mode_octal: int

Get the mode as a base-8 integer.

Return type:

int

owner: Optional[int]
path: str
classmethod validate_root(values)[source]

Validate that “owner” and “group” are correctly specified.

Parameters:

values (Dict[Any, Any]) –

Return type:

Dict[Any, Any]

craft_parts.permissions.apply_permissions(target, permissions)[source]

Apply all permissions configurations in permissions to target.

Parameters:
  • target (Union[Path, str]) –

  • permissions (List[Permissions]) –

Return type:

None

craft_parts.permissions.filter_permissions(target, permissions)[source]

Get the subset of permissions whose path patterns apply to target.

Parameters:
  • target (Union[Path, str]) –

  • permissions (List[Permissions]) –

Return type:

List[Permissions]

craft_parts.permissions.permissions_are_compatible(left, right)[source]

Whether two sets of permissions definitions are not in conflict with each other.

The function determines whether applying the two lists of Permissions to a given path would result in the same owner, group and mode.

Remarks:

  • If either of the parameters is None or empty, they are considered compatible

    because they are understood to not be “in conflict”.

  • Otherwise, the permissions are incompatible if one would they would set one

    of the attributes (owner, group and mode) to different values, even if one of them would not modify the attribute at all.

  • The path attribute of the Permissions are completely ignored, as they

    are understood to apply to the same file of interest through a previous call of filter_permissions().

type left:

Optional[List[Permissions]]

param left:

the first set of permissions.

type right:

Optional[List[Permissions]]

param right:

the second set of permissions.

rtype:

bool