craft_parts.permissions module¶
Specify and apply permissions and ownership to part-owned files.
- class craft_parts.permissions.Permissions(**data)[source]¶
Bases:
BaseModelDescription of the ownership and permission settings for a set of files.
A
Permissionsobject specifies that a given pattern-likepathshould be owned byownerwith a givengroup, and have the read/write/execute bits defined bymode.Notes
pathis optional and defaults to “everything”;ownerandgroupare optional if both are omitted - that is, if one of the pair is specified then both must be;modeis a string containing an integer in base 8. For example, “755”, “0755” and “0o755” are all accepted and are the equivalent of callingchmod 755 ....
- Parameters:
data (
Any)
- applies_to(path)[source]¶
Whether this Permissions’ path pattern applies to
path.- Parameters:
path (
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 matchestarget; be sure to callapplies_to()beforehand.- Parameters:
target (
Path|str)- Return type:
None
-
group:
int|None¶ The numeric group ID (GID) of the desired owner group on the host system.
This entry is required if the permissions contain an
ownerentry.
-
mode:
str|None¶ The numeric representation of the file’s read, write, and execute permissions.
This entry must be assigned an octal number, enclosed in double-quotation marks (
"), for each defined path.This value should align with the POSIX specification for file permissions, just like one would use when calling
chmod. For more detail on octal file permissions, see the chmod command reference.
- property mode_octal: int¶
Get the mode as a base-8 integer.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
-
owner:
int|None¶ The numeric user ID (UID) of the desired owner on the host system.
This entry is required if the permissions contain a
groupentry.
-
path:
str¶ The file path, relative to the prime directory, being assigned permissions.
Wildcards (
*) are supported.If unset, the permissions will be assigned to every file in the prime directory.
- craft_parts.permissions.apply_permissions(target, permissions)[source]¶
Apply all permissions configurations in
permissionstotarget.- Parameters:
target (
Path|str)permissions (
list[Permissions])
- Return type:
None
- craft_parts.permissions.filter_permissions(target, permissions)[source]¶
Get the subset of
permissionswhose path patterns apply totarget.- Parameters:
target (
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,groupandmode.- Return type:
bool
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
pathattribute of thePermissionsare completely ignored, as they are understood to apply to the same file of interest through a previous call of
filter_permissions().
- The
- type left:
list[Permissions] |None- param left:
the first set of permissions.
- type right:
list[Permissions] |None- param right:
the second set of permissions.