Filesystem utilities

class conu.Directory(path, mode=None, user_owner=None, group_owner=None, facl_rules=None, selinux_context=None, selinux_user=None, selinux_role=None, selinux_type=None, selinux_range=None)

This class allows you to do advanced operations on filesystem directories, think of it as mkdir on steroids.

We advise you to use it as a context manager:

with Directory("/funky/path", mode=0o0700) as directory:
    path = os.path.join(directory.path, "my-dir")

The directory is being removed once leaving the context. You can also easily do it on your own:

directory = Directory("/funky/path", mode=0o0700)
try:
    directory.initialize()
finally:
    directory.clean()

This class utilizes CLI tools to perform some operations. If some of them is missing, the exception is raised.

__init__(path, mode=None, user_owner=None, group_owner=None, facl_rules=None, selinux_context=None, selinux_user=None, selinux_role=None, selinux_type=None, selinux_range=None)

For more info on SELinux, please see $ man chcon. An exception will be thrown if selinux_context is specified and at least one of other SELinux fields.

Parameters:
  • path – str, path to the directory we will operate on
  • mode – int, octal representation of permission bits, e.g. 0o0400
  • user_owner – str or int, uid or username to own the directory
  • group_owner – str or int, gid or group name to own the directory
  • facl_rules – list of str, file ACLs to apply, e.g. “u:26:rwx”
  • selinux_context – str, set directory to this SELinux context (this is the full context with all the field, example: “system_u:object_r:unlabeled_t:s0”)
  • selinux_user – str, user in the target security context, e.g. “system_u”
  • selinux_role – str, role in the target security context, e.g. “object_r”
  • selinux_type – str, type in the target security context, e.g. “unlabeled_t”
  • selinux_range – str, range in the target security context, e.g. “s0”
clean()

remove the directory we operated on

Returns:None
initialize()

create the directory if needed and configure it

Returns:None